1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class ogrouptabs extends tabs
24 {
25 var $base= "";
26 var $acl_category;
28 function reload($dd){
29 $objects= preg_replace('/[\[\]]/', '', $dd);
31 /* If there is a phonequeue,
32 * but there is no user left with goPhoneAccount ... remove it.
33 */
34 $usePhoneTab = false;
35 foreach($this->by_object['ogroup']->memberList as $dn => $val){
37 if(isset($this->by_object['ogroup']->objcache[$dn])){
38 $obj = $this->by_object['ogroup']->objcache[$dn];
39 if(isset($obj['objectClass'])){
40 if(in_array("goFonAccount",$obj['objectClass'])){
41 $usePhoneTab = true;
42 }
43 }
44 }
45 }
47 if(class_available("phonequeue")){
48 if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
49 $this->by_object['phonequeue']->remove_from_parent();
50 unset($this->by_object['phonequeue']);
51 unset($this->by_name['phonequeue']);
52 }
53 }
54 /* Remove mail group if there is no user anymore */
55 if(class_available("mailogroup")){
56 if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
57 $this->by_object['mailogroup']->remove_from_parent();
58 unset($this->by_object['mailogroup']);
59 unset($this->by_name['mailogroup']);
60 }
61 }
63 /* Remove terminal group, if theres no terminal left in the object list */
64 if(class_available("termgroup")){
65 if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
66 $this->by_object['termgroup']->remove_from_parent();
67 unset($this->by_object['termgroup']);
68 unset($this->by_name['termgroup']);
69 }
70 }
71 if(class_available("termservice")){
72 if(!preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
73 $this->by_object['termservice']->remove_from_parent();
74 unset($this->by_object['termservice']);
75 unset($this->by_name['termservice']);
76 }
77 }
79 /* Remove ws tabs, if theres no ws left in the object list */
80 if(class_available("workservice")){
81 if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
82 $this->by_object['workservice']->remove_from_parent();
83 unset($this->by_object['workservice']);
84 unset($this->by_name['workservice']);
85 }
86 }
87 if(class_available("workstartup")){
88 if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
89 $this->by_object['workstartup']->remove_from_parent();
90 unset($this->by_object['workstartup']);
91 unset($this->by_name['workstartup']);
92 if (isset($this->by_object['faiSummary'])){
93 $this->by_object['faiSummary']->remove_from_parent();
94 unset($this->by_object['faiSummary']);
95 unset($this->by_name['faiSummary']);
96 }
97 }
98 }
100 /* Create goPhoneAccount if theres an user with goPhoneAccount
101 * but only if there is currently no queue enabled.
102 */
103 if(class_available("phonequeue")){
104 if(!isset($this->by_object['phonequeue'])){
105 foreach($this->by_object['ogroup']->memberList as $dn => $val){
107 if(isset($this->by_object['ogroup']->objcache[$dn])){
108 $obj = $this->by_object['ogroup']->objcache[$dn];
110 if(isset($obj['objectClass'])){
111 if(in_array("goFonAccount",$obj['objectClass'])){
112 $this->by_name['phonequeue']= _("Phone queue");
113 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
114 $this->by_object['phonequeue']->parent= &$this;
115 break;
116 }
117 }
118 }
119 }
120 }
121 }
123 /* Add mail group tab , if there is curerntly no mail tab defined */
124 if(class_available("mailogroup")){
125 if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
126 if(isset($this->config->current['MAILMETHOD'])){
127 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
128 $this->by_name['mailogroup']= _("Mail");
129 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
130 $this->by_object['mailogroup']->parent= &$this;
131 }
132 }
133 }
134 }
136 /* Add Terminal tab */
137 if(class_available("termgroup")){
138 if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
139 if(!isset($this->by_object['termgroup'])){
140 $this->by_name['termgroup']= _("Systems");
141 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
142 $this->by_object['termgroup']->inheritTimeServer = false;
143 $this->by_object['termgroup']->parent= &$this;
144 }
145 }
146 }
147 if(class_available("termservice")){
148 if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
149 if(!isset($this->by_object['termservice'])){
150 $this->by_name['termservice']= _("Devices");
151 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
152 }
153 }
154 }
156 /* Add Workstation tabs */
157 if(class_available("workstartup")){
158 if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
159 $this->by_name['workstartup']= _("Startup");
160 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
161 $this->by_object['workstartup']->parent= &$this;
162 $this->by_object['workstartup']->acl = "#all#";
163 }
164 }
165 if(class_available("workservice")){
166 if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
167 $this->by_name['workservice']= _("Devices");
168 $this->by_object['workservice']= new workservice($this->config, $this->dn);
169 $this->by_object['workservice']->inheritTimeServer = false;
170 $this->by_object['workservice']->parent= &$this;
171 $this->by_object['workservice']->acl = "#all#";
172 }
173 }
174 if(class_available("faiSummary")){
175 if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['faiSummary']))){
176 $this->by_name['faiSummary']= _("FAI summary");
177 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
178 $this->by_object['faiSummary']->parent= &$this;
179 }
180 }
182 /* Add application tab if user or group is member in this object group*/
183 if(class_available("appgroup")){
184 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
185 $this->by_name['appgroup']= _("Application");
186 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
187 $this->by_object['appgroup']->acl = "#all#";
188 $this->by_object['appgroup']->parent= &$this;
189 }
190 }
192 /* Remove application tab if not required any longer */
193 if(class_available("appgroup")){
194 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
195 $this->by_object['appgroup']->remove_from_parent();
196 unset($this->by_name['appgroup']);
197 unset($this->by_object['appgroup']);
198 }
199 }
201 /* Add environment tab if user or group is member in this object group*/
202 if(class_available("environment")){
203 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
204 $this->by_name['environment']= _("Environment");
205 $this->by_object['environment']= new environment($this->config, $this->dn);
206 $this->by_object['environment']->acl = "#all#";
207 $this->by_object['environment']->parent= &$this;
208 }
209 }
211 /* Remove environment tab if not required any longer */
212 if(class_available("environment")){
213 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
214 $this->by_object['environment']->remove_from_parent();
215 unset($this->by_name['environment']);
216 unset($this->by_object['environment']);
217 }
218 }
219 /* Move reference tab to second position from right */
220 if(class_available("acl")){
221 if(isset($this->by_name['acl'])){
222 $tmp = $this->by_name['acl'];
223 unset($this->by_name['acl']);
224 $this->by_name['acl'] = $tmp;
225 }
227 /* Move reference tab to last position*/
228 if(class_available("reference")){
229 if(isset($this->by_name['reference'])){
230 $tmp = $this->by_name['reference'];
231 unset($this->by_name['reference']);
232 $this->by_name['reference'] = $tmp;
233 }
234 }
236 /* Reset acls */
237 $this->set_acl_base($this->base);
238 foreach($this->by_object as $name => $obj){
239 $this->by_object[$name]->set_acl_category($this->acl_category);
240 }
241 }
242 }
244 function execute(){
245 $str = "";
246 $this->by_object['ogroup']->AddDelMembership();
247 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
248 $str .= tabs::execute();
249 return ( $str);
250 }
252 function ogrouptabs($config, $data, $dn,$category ="ogroups")
253 {
255 tabs::tabs($config, $data, $dn, $category);
256 $this->base= $this->by_object['ogroup']->base;
257 $this->acl_category = $category;
259 /* Insert extra tabs for several object types - if present */
261 $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
263 for ($n= 0; $n<strlen($objects); $n++){
264 switch ($objects[$n]){
265 case "T":
266 /* Add a terminal tab */
267 if(class_available("termgroup")){
268 $this->by_name['termgroup']= _("Terminals");
269 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
270 $this->by_object['termgroup']->parent= &$this;
271 }
273 if(class_available("termservice")){
274 $this->by_name['termservice']= _("Devices");
275 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
276 }
277 break;
279 case "U":
280 /* Append a PhoneQueue, if objectClass = goFonAccount */
281 $use = false;
283 /* We found goFonAccount in users objectClasses*/
284 if(class_available("phonequeue")){
285 foreach($this->by_object['ogroup']->memberList as $dn => $val){
287 $obj = $this->by_object['ogroup']->objcache[$dn];
289 if(isset($obj['objectClass'])){
290 if(in_array("goFonAccount",$obj['objectClass'])){
291 $use = true;
292 }
293 }
294 }
296 if($use){
297 $this->by_name['phonequeue']= _("Phone queue");
298 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
299 $this->by_object['phonequeue']->parent= &$this;
300 }
301 }
303 /* Add a user tab used for mail distribution lists */
304 if(class_available("mailogroup")){
305 if(isset($this->config->current['MAILMETHOD'])){
306 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
307 $this->by_name['mailogroup']= _("Mail");
308 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
309 $this->by_object['mailogroup']->parent= &$this;
310 }
311 }
312 }
314 break;
315 }
316 }
318 /* Add references/acls/snapshots */
319 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
320 $this->addSpecialTabs();
321 }
324 function check($ignore_account= FALSE)
325 {
326 return (tabs::check(FALSE));
327 }
330 function save_object($save_current= FALSE)
331 {
332 tabs::save_object($save_current);
334 /* Update reference, transfer variables */
335 $baseobject= $this->by_object['ogroup'];
336 foreach ($this->by_object as $name => $obj){
338 /* Don't touch base object */
339 if ($name != 'ogroup'){
340 $obj->parent = &$this;
341 $obj->uid = $baseobject->uid;
342 $obj->cn = $baseobject->cn;
343 $obj->sn = $baseobject->uid;
344 $obj->givenName = $baseobject->uid;
345 $this->by_object[$name]= $obj;
346 }
348 /* Update parent in base object */
349 $this->by_object['ogroup']->parent= &$this;
350 }
351 }
354 function save($ignore_account= FALSE)
355 {
356 $baseobject= $this->by_object['ogroup'];
358 /* Check for new 'dn', in order to propagate the
359 'dn' to all plugins */
360 $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
362 /* Move group? */
363 if ($this->dn != $new_dn){
365 /* Write entry on new 'dn' */
366 if ($this->dn != "new"){
367 $baseobject->move($this->dn, $new_dn);
368 $this->by_object['ogroup']= $baseobject;
369 }
371 /* Happen to use the new one */
372 $this->dn= $new_dn;
373 }
375 if ($this->dn == "new"){
376 $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
377 }
379 tabs::save();
380 }
382 function getCopyDialog()
383 {
384 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
385 return(tabs::getCopyDialog());
386 }
387 }
389 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
390 ?>