Code

Fixed locking in myAccountTabs
[gosa.git] / gosa-core / plugins / personal / myaccount / main.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: main.inc 15315 2010-01-26 13:00:52Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
24 /* Remove locks created by this plugin
25 */
26 $lock_msg="";
27 if ($remove_lock || isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
28   del_lock($ui->dn);
29   if(session::is_set('MyAccountTabs') && session::is_set('edit')){
30     session::un_set('MyAccountTabs');
31   }
32 }
34 /* Reset requested? */
35 if (isset($_POST['edit_cancel']) || $cleanup){
36   session::un_set ('edit');
37   session::un_set ('MyAccountTabs');
38 }
40 /* Remove this plugin from session
41  */
42 if (! $cleanup ){
44   /* Create MyAccountTabs object on demand */
45   if (!session::is_set('MyAccountTabs') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
46     $MyAccountTabs= new MyAccountTabs($config,$config->data['TABS']['MYACCOUNTTABS'], $ui->dn, "users", true, true); 
47     $MyAccountTabs->setReadOnly(TRUE);
48     session::set('MyAccountTabs',$MyAccountTabs);
49   }
50   $MyAccountTabs = session::get('MyAccountTabs');
51   
52   /* Enter edit mode? */
53   if ((isset($_POST['edit'])) && (!session::is_set('edit'))){
54     
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, array($ui->dn));
61     }else{
63       /* Lock the current entry */
64       add_lock ($ui->dn, $ui->dn);
65       session::set('edit',TRUE);
66       $MyAccountTabs->setReadOnly(FALSE);
67     }
68   }
70   $info= "";
71   if (isset($_POST['edit_finish'])){
72     $message= $MyAccountTabs->check ();
73     if (count ($message) == 0){
74       $MyAccountTabs->save ();
75       del_lock ($ui->dn);
76       session::un_set ('edit');
77       if(isset($MyAccountTabs->by_object['user']) && $MyAccountTabs->by_object['user']->password_change_needed()){
78         $MyAccountTabs->password_change_needed = TRUE;
79       }else{
80         session::un_set ('MyAccountTabs');
81       }
82     } else {
83       msg_dialog::displayChecks($message);
84     }
85   }
88   if (isset($_POST['password_finish']) && $MyAccountTabs->password_change_needed){
89     $user = $MyAccountTabs->by_object['user'];
91     if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
92       $message= array();
93       if ($_POST['new_password'] != $_POST['repeated_password']){
94         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
95       } else {
96         if ($_POST['new_password'] == ""){
97           $message[]= msgPool::required(_("New password"));
98         }
99       }
101       if (count($message) != 0){
102         msg_dialog::displayChecks($message);
103         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
104         return ($display);
105       }
106       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
107       $MyAccountTabs= new MyAccountTabs($config,$config->data['TABS']['MYACCOUNTTABS'], $ui->dn, "users", true, true);
108       $MyAccountTabs->setReadOnly(TRUE);
109       session::set('MyAccountTabs',$MyAccountTabs);
110       new log("modify","users/password","",array(),"Password has been changed");
111     } else {
112       msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
113     }
115     del_lock ($ui->dn);
116     session::un_set ('user');
117   }
119   if($MyAccountTabs->password_change_needed){
120     $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
121   }
123   /* Execute formular */
124   if(!$MyAccountTabs->password_change_needed){
125     pathNavigator::registerPlugin(_("My account"));
126     if($lock_msg){
127       $display = $lock_msg;
128     }else{
129       $display.= $MyAccountTabs->execute ();
130     }
131   }
133   /* Store changes  in session */
134   if (session::is_set('edit')){
135     session::set('MyAccountTabs',$MyAccountTabs);
136   }
138   /* Show page footer depending on the mode */
139   if (!$MyAccountTabs->is_modal_dialog() && empty($lock_msg) && !$MyAccountTabs->password_change_needed){
141     $display.= "<div class='plugin-actions'>";
143     /* Are we in edit mode? */
144     if (session::is_set('edit')){
145       $display.= "<button class='button' type='submit' name='edit_finish'>".msgPool::okButton()."</button>\n";
146       $display.= "<button class='button' type='submit' name='edit_cancel'>".msgPool::cancelButton()."</button>\n";
147     } else {
148       if(preg_match("/r/",$ui->get_category_permissions($ui->dn,"users"))){
149         $display.= "<button class='button' type='submit' name='edit'>".msgPool::editButton()."</button>\n";
150       }
151       $display.= "<input type='hidden' name='ignore'>\n";
152     }
153     $display.= "</div>\n";
154   }
157 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
158 ?>