Code

Closes #237 Just a test commit
[gosa.git] / plugins / personal / generic / main.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
22 /* Preset display */
23 $display  = "";
24 $lock_msg = "";
25 if (!$remove_lock){
26   /* Reset requested? */
27   if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || 
28       (isset($_GET['reset']) && $_GET['reset'] == 1)){
29     del_lock ($ui->dn);
30     sess_del ('edit');
31     sess_del ('user');
32   }
34   /* Create user object on demand */
35   if (!isset($_SESSION['user']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
36     $_SESSION['user']= new user ($config, $ui->dn);
37     $_SESSION['user']->set_acl_base($ui->dn);
38     $_SESSION['user']->set_acl_category("users");
39   }
40   $user= $_SESSION['user'];
42   /* save changes back to object */
43   if (isset ($_SESSION['edit'])){
44     $user->save_object ();
45   }
47   /* Enter edit mode? */
48   if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit'])) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
50     /* Check locking */
51     if (($username= get_lock($ui->dn)) != ""){
52       $_SESSION['back_plugin']= $plug;
53       $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit$/","/^plug$/");
54       $lock_msg =  gen_locked_message ($username, $ui->dn);
55   
56     }else{
58       /* Lock the current entry */
59       add_lock ($ui->dn, $ui->dn);
60       $_SESSION['dn']= $ui->dn;
61       $_SESSION['edit']= TRUE;
62     }
63   }
65   /* Perform password change */
66   if (isset($_POST['password_finish'])){
68     /* For security reasons, check if user is allowed to set password again */
69     if ($user->acl_is_writeable("userPassword") || $user->acl_is_createable()){
71       /* Check input and feed errors into 'message' */
72       $message= array();
74       /* Sanity checks... */
75       if ($_POST['new_password'] != $_POST['repeated_password']){
77         /* Matching passwords in new and repeated? */
78         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
79       } else {
81         /* Empty password is not permitted by default. */
82         if ($_POST['new_password'] == ""){
83           $message[]= _("The password you've entered as 'New password' is empty.");
84         }
85       }
87       /* Errors, or change password? */
88       if (count($message) != 0){
90         /* Show error message and continue editing */
91         show_errors ($message);
92         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
93         return ($display);
94       }
95       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
96       new log("modify","users/password","",array(),"Password has been changed");
98     } else {
100       /* Missing permissions, show message */
101       print_red (_("You are not allowed to set your password!"));
102     }
104     del_lock ($ui->dn);
105     sess_del ('user');
106   }
108   /* save changes to LDAP and disable edit mode */
109   if (isset($_POST['edit_finish'])){
111     /* Perform checks */
112     $message= $user->check ();
114     /* No errors, save object */
115     if (count ($message) == 0){
116       $user->save ();
117       del_lock ($ui->dn);
118       sess_del ('edit');
120       /* Need to reset the password? */
121       if($user->password_change_needed()){
122         /* Save object */
123         $_SESSION['user']= $user;
125         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
126         return ($display);
127       } else {
128         sess_del ('user');
129       }
131     } else {
132       /* Errors found, show message */
133       show_errors ($message);
134     }
135   }
137   /* Execute formular */
138   if($lock_msg){
139     $display.= $lock_msg;
140   }else{
141     $display.= $user->execute ();
142   }
144   /* Store changes  in session */
145   if (isset ($_SESSION['edit'])){
146     $_SESSION['user']= $user;
147   }
149   $info = "";
151   /* Show page footer depending on the mode */
152   if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
153     $display.= "<p class=\"plugbottom\">";
155     /* Are we in edit mode? */
156     if (isset($_SESSION['edit'])){
157       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
158       $display.= "&nbsp;";
159       $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
161       $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
162              "\"> ".$ui->dn."&nbsp;";
163     } else {
164       /* 'viewid' may be set by i.e. the phonelist plugin. This
165          means that we want to go back... */
166       if (isset ($viewid)){
167         $str= _("Back");
168         $fn = "back";
169       } else {
170         $str= _("Edit");
171         $fn = "edit";
172         $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
173                "\"> ".$ui->dn."&nbsp;";
174       }
176       /* Only display edit button if there is at least one attribute editable */
177       if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
178         if ($fn == "edit"){
179           $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
180             _("Click the 'Edit' button below to change informations in this dialog");
181           $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
182         }
183       }
185       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
186     }
187     $display.= "</p>\n";
188   }
190   /* Page header*/
191   $display= print_header(get_template_path('images/personal.png'),
192                          _("Generic user information"), $info).$display;
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>