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'])) && (!isset( $_SESSION['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 $editacl= get_module_permission($acl, "user", $ui->dn);
126 del_lock ($ui->dn);
127 sess_del ('edit');
129 /* Save object */
130 $_SESSION['user']= $user;
132 /* Need to reset the password? */
133 if($user->password_change_needed()){
134 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
135 return ($display);
136 }
138 } else {
139 /* Errors found, show message */
140 show_errors ($message);
141 }
142 }
144 /* Execute formular */
145 $display.= $user->execute ();
147 /* Store changes in session */
148 if (isset ($_SESSION['edit'])){
149 $_SESSION['user']= $user;
150 }
152 $info = "";
153 /* Show page footer depending on the mode */
154 if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
155 $display.= "<p class=\"plugbottom\">";
157 /* Are we in edit mode? */
158 if (isset($_SESSION['edit'])){
159 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
160 $display.= " ";
161 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
162 $display.="<script language='javascript'>";
164 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.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= _("Back");
171 $fn = "back";
172 } else {
173 $str= _("Edit");
174 $fn = "edit";
175 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
176 "\"> ".$ui->dn." ";
177 }
179 if ($fn == "edit" && isset($editacl) && $editacl != "#none#"){
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 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
185 }
186 $display.= "</p>\n";
187 }
189 /* Page header*/
190 $display= print_header(get_template_path('images/personal.png'),
191 _("Generic user information"), $info).$display;
193 }
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>