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\" style=\"width:80px\" value=\""._("Ok")."\">\n";
159 $display.= " ";
160 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
161 $display.="<script language='javascript'>";
163 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
164 "\"> ".$ui->dn." ";
165 } else {
166 /* 'viewid' may be set by i.e. the phonelist plugin. This
167 means that we want to go back... */
168 if (isset ($viewid)){
169 $str= _("Back");
170 $fn = "back";
171 } else {
172 $str= _("Edit");
173 $fn = "edit";
174 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
175 "\"> ".$ui->dn." ";
176 }
177 if ($fn == "edit" && isset($editacl) && $editacl != "#none#"){
178 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
179 _("Click the 'Edit' button below to change informations in this dialog");
180 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
181 }
182 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
183 }
184 $display.= "</p>\n";
185 }
187 /* Page header*/
188 $display= print_header(get_template_path('images/personal.png'),
189 _("Generic user information"), $info).$display;
191 }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>