5c88b5756f006427b6c1e93bde3ad8544ca26c13
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_application.inc";
22 class applicationManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Applications";
26 var $plDescription = "This does something";
28 /* Dialog attributes */
29 var $apptabs = NULL;
30 var $ui = NULL;
31 var $CopyPasteHandler = NULL;
32 var $DivListApplication = NULL;
33 var $applications = array();
34 var $enableReleaseManagement = false;
36 function IsReleaseManagementActivated()
37 {
38 /* Check if we should enable the release selection */
39 $tmp = search_config($this->config->data,"faiManagement","CLASS");
40 if(!empty($tmp)){
41 return(true);
42 }
43 return(false);
44 }
46 function applicationManagement ($config, $ui)
47 {
48 /* Save configuration for internal use */
49 $this->config = $config;
50 $this->ui = $ui;
52 /* Check if copy & paste is activated */
53 if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
54 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
55 }
57 /* Creat dialog object */
58 $this->DivListApplication = new divListApplication($this->config,$this);
60 if($this->IsReleaseManagementActivated()){
61 /* Check if we should enable the release selection */
62 $this->enableReleaseManagement = true;
64 /* Hide SubSearch checkbox */
65 $this->DivListApplication->DisableCheckBox("SubSearch");
66 }
67 }
69 function getReleases($base)
70 {
71 $ldap = $this->config->get_ldap_link();
72 $dn = "ou=apps,".$base;
73 $ret = array();
74 $ret ["ou=apps,".$base] = "/";
76 $ldap->cd($dn);
77 $ldap->search("objectClass=organizationalUnit",array("ou"));
79 while($attrs = $ldap->fetch()){
80 $str = str_replace($dn,"",$attrs['dn']);
81 $tmp = array_reverse( split("ou=",$str));
82 $str = "";
83 foreach($tmp as $val){
84 $val = trim(preg_replace("/,/","",$val));
85 if(empty($val)) break;
86 $str .= "/".$val;
87 }
88 if(!empty($str)){
89 $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
90 }
91 }
92 asort($ret);
93 return($ret);
94 }
96 function execute()
97 {
98 /* Call parent execute */
99 plugin::execute();
102 /****************
103 Variable init
104 ****************/
106 /* These vars will be stored if you try to open a locked app,
107 to be able to perform your last requests after showing a warning message */
108 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/");
110 $smarty = get_smarty(); // Smarty instance
111 $s_action = ""; // Contains the action to proceed
112 $s_entry = ""; // The value for s_action
113 $base_back = ""; // The Link for Backbutton
115 /* Test Posts */
116 foreach($_POST as $key => $val){
117 // Post for delete
118 if(preg_match("/appl_del.*/",$key)){
119 $s_action = "del";
120 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
121 // Post for edit
122 }elseif(preg_match("/appl_edit_.*/",$key)){
123 $s_action="edit";
124 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
125 // Post for new
126 }elseif(preg_match("/^copy_.*/",$key)){
127 $s_action="copy";
128 $s_entry = preg_replace("/^copy_/i","",$key);
129 }elseif(preg_match("/^cut_.*/",$key)){
130 $s_action="cut";
131 $s_entry = preg_replace("/^cut_/i","",$key);
132 // Post for new
133 }elseif(preg_match("/^appl_new.*/",$key)){
134 $s_action="new";
135 }elseif(preg_match("/^editPaste.*/i",$key)){
136 $s_action="editPaste";
137 }
138 }
140 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
141 $s_action ="edit";
142 $s_entry = $_GET['id'];
143 }
145 $s_entry = preg_replace("/_.$/","",$s_entry);
148 /****************
149 Copy & Paste handling
150 ****************/
152 /* Only perform copy / paste if it is enabled
153 */
154 if($this->CopyPasteHandler){
155 if($str = $this->copyPasteHandling($s_action,$s_entry)){
156 return($str);
157 };
158 }
161 /****************
162 Create a new app
163 ****************/
165 /* New application? */
166 if ($s_action=="new"){
168 /* By default we set 'dn' to 'new', all relevant plugins will
169 react on this. */
170 $this->dn= "new";
172 /* Create new usertab object */
173 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
174 $this->apptabs->set_acl_base($this->DivListApplication->selectedBase);
175 }
178 /****************
179 Edit entry canceled
180 ****************/
182 /* Cancel dialogs */
183 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
184 del_lock ($this->apptabs->dn);
185 unset ($this->apptabs);
186 $this->apptabs= NULL;
187 unset ($_SESSION['objectinfo']);
188 }
191 /****************
192 Edit entry finished
193 ****************/
195 /* Finish apps edit is triggered by the tabulator dialog, so
196 the user wants to save edited data. Check and save at this
197 point. */
198 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->apptabs->config))){
200 /* Check tabs, will feed message array */
201 $this->apptabs->last= $this->apptabs->current;
202 $this->apptabs->save_object();
203 $message= $this->apptabs->check();
205 /* Save, or display error message? */
206 if (count($message) == 0){
208 /* Save data data to ldap */
209 $this->apptabs->set_release($this->DivListApplication->selectedRelease);
210 $this->apptabs->save();
211 gosa_log ("Application object'".$this->dn."' has been saved");
213 if (!isset($_POST['edit_apply'])){
214 /* Application has been saved successfully, remove lock from
215 LDAP. */
216 if ($this->dn != "new"){
217 del_lock ($this->dn);
218 }
219 unset ($this->apptabs);
220 $this->apptabs= NULL;
221 unset ($_SESSION['objectinfo']);
222 }
223 } else {
224 /* Ok. There seem to be errors regarding to the tab data,
225 show message and continue as usual. */
226 show_errors($message);
227 }
228 }
231 /****************
232 Edit entry
233 ****************/
235 /* User wants to edit data? */
236 if (($s_action=="edit") && (!isset($this->apptabs->config))){
238 /* Get 'dn' from posted 'applist', must be unique */
239 $this->dn= $this->applications[$s_entry]['dn'];
241 /* Check locking, save current plugin in 'back_plugin', so
242 the dialog knows where to return. */
243 if (($user= get_lock($this->dn)) != ""){
244 return(gen_locked_message ($user, $this->dn));
245 }
247 /* Lock the current entry, so everyone will get the
248 above dialog */
249 add_lock ($this->dn, $this->ui->dn);
251 /* Register apptabs to trigger edit dialog */
252 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
253 $this->apptabs->set_acl_base($this->dn);
254 $_SESSION['objectinfo']= $this->dn;
255 }
258 /****************
259 Delete app
260 ****************/
262 /* Remove user was requested */
263 if ($s_action == "del"){
265 /* Get 'dn' from posted 'uid' */
266 $this->dn= $this->applications[$s_entry]['dn'];
268 /* Load permissions for selected 'dn' and check if
269 we're allowed to remove this 'dn' */
270 $ui = get_userinfo();
271 $acl = $ui->get_permissions($this->dn ,"application/application");
273 if(preg_match("/d/",$acl)){
274 /* Check locking, save current plugin in 'back_plugin', so
275 the dialog knows where to return. */
276 if (($user= get_lock($this->dn)) != ""){
277 return (gen_locked_message ($user, $this->dn));
278 }
280 /* Lock the current entry, so nobody will edit it during deletion */
281 add_lock ($this->dn, $this->ui->dn);
282 $smarty= get_smarty();
283 $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), @LDAP::fix($this->dn)));
284 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
285 } else {
287 /* Obviously the user isn't allowed to delete. Show message and
288 clean session. */
289 print_red (_("You are not allowed to delete this application!"));
290 }
291 }
294 /****************
295 Delete app confirmed
296 ****************/
298 /* Confirmation for deletion has been passed. Group should be deleted. */
299 if (isset($_POST['delete_app_confirm'])){
301 /* Some nice guy may send this as POST, so we've to check
302 for the permissions again. */
303 $ui = get_userinfo();
304 $acl = $ui->get_permissions($this->dn ,"application/application");
306 if(preg_match("/d/",$acl)){
308 /* Delete request is permitted, perform LDAP action */
309 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
310 $this->apptabs->set_acl_base($this->dn);
311 $this->apptabs->delete ();
312 gosa_log ("Application object'".$this->dn."' has been removed");
313 unset ($this->apptabs);
314 $this->apptabs= NULL;
316 } else {
318 /* Normally this shouldn't be reached, send some extra
319 logs to notify the administrator */
320 print_red (_("You are not allowed to delete this application!"));
321 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
322 }
324 /* Remove lock file after successfull deletion */
325 del_lock ($this->dn);
326 }
329 /****************
330 Delete app canceled
331 ****************/
333 /* Delete application canceled? */
334 if (isset($_POST['delete_cancel'])){
335 del_lock ($this->dn);
336 unset($_SESSION['objectinfo']);
337 }
339 /* Show tab dialog if object is present */
340 if (($this->apptabs) && (isset($this->apptabs->config))){
341 $display= $this->apptabs->execute();
343 /* Don't show buttons if tab dialog requests this */
344 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
345 $display.= "<p style=\"text-align:right\">\n";
346 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
347 $display.= " \n";
348 if ($this->dn != "new"){
349 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
350 $display.= " \n";
351 }
352 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
353 $display.= "</p>";
354 }
355 return ($display);
356 }
359 /****************
360 Dialog display
361 ****************/
363 /* Check if there is a snapshot dialog open */
364 $base = $this->DivListApplication->selectedBase;
365 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases($base))){
366 return($str);
367 }
369 /* Display dialog with system list */
370 $this->DivListApplication->parent = $this;
371 $this->DivListApplication->execute();
372 $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase);
373 $this->reload();
374 $this->DivListApplication->setEntries($this->applications);
375 return($this->DivListApplication->Draw());
376 }
379 /* Return departments, that will be included within snapshot detection */
380 function get_used_snapshot_bases(){
381 if($this->DivListApplication->selectedRelease == "main"){
382 return(array($this->DivListApplication->selectedBase));
383 }else{
384 return(array($this->DivListApplication->selectedRelease));
385 }
386 }
389 function reload()
390 {
391 $this->applications= array();
393 /* Set base for all searches */
394 $base = $this->DivListApplication->selectedBase;
395 $release = $this->DivListApplication->selectedRelease;
396 $Regex = $this->DivListApplication->Regex;
397 $SubSearch = $this->DivListApplication->SubSearch;
398 $Flags = GL_NONE | GL_SIZELIMIT;
399 $Filter = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
400 $tmp = array();
401 $Releases = $this->getReleases($base);
403 if(!$this->enableReleaseManagement){
404 $use_base = "ou=apps,".$base;
405 }else{
406 if(isset($Releases[$release])){
407 $use_base = $release;
408 }else{
409 $use_base = "ou=apps,".$base;
410 }
411 }
413 if($SubSearch){
414 $Flags |= GL_SUBSEARCH;
415 }
417 $res= get_list($Filter, "application", $use_base, array("cn","description","dn","objectClass"), $Flags);
418 foreach ($res as $val){
419 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
420 }
422 ksort($tmp);
423 $this->applications=array();
424 foreach($tmp as $val){
425 $this->applications[]=$val;
426 }
427 reset ($this->applications);
428 }
430 function remove_from_parent()
431 {
432 /* Optionally execute a command after we're done */
433 $this->postremove();
434 }
437 function copyPasteHandling($s_action,$s_entry)
438 {
439 /* Paste copied/cutted object in here
440 */
441 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
442 $this->CopyPasteHandler->save_object();
443 $this->CopyPasteHandler->SetVar("base", $this->DivListApplication->selectedBase);
445 if($str = $this->CopyPasteHandler->execute()) {
446 return($str);
447 }
448 }
450 /* Copy current object to CopyHandler
451 */
452 if($s_action == "copy"){
453 $this->CopyPasteHandler->Clear();
454 $dn = $this->applications[$s_entry]['dn'];
455 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
456 $objNew = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], "new");
457 $this->CopyPasteHandler->Copy($obj,$objNew);
458 }
460 /* Copy current object to CopyHandler
461 */
462 if($s_action == "cut"){
463 $this->CopyPasteHandler->Clear();
464 $dn = $this->applications[$s_entry]['dn'];
465 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
466 $this->CopyPasteHandler->Cut($obj);
467 }
468 }
470 /* Save to LDAP */
471 function save()
472 {
473 /* Optionally execute a command after we're done */
474 $this->postcreate();
475 }
477 function remove_lock()
478 {
479 if (isset($this->apptabs->dn)){
480 del_lock ($this->apptabs->dn);
481 }
482 }
484 function save_object() {
485 $this->DivListApplication->save_object();
486 }
488 function check() {}
489 function adapt_from_template($dn) {}
490 function password_change_needed() {}
491 }
492 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
493 ?>