f3826f4d3ca59d89d8e51469e05297453573c272
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= "";
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 }
38 $user= $_SESSION['user'];
40 /* save changes back to object */
41 if (isset ($_SESSION['edit'])){
42 $user->save_object ();
43 }
45 /* Enter edit mode? */
46 if (isset($_POST['edit'])){
48 /* Check locking */
49 if (($username= get_lock($ui->dn)) != ""){
50 $_SESSION['back_plugin']= $plug;
51 gen_locked_message ($username, $ui->dn);
52 exit ();
53 }
55 /* Lock the current entry */
56 add_lock ($ui->dn, $ui->dn);
57 $_SESSION['dn']= $ui->dn;
58 $_SESSION['edit']= TRUE;
59 }
61 /* Adjust acl's to mode */
62 if (isset($_SESSION['edit'])){
63 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
64 $user->acl= get_module_permission($acl, "user", $ui->dn);
65 } else {
66 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
67 $editacl= get_module_permission($acl, "user", $ui->dn);
68 $user->acl= "#none#";
69 }
71 /* Perform password change */
72 if (isset($_POST['password_finish'])){
74 /* For security reasons, check if user is allowed to set password again */
75 if (chkacl($user->acl, "password") == "" || chkacl($user->acl, "create")){
77 /* Check input and feed errors into 'message' */
78 $message= array();
80 /* Sanity checks... */
81 if ($_POST['new_password'] != $_POST['repeated_password']){
83 /* Matching passwords in new and repeated? */
84 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
85 } else {
87 /* Empty password is not permitted by default. */
88 if ($_POST['new_password'] == ""){
89 $message[]= _("The password you've entered as 'New password' is empty.");
90 }
91 }
93 /* Errors, or change password? */
94 if (count($message) != 0){
96 /* Show error message and continue editing */
97 show_errors ($message);
98 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
99 return ($display);
100 }
101 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
102 gosa_log ("Password for '".$user->dn."' has been changed");
104 } else {
106 /* Missing permissions, show message */
107 print_red (_("You are not allowed to set your password!"));
108 }
110 $user->acl= "#none#";
111 del_lock ($ui->dn);
112 }
114 /* save changes to LDAP and disable edit mode */
115 if (isset($_POST['edit_finish'])){
117 /* Perform checks */
118 $message= $user->check ();
120 /* No errors, save object */
121 if (count ($message) == 0){
122 $user->save ();
123 gosa_log ("User/generic object'".$ui->dn."' has been saved");
124 $user->acl= "#none#";
125 del_lock ($ui->dn);
126 sess_del ('edit');
128 /* Save object */
129 $_SESSION['user']= $user;
131 /* Need to reset the password? */
132 if($user->password_change_needed()){
133 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
134 return ($display);
135 }
137 } else {
138 /* Errors found, show message */
139 show_errors ($message);
140 }
141 }
143 /* Execute formular */
144 $display.= $user->execute ();
146 /* Store changes in session */
147 if (isset ($_SESSION['edit'])){
148 $_SESSION['user']= $user;
149 }
151 $info = "";
152 /* Show page footer depending on the mode */
153 if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
154 $display.= "<p class=\"plugbottom\">";
156 /* Are we in edit mode? */
157 if (isset($_SESSION['edit'])){
158 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
159 $display.= " ";
160 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
161 $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
162 "\"> ".$ui->dn." ";
163 } else {
164 /* 'viewid' may be set by i.e. the phonelist plugin. This
165 means that we want to go back... */
166 if (isset ($viewid)){
167 $str= _("Back");
168 $fn = "back";
169 } else {
170 $str= _("Edit");
171 $fn = "edit";
172 $info= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
173 "\"> ".$ui->dn." ";
174 }
175 if ($fn == "edit" && isset($editacl) && $editacl != "#none#"){
176 $info.= "<img alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
177 _("Click the 'Edit' button below to change informations in this dialog");
178 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
179 }
180 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
181 }
182 $display.= "</p>\n";
183 }
185 /* Page header*/
186 $display= print_header(get_template_path('images/personal.png'),
187 _("Generic user information"), $info).$display;
189 }
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>