Code

Updated MyAccount
[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       $MyAccountTabs->setReadOnly(TRUE);
78       if(isset($MyAccountTabs->by_object['user']) && $MyAccountTabs->by_object['user']->password_change_needed()){
79         $MyAccountTabs->password_change_needed = TRUE;
80       }else{
81         session::un_set ('MyAccountTabs');
82       }
83     } else {
84       msg_dialog::displayChecks($message);
85     }
86   }
89   if (isset($_POST['password_finish']) && $MyAccountTabs->password_change_needed){
90     $user = $MyAccountTabs->by_object['user'];
92     if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
93       $message= array();
94       if ($_POST['new_password'] != $_POST['repeated_password']){
95         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
96       } else {
97         if ($_POST['new_password'] == ""){
98           $message[]= msgPool::required(_("New password"));
99         }
100       }
102       if (count($message) != 0){
103         msg_dialog::displayChecks($message);
104         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
105         return ($display);
106       }
107       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
108       $MyAccountTabs= new MyAccountTabs($config,$config->data['TABS']['MYACCOUNTTABS'], $ui->dn, "users", true, true);
109       $MyAccountTabs->setReadOnly(TRUE);
110       session::set('MyAccountTabs',$MyAccountTabs);
111       new log("modify","users/password","",array(),"Password has been changed");
112     } else {
113       msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
114     }
116     del_lock ($ui->dn);
117     session::un_set ('user');
118   }
120   if($MyAccountTabs->password_change_needed){
121     $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
122   }
124   /* Execute formular */
125   if(!$MyAccountTabs->password_change_needed){
126     pathNavigator::registerPlugin(_("My account"));
127     if($lock_msg){
128       $display = $lock_msg;
129     }else{
130       $display.= $MyAccountTabs->execute ();
131     }
132   }
134   /* Store changes  in session */
135   if (session::is_set('edit')){
136     session::set('MyAccountTabs',$MyAccountTabs);
137   }
139   /* Show page footer depending on the mode */
140   if (!$MyAccountTabs->is_modal_dialog() && empty($lock_msg) && !$MyAccountTabs->password_change_needed){
142     $display.= "<div class='plugin-actions'>";
144     /* Are we in edit mode? */
145     if (session::is_set('edit')){
146       $display.= "<button class='button' type='submit' name='edit_finish'>".msgPool::okButton()."</button>\n";
147       $display.= "<button class='button' type='submit' name='edit_cancel'>".msgPool::cancelButton()."</button>\n";
148     } else {
149       if(preg_match("/r/",$ui->get_category_permissions($ui->dn,"users"))){
150         $display.= "<button class='button' type='submit' name='edit'>".msgPool::editButton()."</button>\n";
151       }
152       $display.= "<input type='hidden' name='ignore'>\n";
153     }
154     $display.= "</div>\n";
155   }
158 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
159 ?>