47af9e79ae6ac30f61ecf813c05d62316ca23f65
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 environment tab if user or group is member in this object group*/
183 if(class_available("environment")){
184 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
185 $this->by_name['environment']= _("Environment");
186 $this->by_object['environment']= new environment($this->config, $this->dn);
187 $this->by_object['environment']->acl = "#all#";
188 $this->by_object['environment']->parent= &$this;
189 }
190 }
192 /* Remove environment tab if not required any longer */
193 if(class_available("environment")){
194 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
195 $this->by_object['environment']->remove_from_parent();
196 unset($this->by_name['environment']);
197 unset($this->by_object['environment']);
198 }
199 }
201 /* Add application tab if user or group is member in this object group*/
202 if(class_available("appgroup")){
203 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
204 $this->by_name['appgroup']= _("Applications");
205 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
206 $this->by_object['appgroup']->acl = "#all#";
207 $this->by_object['appgroup']->parent= &$this;
208 }
209 }
211 /* Remove application tab if not required any longer */
212 if(class_available("appgroup")){
213 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
214 $this->by_object['appgroup']->remove_from_parent();
215 unset($this->by_name['appgroup']);
216 unset($this->by_object['appgroup']);
217 }
218 }
220 /* Move reference tab to second position from right */
221 if(class_available("acl")){
222 if(isset($this->by_name['acl'])){
223 $tmp = $this->by_name['acl'];
224 unset($this->by_name['acl']);
225 $this->by_name['acl'] = $tmp;
226 }
228 /* Move reference tab to last position*/
229 if(class_available("reference")){
230 if(isset($this->by_name['reference'])){
231 $tmp = $this->by_name['reference'];
232 unset($this->by_name['reference']);
233 $this->by_name['reference'] = $tmp;
234 }
235 }
237 /* Reset acls */
238 $this->set_acl_base($this->base);
239 foreach($this->by_object as $name => $obj){
240 $this->by_object[$name]->set_acl_category($this->acl_category);
241 }
242 }
243 }
245 function execute(){
246 $str = "";
247 $this->by_object['ogroup']->AddDelMembership();
248 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
249 $str .= tabs::execute();
250 return ( $str);
251 }
253 function ogrouptabs($config, $data, $dn,$category ="ogroups")
254 {
256 tabs::tabs($config, $data, $dn, $category);
257 $this->base= $this->by_object['ogroup']->base;
258 $this->acl_category = $category;
260 /* Insert extra tabs for several object types - if present */
262 $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
264 for ($n= 0; $n<strlen($objects); $n++){
265 switch ($objects[$n]){
266 case "T":
267 /* Add a terminal tab */
268 if(class_available("termgroup")){
269 $this->by_name['termgroup']= _("Terminals");
270 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
271 $this->by_object['termgroup']->parent= &$this;
272 }
274 if(class_available("termservice")){
275 $this->by_name['termservice']= _("Devices");
276 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
277 }
278 break;
280 case "U":
281 /* Append a PhoneQueue, if objectClass = goFonAccount */
282 $use = false;
284 /* We found goFonAccount in users objectClasses*/
285 if(class_available("phonequeue")){
286 foreach($this->by_object['ogroup']->memberList as $dn => $val){
288 $obj = $this->by_object['ogroup']->objcache[$dn];
290 if(isset($obj['objectClass'])){
291 if(in_array("goFonAccount",$obj['objectClass'])){
292 $use = true;
293 }
294 }
295 }
297 if($use){
298 $this->by_name['phonequeue']= _("Phone queue");
299 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
300 $this->by_object['phonequeue']->parent= &$this;
301 }
302 }
304 /* Add a user tab used for mail distribution lists */
305 if(class_available("mailogroup")){
306 if(isset($this->config->current['MAILMETHOD'])){
307 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
308 $this->by_name['mailogroup']= _("Mail");
309 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
310 $this->by_object['mailogroup']->parent= &$this;
311 }
312 }
313 }
315 break;
316 }
317 }
319 /* Add references/acls/snapshots */
320 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
321 $this->addSpecialTabs();
322 }
325 function check($ignore_account= FALSE)
326 {
327 return (tabs::check(FALSE));
328 }
331 function save_object($save_current= FALSE)
332 {
333 tabs::save_object($save_current);
335 /* Update reference, transfer variables */
336 $baseobject= $this->by_object['ogroup'];
337 foreach ($this->by_object as $name => $obj){
339 /* Don't touch base object */
340 if ($name != 'ogroup'){
341 $obj->parent = &$this;
342 $obj->uid = $baseobject->uid;
343 $obj->cn = $baseobject->cn;
344 $obj->sn = $baseobject->uid;
345 $obj->givenName = $baseobject->uid;
346 $this->by_object[$name]= $obj;
347 }
349 /* Update parent in base object */
350 $this->by_object['ogroup']->parent= &$this;
351 }
352 }
355 function save($ignore_account= FALSE)
356 {
357 $baseobject= $this->by_object['ogroup'];
359 /* Check for new 'dn', in order to propagate the
360 'dn' to all plugins */
361 $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
363 /* Move group? */
364 if ($this->dn != $new_dn){
366 /* Write entry on new 'dn' */
367 if ($this->dn != "new"){
368 $baseobject->move($this->dn, $new_dn);
369 $this->by_object['ogroup']= $baseobject;
370 }
372 /* Happen to use the new one */
373 $this->dn= $new_dn;
374 }
376 if ($this->dn == "new"){
377 $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
378 }
380 tabs::save();
381 }
383 function getCopyDialog()
384 {
385 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
386 return(tabs::getCopyDialog());
387 }
388 }
390 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
391 ?>