1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Preset display */
24 $display = "";
25 $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)){
31 /* Only remove lock if object was opened
32 */
33 if(session::is_set('user') && session::is_set('edit')){
34 del_lock ($ui->dn);
35 }
36 session::un_set ('edit');
37 session::un_set ('user');
38 }
40 /* Create user object on demand */
41 if (!session::is_set('user') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
42 $user= new user ($config, $ui->dn);
43 $user->enable_CSN_check();
44 $user->set_acl_base($ui->dn);
45 $user->set_acl_category("users");
46 session::set('user',$user);
47 }
48 $user = session::get('user');
50 /* save changes back to object */
51 if (session::is_set('edit')){
52 $user->save_object ();
53 }
55 /* Enter edit mode? */
56 if ((isset($_POST['edit'])) && (!session::is_set('edit')) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
58 /* Check locking */
59 if (($username= get_lock($ui->dn)) != ""){
60 session::set('back_plugin',$plug);
61 session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
62 $lock_msg = gen_locked_message ($username, $ui->dn);
64 }else{
66 /* Lock the current entry */
67 add_lock ($ui->dn, $ui->dn);
68 session::set('dn',$ui->dn);
69 session::set('edit',TRUE);
70 }
71 }
73 /* Perform password change */
74 if (isset($_POST['password_finish'])){
76 /* For security reasons, check if user is allowed to set password again */
77 if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
79 /* Check input and feed errors into 'message' */
80 $message= array();
82 /* Sanity checks... */
83 if ($_POST['new_password'] != $_POST['repeated_password']){
85 /* Matching passwords in new and repeated? */
86 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
87 } else {
89 /* Empty password is not permitted by default. */
90 if ($_POST['new_password'] == ""){
91 $message[]= msgPool::required(_("New password"));
92 }
93 }
95 /* Errors, or change password? */
96 if (count($message) != 0){
98 /* Show error message and continue editing */
99 msg_dialog::displayChecks($message);
100 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
101 return ($display);
102 }
103 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
104 new log("modify","users/password","",array(),"Password has been changed");
106 } else {
108 /* Missing permissions, show message */
109 msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
110 }
112 del_lock ($ui->dn);
113 session::un_set ('user');
114 }
116 /* save changes to LDAP and disable edit mode */
117 if (isset($_POST['edit_finish'])){
119 /* Perform checks */
120 $message= $user->check ();
122 /* No errors, save object */
123 if (count ($message) == 0){
124 $user->save ();
125 del_lock ($ui->dn);
126 session::un_set ('edit');
128 /* Need to reset the password? */
129 if($user->password_change_needed()){
130 /* Save object */
131 session::set('user',$user);
133 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
134 return ($display);
135 } else {
136 session::un_set ('user');
137 }
139 } else {
140 /* Errors found, show message */
141 msg_dialog::displayChecks($message);
142 }
143 }
145 /* Execute formular */
146 if($lock_msg){
147 $display.= $lock_msg;
148 }else{
149 $display.= $user->execute ();
150 }
152 /* Store changes in session */
153 if (session::is_set('edit')){
154 session::set('user',$user);
155 }
157 $info = "";
159 /* Show page footer depending on the mode */
160 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
161 $display.= "<p class=\"plugbottom\">";
163 /* Are we in edit mode? */
164 if (session::is_set('edit')){
165 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
166 $display.= " ";
167 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
169 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
170 "\"> ".$ui->dn." ";
171 } else {
172 /* 'viewid' may be set by i.e. the phonelist plugin. This
173 means that we want to go back... */
174 if (isset ($viewid)){
175 $str= msgPool::backButton();
176 $fn = "back";
177 } else {
178 $str= msgPool::editButton();
179 $fn = "edit";
180 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
181 "\"> ".$ui->dn." ";
182 }
184 /* Only display edit button if there is at least one attribute editable */
185 if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/user"))){
186 if ($fn == "edit"){
187 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\"> ".
188 msgPool::clickEditToChange();
189 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
190 }
191 }
193 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
194 }
195 $display.= "</p>\n";
196 }
198 /* Page header*/
199 $display= print_header(get_template_path('plugins/generic/images/plugin.png'),
200 _("Generic user information"), $info).$display;
202 }
204 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
205 ?>