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 = "";
25 if (!$remove_lock){
26 /* Reset requested? */
27 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) ||
28 (isset($_GET['reset']) && $_GET['reset'] == 1)){
29 del_lock ($ui->dn);
30 sess_del ('edit');
31 sess_del ('user');
32 }
34 /* Create user object on demand */
35 if (!isset($_SESSION['user']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
36 $_SESSION['user']= new user ($config, $ui->dn);
37 $_SESSION['user']->enable_CSN_check();
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_writeable("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/password","",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 sess_del ('user');
107 }
109 /* save changes to LDAP and disable edit mode */
110 if (isset($_POST['edit_finish'])){
112 /* Perform checks */
113 $message= $user->check ();
115 /* No errors, save object */
116 if (count ($message) == 0){
117 $user->save ();
118 del_lock ($ui->dn);
119 sess_del ('edit');
121 /* Need to reset the password? */
122 if($user->password_change_needed()){
123 /* Save object */
124 $_SESSION['user']= $user;
126 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
127 return ($display);
128 } else {
129 sess_del ('user');
130 }
132 } else {
133 /* Errors found, show message */
134 show_errors ($message);
135 }
136 }
138 /* Execute formular */
139 if($lock_msg){
140 $display.= $lock_msg;
141 }else{
142 $display.= $user->execute ();
143 }
145 /* Store changes in session */
146 if (isset ($_SESSION['edit'])){
147 $_SESSION['user']= $user;
148 }
150 $info = "";
152 /* Show page footer depending on the mode */
153 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
154 $display.= "<p class=\"plugbottom\">";
156 /* Are we in edit mode? */
157 if (isset($_SESSION['edit'])){
158 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
159 $display.= " ";
160 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
162 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
163 "\"> ".$ui->dn." ";
164 } else {
165 /* 'viewid' may be set by i.e. the phonelist plugin. This
166 means that we want to go back... */
167 if (isset ($viewid)){
168 $str= _("Back");
169 $fn = "back";
170 } else {
171 $str= _("Edit");
172 $fn = "edit";
173 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
174 "\"> ".$ui->dn." ";
175 }
177 /* Only display edit button if there is at least one attribute editable */
178 if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
179 if ($fn == "edit"){
180 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
181 _("Click the 'Edit' button below to change informations in this dialog");
182 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
183 }
184 }
186 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
187 }
188 $display.= "</p>\n";
189 }
191 /* Page header*/
192 $display= print_header(get_template_path('images/personal.png'),
193 _("Generic user information"), $info).$display;
195 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>