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$$
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 */
23 /* Preset display */
24 $display = "";
25 $lock_msg = "";
26 if (!$remove_lock){
27 /* Reset requested? */
28 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) ||
29 (isset($_GET['reset']) && $_GET['reset'] == 1)){
30 del_lock ($ui->dn);
31 session::un_set ('edit');
32 session::un_set ('user');
33 }
35 /* Create user object on demand */
36 if (!session::is_set('user') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
37 $user= new user ($config, $ui->dn);
38 $user->enable_CSN_check();
39 $user->set_acl_base($ui->dn);
40 $user->set_acl_category("users");
41 session::set('user',$user);
42 }
43 $user = session::get('user');
45 /* save changes back to object */
46 if (session::is_set('edit')){
47 $user->save_object ();
48 }
50 /* Enter edit mode? */
51 if ((isset($_POST['edit'])) && (!session::is_set('edit')) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
53 /* Check locking */
54 if (($username= get_lock($ui->dn)) != ""){
55 session::set('back_plugin',$plug);
56 session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
57 $lock_msg = gen_locked_message ($username, $ui->dn);
59 }else{
61 /* Lock the current entry */
62 add_lock ($ui->dn, $ui->dn);
63 session::set('dn',$ui->dn);
64 session::set('edit',TRUE);
65 }
66 }
68 /* Perform password change */
69 if (isset($_POST['password_finish'])){
71 /* For security reasons, check if user is allowed to set password again */
72 if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
74 /* Check input and feed errors into 'message' */
75 $message= array();
77 /* Sanity checks... */
78 if ($_POST['new_password'] != $_POST['repeated_password']){
80 /* Matching passwords in new and repeated? */
81 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
82 } else {
84 /* Empty password is not permitted by default. */
85 if ($_POST['new_password'] == ""){
86 $message[]= msgPool::required(_("New password"));
87 }
88 }
90 /* Errors, or change password? */
91 if (count($message) != 0){
93 /* Show error message and continue editing */
94 msg_dialog::displayChecks($message);
95 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
96 return ($display);
97 }
98 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
99 new log("modify","users/password","",array(),"Password has been changed");
101 } else {
103 /* Missing permissions, show message */
104 msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
105 }
107 del_lock ($ui->dn);
108 session::un_set ('user');
109 }
111 /* save changes to LDAP and disable edit mode */
112 if (isset($_POST['edit_finish'])){
114 /* Perform checks */
115 $message= $user->check ();
117 /* No errors, save object */
118 if (count ($message) == 0){
119 $user->save ();
120 del_lock ($ui->dn);
121 session::un_set ('edit');
123 /* Need to reset the password? */
124 if($user->password_change_needed()){
125 /* Save object */
126 session::set('user',$user);
128 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
129 return ($display);
130 } else {
131 session::un_set ('user');
132 }
134 } else {
135 /* Errors found, show message */
136 msg_dialog::displayChecks($message);
137 }
138 }
140 /* Execute formular */
141 if($lock_msg){
142 $display.= $lock_msg;
143 }else{
144 $display.= $user->execute ();
145 }
147 /* Store changes in session */
148 if (session::is_set('edit')){
149 session::set('user',$user);
150 }
152 $info = "";
154 /* Show page footer depending on the mode */
155 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
156 $display.= "<p class=\"plugbottom\">";
158 /* Are we in edit mode? */
159 if (session::is_set('edit')){
160 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
161 $display.= " ";
162 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
164 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
165 "\"> ".$ui->dn." ";
166 } else {
167 /* 'viewid' may be set by i.e. the phonelist plugin. This
168 means that we want to go back... */
169 if (isset ($viewid)){
170 $str= msgPool::backButton();
171 $fn = "back";
172 } else {
173 $str= msgPool::editButton();
174 $fn = "edit";
175 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
176 "\"> ".$ui->dn." ";
177 }
179 /* Only display edit button if there is at least one attribute editable */
180 if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
181 if ($fn == "edit"){
182 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
183 msgPool::clickEditToChange();
184 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
185 }
186 }
188 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
189 }
190 $display.= "</p>\n";
191 }
193 /* Page header*/
194 $display= print_header(get_template_path('images/personal.png'),
195 _("Generic user information"), $info).$display;
197 }
199 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
200 ?>