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 */
22 /* Preset display */
23 $display = "";
24 $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 sess_del ('edit');
32 sess_del ('user');
33 }
35 /* Create user object on demand */
36 if (!isset($_SESSION['user']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
37 $_SESSION['user']= new user ($config, $ui->dn);
38 $_SESSION['user']->set_acl_base($ui->dn);
39 $_SESSION['user']->set_acl_category("users");
40 }
41 $user= $_SESSION['user'];
43 /* save changes back to object */
44 if (isset ($_SESSION['edit'])){
45 $user->save_object ();
46 }
48 /* Enter edit mode? */
49 if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit'])) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
51 /* Check locking */
52 if (($username= get_lock($ui->dn)) != ""){
53 $_SESSION['back_plugin']= $plug;
54 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit$/","/^plug$/");
55 $lock_msg = gen_locked_message ($username, $ui->dn);
57 }else{
59 /* Lock the current entry */
60 add_lock ($ui->dn, $ui->dn);
61 $_SESSION['dn']= $ui->dn;
62 $_SESSION['edit']= TRUE;
63 }
64 }
66 /* Perform password change */
67 if (isset($_POST['password_finish'])){
69 /* For security reasons, check if user is allowed to set password again */
70 if ($user->acl_is_writable("userPassword") || $user->acl_is_createable()){
72 /* Check input and feed errors into 'message' */
73 $message= array();
75 /* Sanity checks... */
76 if ($_POST['new_password'] != $_POST['repeated_password']){
78 /* Matching passwords in new and repeated? */
79 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
80 } else {
82 /* Empty password is not permitted by default. */
83 if ($_POST['new_password'] == ""){
84 $message[]= _("The password you've entered as 'New password' is empty.");
85 }
86 }
88 /* Errors, or change password? */
89 if (count($message) != 0){
91 /* Show error message and continue editing */
92 show_errors ($message);
93 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
94 return ($display);
95 }
96 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
97 new log("modify","users/".get_class($this),"",array(),"Password has been changed");
99 } else {
101 /* Missing permissions, show message */
102 print_red (_("You are not allowed to set your password!"));
103 }
105 del_lock ($ui->dn);
106 }
108 /* save changes to LDAP and disable edit mode */
109 if (isset($_POST['edit_finish'])){
111 /* Perform checks */
112 $message= $user->check ();
114 /* No errors, save object */
115 if (count ($message) == 0){
116 $user->save ();
117 del_lock ($ui->dn);
118 sess_del ('edit');
120 /* Save object */
121 $_SESSION['user']= $user;
123 /* Need to reset the password? */
124 if($user->password_change_needed()){
125 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
126 return ($display);
127 }
129 } else {
130 /* Errors found, show message */
131 show_errors ($message);
132 }
133 }
135 /* Execute formular */
136 if($lock_msg){
137 $display.= $lock_msg;
138 }else{
139 $display.= $user->execute ();
140 }
142 /* Store changes in session */
143 if (isset ($_SESSION['edit'])){
144 $_SESSION['user']= $user;
145 }
147 $info = "";
149 /* Show page footer depending on the mode */
150 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
151 $display.= "<p class=\"plugbottom\">";
153 /* Are we in edit mode? */
154 if (isset($_SESSION['edit'])){
155 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
156 $display.= " ";
157 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
159 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
160 "\"> ".$ui->dn." ";
161 } else {
162 /* 'viewid' may be set by i.e. the phonelist plugin. This
163 means that we want to go back... */
164 if (isset ($viewid)){
165 $str= _("Back");
166 $fn = "back";
167 } else {
168 $str= _("Edit");
169 $fn = "edit";
170 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
171 "\"> ".$ui->dn." ";
172 }
174 /* Only display edit button if there is at least one attribute editable */
175 if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
176 if ($fn == "edit"){
177 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
178 _("Click the 'Edit' button below to change informations in this dialog");
179 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
180 }
181 }
183 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
184 }
185 $display.= "</p>\n";
186 }
188 /* Page header*/
189 $display= print_header(get_template_path('images/personal.png'),
190 _("Generic user information"), $info).$display;
192 }
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>