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){
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 (isset($_GET['reset']) && $_GET['reset'] == 1)){
44 /* Only remove lock if object was opened
45 */
46 if(session::is_set('user') && session::is_set('edit')){
47 del_lock ($ui->dn);
48 }
49 session::un_set ('edit');
50 session::un_set ('user');
51 }
53 /* Create user object on demand */
54 if (!session::is_set('user') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
55 $user= new user ($config, $ui->dn);
56 $user->enable_CSN_check();
57 $user->set_acl_base($ui->dn);
58 $user->set_acl_category("users");
59 session::set('user',$user);
60 }
61 $user = session::get('user');
63 /* save changes back to object */
64 if (session::is_set('edit')){
65 $user->save_object ();
66 }
68 /* Enter edit mode? */
69 if ((isset($_POST['edit'])) && (!session::is_set('edit')) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
71 /* Check locking */
72 if (($username= get_lock($ui->dn)) != ""){
73 session::set('back_plugin',$plug);
74 session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
75 $lock_msg = gen_locked_message ($username, $ui->dn);
77 }else{
79 /* Lock the current entry */
80 add_lock ($ui->dn, $ui->dn);
81 session::set('dn',$ui->dn);
82 session::set('edit',TRUE);
83 }
84 }
86 /* Perform password change */
87 if (isset($_POST['password_finish'])){
89 /* For security reasons, check if user is allowed to set password again */
90 if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
92 /* Check input and feed errors into 'message' */
93 $message= array();
95 /* Sanity checks... */
96 if ($_POST['new_password'] != $_POST['repeated_password']){
98 /* Matching passwords in new and repeated? */
99 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
100 } else {
102 /* Empty password is not permitted by default. */
103 if ($_POST['new_password'] == ""){
104 $message[]= msgPool::required(_("New password"));
105 }
106 }
108 /* Errors, or change password? */
109 if (count($message) != 0){
111 /* Show error message and continue editing */
112 msg_dialog::displayChecks($message);
113 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
114 return ($display);
115 }
116 change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
117 new log("modify","users/password","",array(),"Password has been changed");
119 } else {
121 /* Missing permissions, show message */
122 msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
123 }
125 del_lock ($ui->dn);
126 session::un_set ('user');
127 }
129 /* save changes to LDAP and disable edit mode */
130 if (isset($_POST['edit_finish'])){
132 /* Perform checks */
133 $message= $user->check ();
135 /* No errors, save object */
136 if (count ($message) == 0){
137 $user->save ();
138 del_lock ($ui->dn);
139 session::un_set ('edit');
141 /* Need to reset the password? */
142 if($user->password_change_needed()){
143 /* Save object */
144 session::set('user',$user);
146 $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
147 return ($display);
148 } else {
149 session::un_set ('user');
150 }
152 } else {
153 /* Errors found, show message */
154 msg_dialog::displayChecks($message);
155 }
156 }
158 /* Execute formular */
159 if($lock_msg){
160 $display.= $lock_msg;
161 }else{
162 $display.= $user->execute ();
163 }
165 /* Store changes in session */
166 if (session::is_set('edit')){
167 session::set('user',$user);
168 }
170 $info = "";
172 /* Show page footer depending on the mode */
173 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
174 $display.= "<p class=\"plugbottom\">";
176 /* Are we in edit mode? */
177 if (session::is_set('edit')){
178 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
179 $display.= " ";
180 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
182 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
183 "\"> ".$ui->dn." ";
184 } else {
185 /* 'viewid' may be set by i.e. the phonelist plugin. This
186 means that we want to go back... */
187 if (isset ($viewid)){
188 $str= msgPool::backButton();
189 $fn = "back";
190 } else {
191 $str= msgPool::editButton();
192 $fn = "edit";
193 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
194 "\"> ".$ui->dn." ";
195 }
197 /* Only display edit button if there is at least one attribute editable */
198 if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/user"))){
199 if ($fn == "edit"){
200 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\"> ".
201 msgPool::clickEditToChange();
202 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
203 }
204 }
206 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
207 }
208 $display.= "</p>\n";
209 }
211 /* Page header*/
212 $display= print_header(get_template_path('plugins/generic/images/plugin.png'),
213 _("Generic user information"), $info).$display;
215 }
217 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
218 ?>