Code

back_plugin is not global
[gosa.git] / gosa-core / plugins / personal / generic / main.inc
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 = "";
27 if ( $remove_lock){
28   if(session::is_set('user') && session::is_set('edit')){
29     del_lock ($ui->dn);
30   }
31 }else{
33   /* Reset requested? */
34   if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || 
35       (isset($_GET['reset']) && $_GET['reset'] == 1)){
37     /* Only remove lock if object was opened 
38      */
39     if(session::is_set('user') && session::is_set('edit')){
40       del_lock ($ui->dn);
41     }
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::global_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('edit',TRUE);
75     }
76   }
78   /* Perform password change */
79   if (isset($_POST['password_finish'])){
81     /* For security reasons, check if user is allowed to set password again */
82     if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
84       /* Check input and feed errors into 'message' */
85       $message= array();
87       /* Sanity checks... */
88       if ($_POST['new_password'] != $_POST['repeated_password']){
90         /* Matching passwords in new and repeated? */
91         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
92       } else {
94         /* Empty password is not permitted by default. */
95         if ($_POST['new_password'] == ""){
96           $message[]= msgPool::required(_("New password"));
97         }
98       }
100       /* Errors, or change password? */
101       if (count($message) != 0){
103         /* Show error message and continue editing */
104         msg_dialog::displayChecks($message);
105         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
106         return ($display);
107       }
108       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
109       new log("modify","users/password","",array(),"Password has been changed");
111     } else {
113       /* Missing permissions, show message */
114       msg_dialog::display(_("Error"), _("You have no permission to set your password!"), ERROR_DIALOG);
115     }
117     del_lock ($ui->dn);
118     session::un_set ('user');
119   }
121   /* save changes to LDAP and disable edit mode */
122   if (isset($_POST['edit_finish'])){
124     /* Perform checks */
125     $message= $user->check ();
127     /* No errors, save object */
128     if (count ($message) == 0){
129       $user->save ();
130       del_lock ($ui->dn);
131       session::un_set ('edit');
133       /* Need to reset the password? */
134       if($user->password_change_needed()){
135         /* Save object */
136         session::set('user',$user);
138         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
139         return ($display);
140       } else {
141         session::un_set ('user');
142       }
144     } else {
145       /* Errors found, show message */
146       msg_dialog::displayChecks($message);
147     }
148   }
150   /* Execute formular */
151   if($lock_msg){
152     $display.= $lock_msg;
153   }else{
154     $display.= $user->execute ();
155   }
157   /* Store changes  in session */
158   if (session::is_set('edit')){
159     session::set('user',$user);
160   }
162   $info = "";
164   /* Show page footer depending on the mode */
165   if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
166     $display.= "<p class=\"plugbottom\">";
168     /* Are we in edit mode? */
169     if (session::is_set('edit')){
170       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
171       $display.= "&nbsp;";
172       $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
174       $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/locked.png').
175         "\"> ".$ui->dn."&nbsp;";
176     } else {
177       /* 'viewid' may be set by i.e. the phonelist plugin. This
178          means that we want to go back... */
179       if (isset ($viewid)){
180         $str= msgPool::backButton();
181         $fn = "back";
182       } else {
183         $str= msgPool::editButton();
184         $fn = "edit";
185         $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/unlocked.png').
186           "\"> ".$ui->dn."&nbsp;";
187       }
189       /* Only display edit button if there is at least one attribute editable */
190       if(preg_match("/r/",$ui->get_permissions($ui->dn,"users/user"))){
191         if ($fn == "edit"){
192           $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lists/on.png')."\"> ".
193             msgPool::clickEditToChange();
194           $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
195         }
196       }
198       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
199     }
200     $display.= "</p>\n";
201   }
203   /* Page header*/
204   $display= print_header(get_template_path('plugins/generic/images/plugin.png'),
205       _("Generic user information"), $info).$display;
209 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
210 ?>