Code

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