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