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 /* Remove locks created by this plugin
24 */
25 $lock_msg="";
26 if ($remove_lock || isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
27 if(session::is_set('user') && session::is_set('edit')){
28 del_lock($ui->dn);
29 }
30 }
32 /* Remove this plugin from session
33 */
34 if ( $cleanup ){
35 session::un_set('user');
36 session::un_set('edit');
38 }else{
40 /* Reset requested? */
41 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
42 session::un_set ('edit');
43 session::un_set ('user');
44 }
46 /* Create user object on demand */
47 if (!session::is_set('user') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
48 $user= new user ($config, $ui->dn);
49 $user->enable_CSN_check();
50 $user->set_acl_base($ui->dn);
51 $user->set_acl_category("users");
52 session::set('user',$user);
53 }
54 $user = session::get('user');
56 /* save changes back to object */
57 if (session::is_set('edit')){
58 $user->save_object ();
59 }
61 /* Enter edit mode? */
62 if ((isset($_POST['edit'])) && (!session::is_set('edit')) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
64 /* Check locking */
65 if (($username= get_lock($ui->dn)) != ""){
66 session::set('back_plugin',$plug);
67 session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
68 $lock_msg = gen_locked_message ($username, $ui->dn);
70 }else{
72 /* Lock the current entry */
73 add_lock ($ui->dn, $ui->dn);
74 session::set('dn',$ui->dn);
75 session::set('edit',TRUE);
76 }
77 }
79 /* Perform password change */
80 if (isset($_POST['password_finish'])){
82 /* For security reasons, check if user is allowed to set password again */
83 if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
85 /* Check input and feed errors into 'message' */
86 $message= array();
88 /* Sanity checks... */
89 if ($_POST['new_password'] != $_POST['repeated_password']){
91 /* Matching passwords in new and repeated? */
92 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
93 } else {
95 /* Empty password is not permitted by default. */
96 if ($_POST['new_password'] == ""){
97 $message[]= msgPool::required(_("New password"));
98 }
99 }
101 /* Errors, or change password? */
102 if (count($message) != 0){
104 /* Show error message and continue editing */
105 msg_dialog::displayChecks($message);
106 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
107 return ($display);
108 }
109 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
110 new log("modify","users/password","",array(),"Password has been changed");
112 } else {
114 /* Missing permissions, show message */
115 msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
116 }
118 del_lock ($ui->dn);
119 session::un_set ('user');
120 }
122 /* save changes to LDAP and disable edit mode */
123 if (isset($_POST['edit_finish'])){
125 /* Perform checks */
126 $message= $user->check ();
128 /* No errors, save object */
129 if (count ($message) == 0){
130 $user->save ();
131 del_lock ($ui->dn);
132 session::un_set ('edit');
134 /* Need to reset the password? */
135 if($user->password_change_needed()){
136 /* Save object */
137 session::set('user',$user);
139 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
140 return ($display);
141 } else {
142 session::un_set ('user');
143 }
145 } else {
146 /* Errors found, show message */
147 msg_dialog::displayChecks($message);
148 }
149 }
151 /* Execute formular */
152 if($lock_msg){
153 $display.= $lock_msg;
154 }else{
155 $display.= $user->execute ();
156 }
158 /* Store changes in session */
159 if (session::is_set('edit')){
160 session::set('user',$user);
161 }
163 $info = "";
165 /* Show page footer depending on the mode */
166 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
167 $display.= "<p class=\"plugbottom\">";
169 /* Are we in edit mode? */
170 if (session::is_set('edit')){
171 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
172 $display.= " ";
173 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
175 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
176 "\"> ".$ui->dn." ";
177 } else {
178 /* 'viewid' may be set by i.e. the phonelist plugin. This
179 means that we want to go back... */
180 if (isset ($viewid)){
181 $str= msgPool::backButton();
182 $fn = "back";
183 } else {
184 $str= msgPool::editButton();
185 $fn = "edit";
186 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
187 "\"> ".$ui->dn." ";
188 }
190 /* Only display edit button if there is at least one attribute editable */
191 if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/user"))){
192 if ($fn == "edit"){
193 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\"> ".
194 msgPool::clickEditToChange();
195 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
196 }
197 }
199 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
200 }
201 $display.= "</p>\n";
202 }
204 /* Page header*/
205 $display= print_header(get_template_path('plugins/generic/images/plugin.png'),
206 _("Generic user information"), $info).$display;
208 }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>