e5654cd7342dfb9f4b180075b42eab2d3d209c2b
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 $this->by_object['faiSummary']->remove_from_parent();
93 unset($this->by_object['faiSummary']);
94 unset($this->by_name['faiSummary']);
95 }
96 }
98 /* Create goPhoneAccount if theres an user with goPhoneAccount
99 * but only if there is currently no queue enabled.
100 */
101 if(class_available("phonequeue")){
102 if(!isset($this->by_object['phonequeue'])){
103 foreach($this->by_object['ogroup']->memberList as $dn => $val){
105 if(isset($this->by_object['ogroup']->objcache[$dn])){
106 $obj = $this->by_object['ogroup']->objcache[$dn];
108 if(isset($obj['objectClass'])){
109 if(in_array("goFonAccount",$obj['objectClass'])){
110 $this->by_name['phonequeue']= _("Phone queue");
111 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
112 $this->by_object['phonequeue']->parent= &$this;
113 break;
114 }
115 }
116 }
117 }
118 }
119 }
121 /* Add mail group tab , if there is curerntly no mail tab defined */
122 if(class_available("mailogroup")){
123 if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
124 if(isset($this->config->current['MAILMETHOD'])){
125 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
126 $this->by_name['mailogroup']= _("Mail");
127 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
128 $this->by_object['mailogroup']->parent= &$this;
129 }
130 }
131 }
132 }
134 /* Add Terminal tab */
135 if(class_available("termgroup")){
136 if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
137 if(!isset($this->by_object['termgroup'])){
138 $this->by_name['termgroup']= _("Systems");
139 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
140 $this->by_object['termgroup']->inheritTimeServer = false;
141 $this->by_object['termgroup']->parent= &$this;
142 }
143 }
144 }
145 if(class_available("termservice")){
146 if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
147 if(!isset($this->by_object['termservice'])){
148 $this->by_name['termservice']= _("Devices");
149 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
150 }
151 }
152 }
154 /* Add Workstation tabs */
155 if(class_available("workstartup")){
156 if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
157 $this->by_name['workstartup']= _("Startup");
158 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
159 $this->by_object['workstartup']->parent= &$this;
160 $this->by_object['workstartup']->acl = "#all#";
161 }
162 }
163 if(class_available("workservice")){
164 if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
165 $this->by_name['workservice']= _("Devices");
166 $this->by_object['workservice']= new workservice($this->config, $this->dn);
167 $this->by_object['workservice']->inheritTimeServer = false;
168 $this->by_object['workservice']->parent= &$this;
169 $this->by_object['workservice']->acl = "#all#";
170 }
171 }
172 if(class_available("faiSummary")){
173 if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['faiSummary']))){
174 $this->by_name['faiSummary']= _("FAI summary");
175 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
176 $this->by_object['faiSummary']->parent= &$this;
177 }
178 }
180 /* Add application tab if user or group is member in this object group*/
181 if(class_available("appgroup")){
182 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
183 $this->by_name['appgroup']= _("Application");
184 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
185 $this->by_object['appgroup']->acl = "#all#";
186 $this->by_object['appgroup']->parent= &$this;
187 }
188 }
190 /* Remove application tab if not required any longer */
191 if(class_available("appgroup")){
192 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
193 $this->by_object['appgroup']->remove_from_parent();
194 unset($this->by_name['appgroup']);
195 unset($this->by_object['appgroup']);
196 }
197 }
199 /* Add environment tab if user or group is member in this object group*/
200 if(class_available("environment")){
201 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
202 $this->by_name['environment']= _("Environment");
203 $this->by_object['environment']= new environment($this->config, $this->dn);
204 $this->by_object['environment']->acl = "#all#";
205 $this->by_object['environment']->parent= &$this;
206 }
207 }
209 /* Remove environment tab if not required any longer */
210 if(class_available("environment")){
211 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
212 $this->by_object['environment']->remove_from_parent();
213 unset($this->by_name['environment']);
214 unset($this->by_object['environment']);
215 }
216 }
217 /* Move reference tab to second position from right */
218 if(class_available("acl")){
219 if(isset($this->by_name['acl'])){
220 $tmp = $this->by_name['acl'];
221 unset($this->by_name['acl']);
222 $this->by_name['acl'] = $tmp;
223 }
225 /* Move reference tab to last position*/
226 if(class_available("reference")){
227 if(isset($this->by_name['reference'])){
228 $tmp = $this->by_name['reference'];
229 unset($this->by_name['reference']);
230 $this->by_name['reference'] = $tmp;
231 }
232 }
234 /* Reset acls */
235 $this->set_acl_base($this->base);
236 foreach($this->by_object as $name => $obj){
237 $this->by_object[$name]->set_acl_category($this->acl_category);
238 }
239 }
240 }
242 function execute(){
243 $str = "";
244 $this->by_object['ogroup']->AddDelMembership();
245 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
246 $str .= tabs::execute();
247 return ( $str);
248 }
250 function ogrouptabs($config, $data, $dn,$category ="ogroups")
251 {
253 tabs::tabs($config, $data, $dn, $category);
254 $this->base= $this->by_object['ogroup']->base;
255 $this->acl_category = $category;
257 /* Insert extra tabs for several object types - if present */
259 $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
261 for ($n= 0; $n<strlen($objects); $n++){
262 switch ($objects[$n]){
263 case "T":
264 /* Add a terminal tab */
265 if(class_available("termgroup")){
266 $this->by_name['termgroup']= _("Terminals");
267 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
268 $this->by_object['termgroup']->parent= &$this;
269 }
271 if(class_available("termservice")){
272 $this->by_name['termservice']= _("Devices");
273 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
274 }
275 break;
277 case "U":
278 /* Append a PhoneQueue, if objectClass = goFonAccount */
279 $use = false;
281 /* We found goFonAccount in users objectClasses*/
282 if(class_available("phonequeue")){
283 foreach($this->by_object['ogroup']->memberList as $dn => $val){
285 $obj = $this->by_object['ogroup']->objcache[$dn];
287 if(isset($obj['objectClass'])){
288 if(in_array("goFonAccount",$obj['objectClass'])){
289 $use = true;
290 }
291 }
292 }
294 if($use){
295 $this->by_name['phonequeue']= _("Phone queue");
296 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
297 $this->by_object['phonequeue']->parent= &$this;
298 }
299 }
301 /* Add a user tab used for mail distribution lists */
302 if(class_available("mailogroup")){
303 if(isset($this->config->current['MAILMETHOD'])){
304 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
305 $this->by_name['mailogroup']= _("Mail");
306 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
307 $this->by_object['mailogroup']->parent= &$this;
308 }
309 }
310 }
312 break;
313 }
314 }
316 /* Add references/acls/snapshots */
317 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
318 $this->addSpecialTabs();
319 }
322 function check($ignore_account= FALSE)
323 {
324 return (tabs::check(FALSE));
325 }
328 function save_object($save_current= FALSE)
329 {
330 tabs::save_object($save_current);
332 /* Update reference, transfer variables */
333 $baseobject= $this->by_object['ogroup'];
334 foreach ($this->by_object as $name => $obj){
336 /* Don't touch base object */
337 if ($name != 'ogroup'){
338 $obj->parent = &$this;
339 $obj->uid = $baseobject->uid;
340 $obj->cn = $baseobject->cn;
341 $obj->sn = $baseobject->uid;
342 $obj->givenName = $baseobject->uid;
343 $this->by_object[$name]= $obj;
344 }
346 /* Update parent in base object */
347 $this->by_object['ogroup']->parent= &$this;
348 }
349 }
352 function save($ignore_account= FALSE)
353 {
354 $baseobject= $this->by_object['ogroup'];
356 /* Check for new 'dn', in order to propagate the
357 'dn' to all plugins */
358 $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
360 /* Move group? */
361 if ($this->dn != $new_dn){
363 /* Write entry on new 'dn' */
364 if ($this->dn != "new"){
365 $baseobject->move($this->dn, $new_dn);
366 $this->by_object['ogroup']= $baseobject;
367 }
369 /* Happen to use the new one */
370 $this->dn= $new_dn;
371 }
373 if ($this->dn == "new"){
374 $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
375 }
377 tabs::save();
378 }
380 function getCopyDialog()
381 {
382 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
383 return(tabs::getCopyDialog());
384 }
385 }
387 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
388 ?>