Code

1d57e66edee04cd26c26954b64c419f1f6785edd
[gosa.git] / sudo-ldap / addons / sudo / main.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2008  Guido Serra <gserra@guidoserra.it>
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  */
21 /* Clear display */
22 $display= "";
24 if (!$remove_lock){
26   /* Reset requested? */
27   if (isset($_POST['edit_cancel']) ||
28       (isset($_GET['reset']) && $_GET['reset'] == 1)){
30     del_lock ($ui->dn);
31     sess_del ('edit');
32     sess_del ('sudoldap');
33   }
35   /* Create sudoldap object on demand */
36   if (!isset($_SESSION['sudoldap']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
37     $_SESSION['sudoldap']= new sudoldap ($config, $ui->dn);
38   }
39   $sudoldap= $_SESSION['sudoldap'];
41   /* save changes back to object */
42   if (isset ($_SESSION['edit'])){
43     $sudoldap->save_object ();
44   }
46   /* Enter edit mode? */
47   if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit']))){
49     /* Check locking */
50     if (($username= get_lock($ui->dn)) != ""){
51       $_SESSION['back_plugin']= $plug;
52       gen_locked_message ($username, $ui->dn);
53       exit ();
54     }
56     /* Lock the current entry */
57     add_lock ($ui->dn, $ui->dn);
58     $_SESSION['dn']= $ui->dn;
59     $_SESSION['edit']= TRUE;
60   }
62   /* Adjust acl's to mode */
63   if (isset($_SESSION['edit'])){
64     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
65     $sudoldap->acl= get_module_permission($acl, "sudoldap", $ui->dn);
66   } else {
67     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
68     $editacl= get_module_permission($acl, "sudoldap", $ui->dn);
69     $sudoldap->acl= "#none#";
70   }
72   /* save changes to LDAP and disable edit mode */
73   $info= "";
74   if (isset($_POST['edit_finish'])){
76     /* Perform checks */
77     $message= $sudoldap->check ();
79     /* No errors, save object */
80     if (count ($message) == 0){
81       $sudoldap->save ();
82       gosa_log ("SUDO/ldap object'".$ui->dn."' has been saved");
83       $sudoldap->acl= "#none#";
84       $editacl= get_module_permission($acl, "sudoldap", $ui->dn);
85       del_lock ($ui->dn);
86       sess_del ('edit');
88       /* Remove from session */
89       sess_del ('sudoldap');
90     } else {
91       /* Errors found, show message */
92       show_errors ($message);
93     }
94   }
96   /* Execute formular */
97   $display.= $sudoldap->execute ();
99   /* Store changes  in session */
100   if (isset ($_SESSION['edit'])){
101     $_SESSION['sudoldap']= $sudoldap;
102   }
104   /* Page header*/
105   $display= print_header(get_template_path('images/posix.png'),
106                          _("sudo-ldap"), $info).$display;
110 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
111 ?>