Code

Added cleanup variable to main.incs
[gosa.git] / gosa-plugins / goto / personal / environment / main.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 $lock_msg = "";
22 /* Remove classes and variables from session
23  */
24 if ( $cleanup ){
25   session::un_set('environment');
26   session::un_set('edit');
27 }
29 if ( $remove_lock){
30   if(session::is_set('environment') && session::is_set('edit')){
31     del_lock ($ui->dn);
32   }
34 }else{
36   /* Reset requested? */
37   if (isset($_POST['edit_cancel']) || 
38       (isset($_GET['reset']) && $_GET['reset'] == 1)){
40     /* Only remove lock if object was opened 
41      */
42     if(session::is_set('environment') && session::is_set('edit')){
43       del_lock ($ui->dn);
44     }
45     session::un_set ('edit');
46     session::un_set ('environment');
47   }
49   /* Create mail object on demand */
50   if (!session::is_set('environment') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
51     $environment= new environment ($config, $ui->dn);
52     $environment->enable_CSN_check();
53     $environment->set_acl_category('users');
54     $environment->set_acl_base($ui->dn);
55     session::set('environment',$environment);
56   }
57   $environment = session::get('environment');
59   /* save changes back to object */
60   if (session::is_set('edit')){
61     $environment->save_object ();
62   }
64   /* Enter edit mode? */
65   if (isset($_POST['edit']) || isset($_POST['delete_lock'])){
66   
67    /* Check locking */
68     if (($username= get_lock($ui->dn)) != ""){
69       session::set('back_plugin',$plug);
70       session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
71       $lock_msg =  gen_locked_message ($username, $ui->dn);
73     }else{
75       /* Lock the current entry */
76       add_lock ($ui->dn, $ui->dn);
77       session::set('edit',TRUE);
78     }
79   }
81   /* save changes to LDAP and disable edit mode */
82   if (isset($_POST['edit_finish'])){
84     /* Perform checks */
85     $message= $environment->check ();
87     /* No errors, save object */
88     if (count ($message) == 0){
89       $environment->save ();
90       del_lock ($ui->dn);
91       session::un_set ('edit');
93       /* Remove object */
94       session::un_set ('environment');
95     } else {
96       /* Errors found, show message */
97       msg_dialog::displayChecks($message);
98     }
99   }
101   /* Execute formular */
102   if($lock_msg){
103     $display = $lock_msg;
104   }else{
105     $display = $environment->execute();
106   }
108   /* Store changes  in session */
109   if (session::is_set('edit')){
110     session::set('environment',$environment);
111   }
113   $info= "";
114   /* Show page footer depending on the mode */
115   if (!$environment->in_dialog && !$environment->dialog && $environment->is_account  && empty($lock_msg)){
116     $display.= "<p class=\"plugbottom\">";
118     /* Are we in edit mode? */
119     if (session::is_set('edit')){
120       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
121       $display.= "&nbsp;";
122       $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
123       $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
124              "\"> ".$ui->dn."&nbsp;";
125     } else {
126       $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
127         "\"> ".$ui->dn."&nbsp;";
128       if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/environment"))){
129         $info.= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png').
130           "\"> ".msgPool::clickEditToChange();
131         $display.= "<input type=submit name=\"edit\" value=\"".msgPool::editButton()."\">\n";
132       }
133       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
134     }
135     $display.= "</p>\n";
136   }
138   /* Page header*/
139   $display= print_header(get_template_path('plugins/goto/images/plugin.png'), _("User environment settings"), $info).$display;
143 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
144 ?>