Code

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