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;
27 var $to_remove=array();
29 /*! \brief Stage an object for removal */
30 function remove($object) {
31 if (!isset($this->to_remove[$object])) {
32 $this->to_remove[$object] = $this->by_object[$object];
33 unset($this->by_object[$object]);
34 }
35 }
37 /*! \brief Unstage an object from removal */
38 function add($object) {
39 if (isset($this->to_remove[$object])) {
40 unset($this->to_remove[$object]);
41 }
42 }
44 function reload($dd)
45 {
46 $objects = preg_replace('/[\[\]]/', '', $dd);
48 /* Check if we have a group with a set different mixed objects.
49 */
50 $mixed_type = FALSE;
51 for($i = 0 ; $i < (strlen($objects) -1 );$i++){
52 $mixed_type |= $objects[$i] != $objects[($i+1)];
53 }
55 /* If there is a phonequeue,
56 * but there is no user left with goPhoneAccount ... remove it.
57 */
58 $usePhoneTab = false;
59 if(class_available("phonequeue")){
61 foreach($this->by_object['ogroup']->memberList as $dn => $val){
62 if(isset($this->by_object['ogroup']->objcache[$dn])){
63 $obj = $this->by_object['ogroup']->objcache[$dn];
64 if(isset($obj['objectClass'])){
65 if(in_array("goFonAccount",$obj['objectClass'])){
66 $usePhoneTab = true;
67 }
68 }
69 }
70 }
71 if((!$usePhoneTab && isset($this->by_object['phonequeue']))||
72 (!preg_match("/U/",$objects) && isset($this->by_object['phonequeue']))){
73 $this->remove('phonequeue');
74 unset($this->by_object['phonequeue']);
75 unset($this->by_name['phonequeue']);
76 }
77 }
79 /* Remove mail group if there is no user anymore
80 */
81 if(class_available("mailogroup")){
82 if(!preg_match("/U/",$objects) && isset($this->by_object['mailogroup'])){
83 $this->remove('mailogroup');
84 unset($this->by_object['mailogroup']);
85 unset($this->by_name['mailogroup']);
86 }
87 }
89 /* Remove terminal group, if theres no terminal left in the object list
90 */
91 if(class_available("termgroup")){
92 if(($mixed_type && isset($this->by_object['termgroup'])) ||
93 !preg_match("/T/",$objects) && !preg_match("/W/",$objects) && isset($this->by_object['termgroup'])){
94 $this->remove('termgroup');
95 unset($this->by_object['termgroup']);
96 unset($this->by_name['termgroup']);
97 }
98 }
99 if(class_available("termservice")){
100 if(($mixed_type && isset($this->by_object['termservice'])) ||
101 !preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
102 $this->remove('termservice');
103 unset($this->by_object['termservice']);
104 unset($this->by_name['termservice']);
105 }
106 }
107 if(class_available("termstartup")){
108 if(($mixed_type && isset($this->by_object['termstartup'])) ||
109 !preg_match("/T/",$objects)&&(isset($this->by_object['termstartup']))){
110 $this->remove('termstartup');
111 unset($this->by_object['termstartup']);
112 unset($this->by_name['termstartup']);
113 }
114 }
116 /* Remove ws tabs, if theres no ws left in the object list */
117 if(class_available("workservice")){
118 if(($mixed_type && isset($this->by_object['workservice'])) ||
119 (!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
120 $this->remove('workservice');
121 unset($this->by_object['workservice']);
122 unset($this->by_name['workservice']);
123 }
124 }
125 if(class_available("workstartup")){
126 if(($mixed_type && isset($this->by_object['workstartup'])) ||
127 (!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
128 $this->remove('workstartup');
129 unset($this->by_object['workstartup']);
130 unset($this->by_name['workstartup']);
131 if (isset($this->by_object['faiSummary'])){
132 unset($this->by_object['faiSummary']);
133 unset($this->by_name['faiSummary']);
134 }
135 }
136 }
138 /* Create goPhoneAccount if theres an user with goPhoneAccount
139 * but only if there is currently no queue enabled.
140 */
141 if(class_available("phonequeue")){
142 if(!isset($this->by_object['phonequeue'])){
143 foreach($this->by_object['ogroup']->memberList as $dn => $val){
144 if(isset($this->by_object['ogroup']->objcache[$dn])){
145 $obj = $this->by_object['ogroup']->objcache[$dn];
146 if(isset($obj['objectClass'])){
147 if(in_array("goFonAccount",$obj['objectClass'])){
148 $this->by_name['phonequeue']= _("Phone queue");
149 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
150 $this->by_object['phonequeue']->parent= &$this;
151 $this->add('phonequeue');
152 break;
153 }
154 }
155 }
156 }
157 }
158 }
160 /* Add mail group tab , if there is curerntly no mail tab defined */
161 if(class_available("mailogroup")){
162 if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
163 if ($this->config->get_cfg_value("mailmethod") == "kolab"){
164 $this->by_name['mailogroup']= _("Mail");
165 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
166 $this->by_object['mailogroup']->parent= &$this;
167 $this->add('mailogroup');
168 }
169 }
170 }
172 /* Add Terminal tab */
173 if(class_available("termgroup")){
174 if(!$mixed_type &&
175 ((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
176 if(!isset($this->by_object['termgroup'])){
177 $this->by_name['termgroup']= _("Systems");
178 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
179 $this->by_object['termgroup']->inheritTimeServer = false;
180 $this->by_object['termgroup']->parent= &$this;
181 $this->add('termgroup');
182 }
183 }
184 }
185 if(class_available("termstartup")){
186 if(!$mixed_type &&
187 preg_match("/T/",$objects) &&(!isset($this->by_object['termstartup']))){
188 if(!isset($this->by_object['termstartup'])){
189 $this->by_name['termstartup']= _("Startup");
190 $this->by_object['termstartup']= new termstartup($this->config, $this->dn,$this->by_object['ogroup']);
191 $this->by_object['termstartup']->parent= &$this;
192 $this->by_object['termstartup']->acl = "#all#";
193 $this->add('termstartup');
194 }
195 }
196 }
197 if(!$mixed_type &&
198 class_available("termservice")){
199 if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
200 if(!isset($this->by_object['termservice'])){
201 $this->by_name['termservice']= _("Devices");
202 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
203 $this->by_object['termservice']->parent= &$this;
204 $this->by_object['termservice']->acl = "#all#";
205 $this->add('termservice');
206 }
207 }
208 }
210 /* Add Workstation tabs */
211 if(class_available("workstartup")){
212 if(!$mixed_type &&
213 (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
214 $this->by_name['workstartup']= _("Startup");
215 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
216 $this->by_object['workstartup']->parent= &$this;
217 $this->by_object['workstartup']->acl = "#all#";
218 $this->add("workstartup");
219 }
220 }
221 if(!$mixed_type &&
222 class_available("workservice")){
223 if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
224 $this->by_name['workservice']= _("Devices");
225 $this->by_object['workservice']= new workservice($this->config, $this->dn);
226 $this->by_object['workservice']->inheritTimeServer = false;
227 $this->by_object['workservice']->parent= &$this;
228 $this->by_object['workservice']->acl = "#all#";
229 $this->add("workservice");
230 }
231 }
232 if(class_available("faiSummary")){
233 if(!$mixed_type &&
234 (preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['faiSummary']))){
235 $this->by_name['faiSummary']= _("FAI summary");
236 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
237 $this->by_object['faiSummary']->parent= &$this;
238 $this->add("faiSummary");
239 }
240 }
242 /* Add environment tab if user or group is member in this object group*/
243 if(class_available("environment")){
244 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
245 $this->by_name['environment']= _("Environment");
246 $this->by_object['environment']= new environment($this->config, $this->dn);
247 $this->by_object['environment']->acl = "#all#";
248 $this->by_object['environment']->parent= &$this;
249 $this->add("environment");
250 }
251 }
253 /* Remove environment tab if not required any longer */
254 if(class_available("environment")){
255 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
256 $this->remove("environment");
257 unset($this->by_name['environment']);
258 unset($this->by_object['environment']);
259 }
260 }
262 /* Add application tab if user or group is member in this object group*/
263 if(class_available("appgroup")){
264 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
265 $this->by_name['appgroup']= _("Applications");
266 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
267 $this->by_object['appgroup']->acl = "#all#";
268 $this->by_object['appgroup']->parent= &$this;
269 $this->add('appgroup');
270 }
271 }
273 /* Remove application tab if not required any longer */
274 if(class_available("appgroup")){
275 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
276 $this->remove('appgroup');
277 unset($this->by_name['appgroup']);
278 unset($this->by_object['appgroup']);
279 }
280 }
282 /* Move reference tab to second position from right */
283 if(class_available("acl")){
284 if(isset($this->by_name['acl'])){
285 $tmp = $this->by_name['acl'];
286 unset($this->by_name['acl']);
287 $this->by_name['acl'] = $tmp;
288 }
290 /* Move reference tab to last position*/
291 if(class_available("reference")){
292 if(isset($this->by_name['reference'])){
293 $tmp = $this->by_name['reference'];
294 unset($this->by_name['reference']);
295 $this->by_name['reference'] = $tmp;
296 }
297 }
299 /* Reset acls */
300 $this->set_acl_base($this->base);
301 foreach($this->by_object as $name => $obj){
302 $this->by_object[$name]->set_acl_category($this->acl_category);
303 }
304 }
305 }
307 function execute(){
308 $str = "";
309 $this->by_object['ogroup']->AddDelMembership();
310 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
311 $str .= tabs::execute();
312 return ( $str);
313 }
315 function ogrouptabs($config, $data, $dn,$category ="ogroups")
316 {
318 tabs::tabs($config, $data, $dn, $category);
319 $this->base= $this->by_object['ogroup']->base;
320 $this->acl_category = $category;
322 /* Add references/acls/snapshots */
323 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
324 $this->addSpecialTabs();
325 }
328 function check($ignore_account= FALSE)
329 {
330 return (tabs::check(FALSE));
331 }
334 function save_object($save_current= FALSE)
335 {
336 tabs::save_object($save_current);
338 /* Update reference, transfer variables */
339 $baseobject= $this->by_object['ogroup'];
340 foreach ($this->by_object as $name => $obj){
342 /* Don't touch base object */
343 if ($name != 'ogroup'){
344 $obj->parent = &$this;
345 $obj->uid = $baseobject->uid;
346 $obj->cn = $baseobject->cn;
347 $obj->sn = $baseobject->uid;
348 $obj->givenName = $baseobject->uid;
349 $this->by_object[$name]= $obj;
350 }
352 /* Update parent in base object */
353 $this->by_object['ogroup']->parent= &$this;
354 }
355 }
358 function save($ignore_account= FALSE)
359 {
360 $baseobject= $this->by_object['ogroup'];
362 /* Check for new 'dn', in order to propagate the
363 'dn' to all plugins */
364 $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupRDN').$baseobject->base;
366 /* Move group? */
367 if (LDAP::fix($this->dn) != LDAP::fix($new_dn)){
369 /* Write entry on new 'dn' */
370 if ($this->dn != "new"){
371 $baseobject->move($this->dn, $new_dn);
372 $this->by_object['ogroup']= $baseobject;
373 }
375 /* Happen to use the new one */
376 $this->dn= $new_dn;
377 }
379 if ($this->dn == "new"){
380 $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupRDN').$baseobject->base;
381 }
383 foreach(array_keys($this->to_remove) as $object) {
384 $this->to_remove[$object]->remove_from_parent();
385 }
386 tabs::save();
387 }
389 function getCopyDialog()
390 {
391 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
392 return(tabs::getCopyDialog());
393 }
394 }
396 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
397 ?>