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'])|| isset($_POST['password_changed'])){
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 /* save changes to LDAP and disable edit mode */
80 $info = "";
81 if (isset($_POST['edit_finish'])){
83 /* Perform checks */
84 $message= $user->check ();
86 /* No errors, save object */
87 if (count ($message) == 0){
88 $user->save ();
89 del_lock ($ui->dn);
90 session::un_set ('edit');
92 /* Need to reset the password? */
93 if($user->password_change_needed()){
95 $user->passwordClass= new password($config, $ui->dn);
96 $user->passwordClass->forceHash($user->pw_storage);
98 session::set('user',$user);
99 $display.=$user->passwordClass->execute();
100 } else {
101 session::un_set ('user');
102 }
104 } else {
105 /* Errors found, show message */
106 msg_dialog::displayChecks($message);
107 }
108 }elseif(isset($user->passwordClass)){
110 $display.=$user->passwordClass->execute();
112 }else{
114 /* Execute formular */
115 if($lock_msg){
116 $display.= $lock_msg;
117 }else{
118 $display.= $user->execute ();
119 }
121 /* Store changes in session */
122 if (session::is_set('edit')){
123 session::set('user',$user);
124 }
126 /* Show page footer depending on the mode */
127 if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
128 $display.= "<p class=\"plugbottom\">";
130 /* Are we in edit mode? */
131 if (session::is_set('edit')){
132 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
133 $display.= " ";
134 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
136 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
137 "\"> ".$ui->dn." ";
138 } else {
139 /* 'viewid' may be set by i.e. the phonelist plugin. This
140 means that we want to go back... */
141 if (isset ($viewid)){
142 $str= msgPool::backButton();
143 $fn = "back";
144 } else {
145 $str= msgPool::editButton();
146 $fn = "edit";
147 $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
148 "\"> ".$ui->dn." ";
149 }
151 /* Only display edit button if there is at least one attribute editable */
152 if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/user"))){
153 if ($fn == "edit"){
154 $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\"> ".
155 msgPool::clickEditToChange();
156 $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
157 }
158 }
160 $display.= "<input type=\"hidden\" name=\"ignore\">\n";
161 }
162 $display.= "</p>\n";
163 }
164 }
166 /* Page header*/
167 $display= print_header(get_template_path('plugins/generic/images/plugin.png'),
168 _("Generic user information"), $info).$display;
170 }
172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
173 ?>