1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_department.inc";
22 class departmentManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Departments";
26 var $plDescription= "This does something";
28 /* CLI vars */
29 var $cli_summary= "Handling of LDAP subtrees";
30 var $cli_description= "Some longer text\nfor help";
31 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* Headpage attributes */
34 var $last_dep_sorting= "invalid";
35 var $departments= array();
36 var $deptabs= NULL;
38 /* attribute list for save action */
39 var $attributes= array();
40 var $objectclasses= array();
42 /* Tagging || Moving in progress */
43 var $AfterSaveProcedure = false;
45 function departmentManagement ($config, $ui)
46 {
47 $this->ui= $ui;
48 $this->dn= "";
49 $this->config= $config;
50 $this->DivListDepartment = new divListDepartment($this->config,$this);
51 }
53 function execute()
54 {
55 global $config;
57 /* Call parent execute */
58 plugin::execute();
60 /***************
61 Var init
62 ***************/
64 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^dep_edit_.*/","/^dep_del_.*/");
66 /* Reload departments */
67 $smarty = get_smarty();
68 $display = "";
69 $s_action = ""; // Will contain an action, like del or edit
70 $s_entry = ""; // The entry name for edit delete -...
73 /***************
74 Check posts
75 ***************/
77 // Check Post action
78 foreach($_POST as $key => $val){
79 // Post for delete
80 if(preg_match("/dep_del.*/",$key)){
81 $s_action = "del";
82 $s_entry = preg_replace("/dep_".$s_action."_/i","",$key);
83 $s_entry = preg_replace("/_.*$/","",$s_entry);
84 $s_entry = base64_decode($s_entry);
85 // Post for edit
86 }elseif(preg_match("/dep_edit_.*/",$key)){
87 $s_action="edit";
88 $s_entry = preg_replace("/dep_".$s_action."_/i","",$key);
89 $s_entry = preg_replace("/_.*$/","",$s_entry);
90 $s_entry = base64_decode($s_entry);
91 // Post for new
92 }elseif(preg_match("/dep_new.*/",$key)){
93 $s_action="new";
94 }
96 }
99 /***************
100 Create a new department
101 ***************/
103 /* New Entry if Posted action (s_action) == new
104 */
105 if ($s_action=="new"){
106 $this->dn= "new";
107 $this->deptabs= new deptabs($this->config,
108 $this->config->data['TABS']['DEPTABS'], $this->dn);
109 }
112 /***************
113 Edit entry
114 ***************/
116 /* Edit Entry if Posted action (s_action) == edit
117 * The entry which will be edited is defined in $s_entry
118 */
119 if (( $s_action=="edit") && (!isset($this->deptabs->config))){
120 $s_entry = convert_department_dn(base64_decode($s_entry));
121 $this->dn= $this->config->departments[trim($s_entry)];
123 if (($user= get_lock($this->dn)) != ""){
124 return(gen_locked_message ($user, $this->dn));
125 }
127 /* Lock the current entry, so everyone will get the above dialog */
128 add_lock ($this->dn, $this->ui->dn);
130 /* Set up the users ACL's for this 'dn' */
131 $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
133 /* Register deptabs to trigger edit dialog */
134 $this->deptabs= new deptabs($this->config,$this->config->data['TABS']['DEPTABS'], $this->dn);
135 $this->deptabs->set_acl($this->acl);
136 $_SESSION['objectinfo']= $this->dn;
137 }
140 /***************
141 Delete entry
142 ***************/
144 /* Delete Entry if Posted action (s_action) == del
145 * The entry which will be deleted is defined in $s_entry
146 */
147 if ($s_action =="del"){
148 $s_entry = convert_department_dn(base64_decode($s_entry));
149 $this->dn= $this->config->departments[trim($s_entry)];
151 /* Check locking */
152 if (($user= get_lock($this->dn)) != ""){
153 $_SESSION['dn']= $this->dn;
154 return(gen_locked_message($user, $this->dn));
155 } else {
156 add_lock ($this->dn, $this->ui->dn);
157 $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), @LDAP::fix($this->dn)));
158 $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
159 return ($display);
160 }
161 }
164 /***************
165 Delete department confirmed
166 ***************/
168 /* If department deletion is accepted ...
169 * Finally delete department
170 */
171 if (isset($_POST['delete_department_confirm'])){
172 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
173 $acl= get_module_permission($acl, "department", $this->dn);
174 if (chkacl($acl, "delete") == ""){
175 $this->remove_from_parent();
176 gosa_log ("Department object'".$this->dn."' has been removed");
177 } else {
178 print_red (_("You have no permission to remove this department."));
179 }
180 }
182 /***************
183 Handle Tagging (Return output for an iframe)
184 ***************/
186 /* This department must be tagged (Is called from iframe, generates output) */
187 if(isset($_GET['TagDepartment'])){
188 $this->deptabs->by_object['department']->tag_objects();
189 $this->deptabs->by_object['department']->must_be_tagged = false;
190 exit();
191 }
194 /***************
195 Handle recursive move (Return output for an iframe)
196 ***************/
198 /* initiate recursive remove (Is called from iframe, generates output)*/
199 if(isset($_GET['PerformRecMove'])){
200 $this->deptabs->by_object['department']->recursive_move();
201 $this->deptabs->by_object['department']->MustBeMoved = false;
202 exit();
203 }
207 /***************
208 Edit department finished
209 ***************/
211 if (($this->AfterSaveProcedure || isset($_POST['edit_finish'])) && (isset($this->deptabs->config))){
213 /* Check tabs, will feed message array */
214 $message= $this->deptabs->check();
216 /* Save, or display error message? */
217 if (count($message) == 0){
219 /* Save current changes */
220 if(!$this->AfterSaveProcedure){
221 $this->deptabs->save(true);
222 }
224 /* Check if we have to tag this department */
225 if($this->deptabs->by_object['department']->must_be_tagged){
226 $this->AfterSaveProcedure = true;
227 $this->deptabs->by_object['department']->must_be_tagged = false;
228 return($this->deptabs->by_object['department']->ShowTagFrame());
229 }
231 /* Saving and tagging, is done now, lets move the dep if required */
232 if($this->deptabs->by_object['department']->MustBeMoved){
233 $this->AfterSaveProcedure = true;
234 $this->deptabs->by_object['department']->MustBeMoved = false;
235 return($this->deptabs->by_object['department']->ShowMoveFrame());
236 }
238 if ($this->dn != "new"){
239 del_lock ($this->dn);
240 }
241 gosa_log ("Department object'".$this->dn."' has been saved");
242 unset ($this->deptabs);
243 $this->deptabs= NULL;
244 $this->AfterSaveProcedure = false;
245 unset ($_SESSION['objectinfo']);
246 } else {
247 /* Ok. There seem to be errors regarding to the tab data,
248 show message and continue as usual. */
249 show_errors($message);
250 }
251 }
254 /***************
255 Dialog canceled
256 ***************/
258 /* User canceled edit oder delete
259 * Cancel dialog
260 */
261 if (isset($_POST['edit_cancel']) || isset($_POST['delete_cancel']) || isset($_POST['delete_department_confirm'])){
262 del_lock ($this->dn);
263 unset($this->depdabs);
264 $this->deptabs= NULL;
265 unset ($_SESSION['objectinfo']);
266 }
268 /* Headpage or normal plugin screen? */
269 if ($this->deptabs != NULL){
271 /* Show main page (tabs) */
272 $display= $this->deptabs->execute();
273 if (!$this->deptabs->by_object[$this->deptabs->current]->dialog){
274 $display.= "<p style=\"text-align:right\">\n";
275 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
276 $display.= " \n";
277 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
278 $display.= "</p>";
279 }
280 return ($display);
281 }else{
283 /* Check if there is a snapshot dialog open */
284 if($str = $this->showSnapshotDialog($this->DivListDepartment->selectedBase,$this->DivListDepartment->selectedBase)){
285 return($str);
286 }
288 /* Display dialog with group list */
289 $this->DivListDepartment->parent = $this;
290 $this->DivListDepartment->execute();
291 $this->reload();
292 $this->DivListDepartment->DepartmentsAdded = true;
293 $this->DivListDepartment->setEntries($this->departments);
294 return($this->DivListDepartment->Draw());
295 }
296 }
299 function reload()
300 {
301 /* Vairaible init */
302 $base = $this->DivListDepartment->selectedBase;
303 $base_back = preg_replace("/^[^,]+,/","",$base);
304 $Regex = $this->DivListDepartment->Regex;
306 // Create Array to Test if we have a valid back button
307 $tmp = $_SESSION['config']->idepartments;
309 // In case of a valid back button create entry
310 if(isset($tmp[$base_back])){
311 $tmp2 ['dn'] = convert_department_dn($base_back);
313 // If empty always go to top
314 if(empty($tmp2['dn'])){
315 $tmp2['dn']="/";
316 }
317 $tmp2 ['description'][0] = _("..");
318 $result[$tmp[$base_back]]=$tmp2;
319 }
321 if($this->DivListDepartment->SubSearch){
322 $res= get_list("(&(|(ou=$Regex)(description=$Regex))(objectClass=gosaDepartment))",
323 $this->ui->subtreeACL, $base, array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
324 }else{
325 $res= get_list("(&(|(ou=$Regex)(description=$Regex))(objectClass=gosaDepartment))",
326 $this->ui->subtreeACL, $base, array("ou", "description"), GL_SIZELIMIT );
327 }
329 $this->departments= array();
330 $tmp = array();
331 foreach ($res as $key => $value){
332 #$tmp[get_sub_department(convert_department_dn($value['dn']))] = $key;
333 $tmp[$key] = get_sub_department(convert_department_dn($value['dn']));
334 }
335 natcasesort($tmp);
336 foreach($tmp as $key => $q){
337 $value = $res [$key];
338 /* Don't display base as entry on subsearch */
339 if(($value['dn'] == $base) && ($this->DivListDepartment->SubSearch)){
340 continue;
341 }
343 $this->departments[base64_encode($value['dn'])]= $value;
344 }
345 }
347 function remove_from_parent()
348 {
349 $ldap= $this->config->get_ldap_link();
350 $ldap->cd ($this->dn);
351 $ldap->recursive_remove();
353 /* Optionally execute a command after we're done */
354 $this->postremove();
356 /* Delete references to object groups */
357 $ldap->cd ($this->config->current['BASE']);
358 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
359 while ($ldap->fetch()){
360 $og= new ogroup($this->config, $ldap->getDN());
361 unset($og->member[$this->dn]);
362 $og->save ();
363 }
365 }
367 function remove_lock()
368 {
369 if (isset($this->dn)){
370 del_lock ($this->dn);
371 }
372 }
374 function save_object()
375 {
376 /* reload department */
377 $this->config->get_departments();
378 $config = $this->config;
380 $this->config->make_idepartments();
381 $this->DivListDepartment->save_object();
382 }
384 }
385 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
386 ?>