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