Code

Fixed stupid error
[gosa.git] / plugins / admin / applications / class_applicationManagement.inc
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 $acl                      = "";
35   var $enableReleaseManagement  = false;
37   function IsReleaseManagementActivated($config)
38   {
39     /* Check if we should enable the release selection */
40     $tmp = search_config($this->config->data,"faiManagement","CLASS");
41     if(!empty($tmp)){
42       return(true);
43     }
44     return(false);
45   }
47   function applicationManagement ($config, $ui)
48   {
49     /* Save configuration for internal use */
50     $this->config   = $config;
51     $this->ui       = $ui;
53     /* Check if copy & paste is activated */
54     if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
55       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
56     }
58     /* Creat dialog object */
59     $this->DivListApplication = new divListApplication($this->config,$this);
61     if($this->IsReleaseManagementActivated($this->config)){
62     /* Check if we should enable the release selection */
63       $this->enableReleaseManagement = true;
65       /* Hide SubSearch checkbox */
66       $this->DivListApplication->DisableCheckBox("SubSearch");
67     }
68   }
70   function getReleases($base)
71   {
72     $ldap                   = $this->config->get_ldap_link();
73     $dn                     = "ou=apps,".$base;
74     $ret                    = array();
75     $ret [$base] = "/";
77     $ldap->cd($dn);
78     $ldap->search("objectClass=organizationalUnit",array("ou"));
80     while($attrs = $ldap->fetch()){
81       $str = str_replace($dn,"",$attrs['dn']);
82       $tmp = array_reverse( split("ou=",$str));
83       $str = "";
84       foreach($tmp as $val){
85         $val = trim(preg_replace("/,/","",$val));
86         if(empty($val)) break;
87         $str .= "/".$val;
88       } 
89       if(!empty($str)){
90         $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
91       }
92     }
93     asort($ret);
94     return($ret);
95   }
97   function execute()
98   {
99     /* Call parent execute */
100     plugin::execute();
103     /**************** 
104       Variable init 
105      ****************/
107     /* These vars will be stored if you try to open a locked app, 
108         to be able to perform your last requests after showing a warning message */
109     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/");
111     $smarty       = get_smarty();             // Smarty instance
112     $s_action     = "";                       // Contains the action to proceed
113     $s_entry      = "";                       // The value for s_action
114     $base_back    = "";                       // The Link for Backbutton
115     
116     /* Test Posts */
117     foreach($_POST as $key => $val){
118       // Post for delete
119       if(preg_match("/appl_del.*/",$key)){
120         $s_action = "del";
121         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
122         // Post for edit
123       }elseif(preg_match("/appl_edit_.*/",$key)){
124         $s_action="edit";
125         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
126         // Post for new
127       }elseif(preg_match("/^copy_.*/",$key)){
128         $s_action="copy";
129         $s_entry  = preg_replace("/^copy_/i","",$key);
130       }elseif(preg_match("/^cut_.*/",$key)){
131         $s_action="cut";
132         $s_entry  = preg_replace("/^cut_/i","",$key);
133         // Post for new
134       }elseif(preg_match("/^appl_new.*/",$key)){
135         $s_action="new";
136       }elseif(preg_match("/^editPaste.*/i",$key)){
137         $s_action="editPaste";
138       }
139     }
141     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
142       $s_action ="edit";
143       $s_entry  = $_GET['id'];
144     }
146     $s_entry  = preg_replace("/_.$/","",$s_entry);
149     /**************** 
150       Copy & Paste handling  
151      ****************/
153     /* Only perform copy / paste if it is enabled 
154      */
155     if($this->CopyPasteHandler){
156       if($str = $this->copyPasteHandling($s_action,$s_entry)){
157        return($str);
158       };
159     }
162     /**************** 
163       Create a new app 
164      ****************/
166     /* New application? */
167     if ($s_action=="new"){
169       /* By default we set 'dn' to 'new', all relevant plugins will
170          react on this. */
171       $this->dn= "new";
173       /* Create new usertab object */
174       $this->apptabs= new apptabs($this->config,
175           $this->config->data['TABS']['APPSTABS'], $this->dn);
176       $this->apptabs->set_acl(array(':all'));
177     }
180     /**************** 
181       Edit entry canceled 
182      ****************/
184     /* Cancel dialogs */
185     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
186       del_lock ($this->apptabs->dn);
187       unset ($this->apptabs);
188       $this->apptabs= NULL;
189       unset ($_SESSION['objectinfo']);
190     }
193     /**************** 
194       Edit entry finished 
195      ****************/
197     /* Finish apps edit is triggered by the tabulator dialog, so
198        the user wants to save edited data. Check and save at this
199        point. */
200     if ((isset($_POST['edit_finish'])) && (isset($this->apptabs->config))){
202       /* Check tabs, will feed message array */
203       $this->apptabs->last= $this->apptabs->current;
204       $this->apptabs->save_object();
205       $message= $this->apptabs->check();
207       /* Save, or display error message? */
208       if (count($message) == 0){
210         /* Save data data to ldap */
211         $this->apptabs->set_release($this->DivListApplication->selectedRelease);
212         $this->apptabs->save();
213         gosa_log ("Application object'".$this->dn."' has been saved");
215         /* Application has been saved successfully, remove lock from
216            LDAP. */
217         if ($this->dn != "new"){
218           del_lock ($this->dn);
219         }
220         unset ($this->apptabs);
221         $this->apptabs= NULL;
222         unset ($_SESSION['objectinfo']);
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       /* Set up the users ACL's for this 'dn' */
252       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
254       /* Register apptabs to trigger edit dialog */
255       $this->apptabs= new apptabs($this->config,
256           $this->config->data['TABS']['APPSTABS'], $this->dn);
257       $this->apptabs->set_acl($acl);
258       $_SESSION['objectinfo']= $this->dn;
259     }
262     /**************** 
263       Delete app 
264      ****************/
266     /* Remove user was requested */
267     if ($s_action == "del"){
269       /* Get 'dn' from posted 'uid' */
270       $this->dn= $this->applications[$s_entry]['dn'];
272       /* Load permissions for selected 'dn' and check if
273          we're allowed to remove this 'dn' */
274       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
275       $this->acl= get_module_permission($acl, "application", $this->dn);
276       if (chkacl($this->acl, "delete") == ""){
278         /* Check locking, save current plugin in 'back_plugin', so
279            the dialog knows where to return. */
280         if (($user= get_lock($this->dn)) != ""){
281           return (gen_locked_message ($user, $this->dn));
282         }
284         /* Lock the current entry, so nobody will edit it during deletion */
285         add_lock ($this->dn, $this->ui->dn);
286         $smarty= get_smarty();
287         $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), @LDAP::fix($this->dn)));
288         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
289       } else {
291         /* Obviously the user isn't allowed to delete. Show message and
292            clean session. */
293         print_red (_("You are not allowed to delete this application!"));
294       }
295     }
298     /**************** 
299       Delete app confirmed 
300      ****************/
302     /* Confirmation for deletion has been passed. Group should be deleted. */
303     if (isset($_POST['delete_app_confirm'])){
305       /* Some nice guy may send this as POST, so we've to check
306          for the permissions again. */
307       if (chkacl($this->acl, "delete") == ""){
309         /* Delete request is permitted, perform LDAP action */
310         $this->apptabs= new apptabs($this->config,
311             $this->config->data['TABS']['APPSTABS'], $this->dn);
312         $this->apptabs->set_acl(array($this->acl));
313         $this->apptabs->delete ();
314         gosa_log ("Application object'".$this->dn."' has been removed");
315         unset ($this->apptabs);
316         $this->apptabs= NULL;
318       } else {
320         /* Normally this shouldn't be reached, send some extra
321            logs to notify the administrator */
322         print_red (_("You are not allowed to delete this application!"));
323         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
324       }
326       /* Remove lock file after successfull deletion */
327       del_lock ($this->dn);
328     }
331     /**************** 
332       Delete app canceled 
333      ****************/
335     /* Delete application canceled? */
336     if (isset($_POST['delete_cancel'])){
337       del_lock ($this->dn);
338       unset($_SESSION['objectinfo']);
339     }
341     /* Show tab dialog if object is present */
342     if (($this->apptabs) && (isset($this->apptabs->config))){
343       $display= $this->apptabs->execute();
345       /* Don't show buttons if tab dialog requests this */
346       if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
347         $display.= "<p style=\"text-align:right\">\n";
348         $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
349         $display.= "&nbsp;\n";
350         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
351         $display.= "</p>";
352       }
353       return ($display);
354     }
357     /****************
358       Dialog display
359      ****************/
361     /* Display dialog with system list */
362     $this->DivListApplication->execute();
363     $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase);
364     $this->reload();
365     $this->DivListApplication->setEntries($this->applications);
366     return($this->DivListApplication->Draw());
367   }
370   function reload()
371   {
372     $this->applications= array();
374     /* Set base for all searches */
375     $base       = $this->DivListApplication->selectedBase;
376     $release    = $this->DivListApplication->selectedRelease;
377     $Regex      = $this->DivListApplication->Regex;
378     $SubSearch  = $this->DivListApplication->SubSearch; 
379     $Flags      =  GL_NONE | GL_SIZELIMIT;
380     $Filter     = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
381     $tmp        = array();
382     $Releases   = $this->getReleases($base);
384     if(!$this->enableReleaseManagement){
385       $use_base = $base;
386     }else{
387       if(isset($Releases[$release])){
388         $use_base  = $release;
389       }else{
390         $use_base  = $base;
391       }
392     }
394     if($SubSearch){
395       $Flags    |= GL_SUBSEARCH;  
396     }
397    
398     $res= get_list($Filter, $this->ui->subtreeACL,$use_base, array("cn","description","dn","objectClass"), $Flags);
399     foreach ($res as $val){
400       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
401     }
403     ksort($tmp);
404     $this->applications=array();
405     foreach($tmp as $val){
406       $this->applications[]=$val;
407     }
408     reset ($this->applications);
409   }
411   function remove_from_parent()
412   {
413     /* Optionally execute a command after we're done */
414     $this->postremove();
415   }
418   function copyPasteHandling($s_action,$s_entry)
419   {
420     /* Paste copied/cutted object in here
421      */
422     if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
423       $this->CopyPasteHandler->save_object();
424       $this->CopyPasteHandler->SetVar("base", $this->DivListApplication->selectedBase);
426       if($str = $this->CopyPasteHandler->execute()) {
427         return($str);
428       }
429     }
431     /* Copy current object to CopyHandler
432      */
433     if($s_action == "copy"){
434       $this->CopyPasteHandler->Clear();
435       $dn = $this->applications[$s_entry]['dn'];
436       $obj    = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
437       $objNew = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], "new");
438       $this->CopyPasteHandler->Copy($obj,$objNew);
439     }
441     /* Copy current object to CopyHandler
442      */
443     if($s_action == "cut"){
444       $this->CopyPasteHandler->Clear();
445       $dn = $this->applications[$s_entry]['dn'];
446       $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
447       $this->CopyPasteHandler->Cut($obj);
448     }
449   }
451   /* Save to LDAP */
452   function save()
453   {
454     /* Optionally execute a command after we're done */
455     $this->postcreate();
456   }
458   function remove_lock()
459   {
460     if (isset($this->apptabs->dn)){
461       del_lock ($this->apptabs->dn);
462     }
463   }
465   function save_object() {
466     $this->DivListApplication->save_object();
467   }
469   function check() {}
470   function adapt_from_template($dn) {}
471   function password_change_needed() {}
472   function show_header($button_text, $text, $disabled= FALSE) {}
474 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
475 ?>