667500672e0f10f09be2aa925a53b0ef455eaa32
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 }
46 if(((!$usePhoneTab)&&(isset($this->by_object['phonequeue'])))||((!preg_match("/U/",$objects))&&(isset($this->by_object['phonequeue'])))){
47 $this->by_object['phonequeue']->remove_from_parent();
48 unset($this->by_object['phonequeue']);
49 unset($this->by_name['phonequeue']);
50 }
51 /* Remove mail group if there is no user anymore */
52 if((!preg_match("/U/",$objects))&&(isset($this->by_object['mailogroup']))){
53 $this->by_object['mailogroup']->remove_from_parent();
54 unset($this->by_object['mailogroup']);
55 unset($this->by_name['mailogroup']);
56 }
58 /* Remove terminal group, if theres no terminal left in the object list */
59 if(((!preg_match("/T/",$objects)) && (!preg_match("/W/",$objects)))&&(isset($this->by_object['termgroup']))){
60 $this->by_object['termgroup']->remove_from_parent();
61 unset($this->by_object['termgroup']);
62 unset($this->by_name['termgroup']);
63 }
64 if(!preg_match("/T/",$objects) &&(isset($this->by_object['termservice']))){
65 $this->by_object['termservice']->remove_from_parent();
66 unset($this->by_object['termservice']);
67 unset($this->by_name['termservice']);
68 }
70 /* Remove ws tabs, if theres no ws left in the object list */
71 if((!preg_match("/W/",$objects))&&(isset($this->by_object['workservice']))){
72 $this->by_object['workservice']->remove_from_parent();
73 unset($this->by_object['workservice']);
74 unset($this->by_name['workservice']);
75 }
76 if((!preg_match("/S/",$objects) && !preg_match("/W/",$objects))&&(isset($this->by_object['workstartup']))){
77 $this->by_object['workstartup']->remove_from_parent();
78 unset($this->by_object['workstartup']);
79 unset($this->by_name['workstartup']);
80 $this->by_object['faiSummary']->remove_from_parent();
81 unset($this->by_object['faiSummary']);
82 unset($this->by_name['faiSummary']);
83 }
85 /* Create goPhoneAccount if theres an user with goPhoneAccount
86 * but only if there is currently no queue enabled.
87 */
88 if(!isset($this->by_object['phonequeue'])){
89 foreach($this->by_object['ogroup']->memberList as $dn => $val){
91 if(isset($this->by_object['ogroup']->objcache[$dn])){
92 $obj = $this->by_object['ogroup']->objcache[$dn];
94 if(isset($obj['objectClass'])){
95 if(in_array("goFonAccount",$obj['objectClass'])){
96 $this->by_name['phonequeue']= _("Phone queue");
97 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
98 $this->by_object['phonequeue']->parent= &$this;
99 break;
100 }
101 }
102 }
103 }
104 }
106 /* Add mail group tab , if there is curerntly no mail tab defined */
107 if((preg_match("/U/",$objects))&&(!isset($this->by_object['mailogroup']))){
108 if(isset($this->config->current['MAILMETHOD'])){
109 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
110 $this->by_name['mailogroup']= _("Mail");
111 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
112 $this->by_object['mailogroup']->parent= &$this;
113 }
114 }
115 }
117 /* Add Terminal tab */
118 if(((preg_match("/T/",$objects)) || (preg_match("/W/",$objects)))&&(!isset($this->by_object['termgroup']))){
119 if(!isset($this->by_object['termgroup'])){
120 $this->by_name['termgroup']= _("System");
121 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
122 $this->by_object['termgroup']->inheritTimeServer = false;
123 $this->by_object['termgroup']->parent= &$this;
124 }
125 }
126 if(preg_match("/T/",$objects) &&(!isset($this->by_object['termservice']))){
127 if(!isset($this->by_object['termservice'])){
128 $this->by_name['termservice']= _("Devices");
129 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
130 }
131 }
133 /* Add Workstation tabs */
134 if((preg_match("/W/",$objects))&&(!isset($this->by_object['workservice']))){
135 $this->by_name['workservice']= _("Devices");
136 $this->by_object['workservice']= new workservice($this->config, $this->dn);
137 $this->by_object['workservice']->inheritTimeServer = false;
138 $this->by_object['workservice']->parent= &$this;
139 $this->by_object['workservice']->acl = "#all#";
140 }
141 if((preg_match("/S/",$objects) || preg_match("/W/",$objects))&&(!isset($this->by_object['workstartup']))){
142 $this->by_name['workstartup']= _("Startup");
143 $this->by_object['workstartup']= new workstartup($this->config, $this->dn);
144 $this->by_object['workstartup']->parent= &$this;
145 $this->by_object['workstartup']->acl = "#all#";
146 $this->by_name['faiSummary']= _("Summary");
147 $this->by_object['faiSummary']= new faiSummaryTab($this->config, $this->dn);
148 $this->by_object['faiSummary']->parent= &$this;
149 }
151 /* Add application tab if user or group is member in this object group*/
152 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['appgroup'])){
153 $this->by_name['appgroup']= _("Application");
154 $this->by_object['appgroup']= new appgroup($this->config, $this->dn);
155 $this->by_object['appgroup']->acl = "#all#";
156 $this->by_object['appgroup']->parent= &$this;
157 }
159 /* Remove application tab if not required any longer */
160 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['appgroup'])){
161 $this->by_object['appgroup']->remove_from_parent();
162 unset($this->by_name['appgroup']);
163 unset($this->by_object['appgroup']);
164 }
166 /* Add environment tab if user or group is member in this object group*/
167 if((preg_match("/G/",$objects) || preg_match("/U/",$objects)) && !isset($this->by_name['environment'])){
168 $this->by_name['environment']= _("Environment");
169 $this->by_object['environment']= new environment($this->config, $this->dn);
170 $this->by_object['environment']->acl = "#all#";
171 $this->by_object['environment']->parent= &$this;
172 }
174 /* Remove environment tab if not required any longer */
175 if(!preg_match("/G/",$objects) && !preg_match("/U/",$objects) && isset($this->by_name['environment'])){
176 $this->by_object['environment']->remove_from_parent();
177 unset($this->by_name['environment']);
178 unset($this->by_object['environment']);
179 }
180 /* Move reference tab to second position from right */
181 if(isset($this->by_name['acl'])){
182 $tmp = $this->by_name['acl'];
183 unset($this->by_name['acl']);
184 $this->by_name['acl'] = $tmp;
185 }
187 /* Move reference tab to last position*/
188 if(isset($this->by_name['reference'])){
189 $tmp = $this->by_name['reference'];
190 unset($this->by_name['reference']);
191 $this->by_name['reference'] = $tmp;
192 }
194 /* Reset acls */
195 $this->set_acl_base($this->base);
196 foreach($this->by_object as $name => $obj){
197 $this->by_object[$name]->set_acl_category($this->acl_category);
198 }
199 }
201 function execute(){
202 $str = "";
203 $this->by_object['ogroup']->AddDelMembership();
204 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
205 $str .= tabs::execute();
206 return ( $str);
207 }
209 function ogrouptabs($config, $data, $dn,$category ="ogroups")
210 {
212 tabs::tabs($config, $data, $dn, $category);
213 $this->base= $this->by_object['ogroup']->base;
214 $this->acl_category = $category;
216 /* Insert extra tabs for several object types - if present */
218 $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
220 for ($n= 0; $n<strlen($objects); $n++){
221 switch ($objects[$n]){
222 case "T":
223 /* Add a terminal tab */
224 $this->by_name['termgroup']= _("Terminals");
225 $this->by_object['termgroup']= new termgroup($this->config, $this->dn);
226 $this->by_object['termgroup']->parent= &$this;
228 $this->by_name['termservice']= _("Devices");
229 $this->by_object['termservice']= new termservice($this->config, $this->dn,$this->by_object['ogroup']);
230 break;
232 case "U":
233 /* Append a PhoneQueue, if objectClass = goFonAccount */
234 $use = false;
235 foreach($this->by_object['ogroup']->memberList as $dn => $val){
237 $obj = $this->by_object['ogroup']->objcache[$dn];
239 if(isset($obj['objectClass'])){
240 if(in_array("goFonAccount",$obj['objectClass'])){
241 $use = true;
242 }
243 }
244 }
246 /* We found goFonAccount in users objectClasses*/
247 if($use){
248 $this->by_name['phonequeue']= _("Phone queue");
249 $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
250 $this->by_object['phonequeue']->parent= &$this;
251 }
253 /* Add a user tab used for mail distribution lists */
254 if(isset($this->config->current['MAILMETHOD'])){
255 if (preg_match('/kolab/i', $this->config->current['MAILMETHOD'])){
256 $this->by_name['mailogroup']= _("Mail");
257 $this->by_object['mailogroup']= new mailogroup($this->config, $this->dn);
258 $this->by_object['mailogroup']->parent= &$this;
259 }
260 }
262 break;
263 }
264 }
266 /* Add references/acls/snapshots */
267 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
268 $this->addSpecialTabs();
269 }
272 function check($ignore_account= FALSE)
273 {
274 return (tabs::check(FALSE));
275 }
278 function save_object($save_current= FALSE)
279 {
280 tabs::save_object($save_current);
282 /* Update reference, transfer variables */
283 $baseobject= $this->by_object['ogroup'];
284 foreach ($this->by_object as $name => $obj){
286 /* Don't touch base object */
287 if ($name != 'ogroup'){
288 $obj->parent = &$this;
289 $obj->uid = $baseobject->uid;
290 $obj->cn = $baseobject->cn;
291 $obj->sn = $baseobject->uid;
292 $obj->givenName = $baseobject->uid;
293 $this->by_object[$name]= $obj;
294 }
296 /* Update parent in base object */
297 $this->by_object['ogroup']->parent= &$this;
298 }
299 }
302 function save($ignore_account= FALSE)
303 {
304 $baseobject= $this->by_object['ogroup'];
306 /* Check for new 'dn', in order to propagate the
307 'dn' to all plugins */
308 $new_dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
310 /* Move group? */
311 if ($this->dn != $new_dn){
313 /* Write entry on new 'dn' */
314 if ($this->dn != "new"){
315 $baseobject->move($this->dn, $new_dn);
316 $this->by_object['ogroup']= $baseobject;
317 }
319 /* Happen to use the new one */
320 $this->dn= $new_dn;
321 }
323 if ($this->dn == "new"){
324 $this->dn= 'cn='.$baseobject->cn.','.get_ou('ogroupou').$baseobject->base;
325 }
327 tabs::save();
328 }
330 function getCopyDialog()
331 {
332 $this->reload($this->by_object['ogroup']->gosaGroupObjects);
333 return(tabs::getCopyDialog());
334 }
335 }
337 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
338 ?>