Code

Removed duplicated addslashes
[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= "";
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']))){
50     /* Check locking */
51     if (($username= get_lock($ui->dn)) != ""){
52       $_SESSION['back_plugin']= $plug;
53       gen_locked_message ($username, $ui->dn);
54       exit ();
55     }
57     /* Lock the current entry */
58     add_lock ($ui->dn, $ui->dn);
59     $_SESSION['dn']= $ui->dn;
60     $_SESSION['edit']= TRUE;
61   }
63   /* Perform password change */
64   if (isset($_POST['password_finish'])){
66     /* For security reasons, check if user is allowed to set password again */
67     if ($user->acl_is_writable("userPassword") || $user->acl_is_createable()){
69       /* Check input and feed errors into 'message' */
70       $message= array();
72       /* Sanity checks... */
73       if ($_POST['new_password'] != $_POST['repeated_password']){
75         /* Matching passwords in new and repeated? */
76         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
77       } else {
79         /* Empty password is not permitted by default. */
80         if ($_POST['new_password'] == ""){
81           $message[]= _("The password you've entered as 'New password' is empty.");
82         }
83       }
85       /* Errors, or change password? */
86       if (count($message) != 0){
88         /* Show error message and continue editing */
89         show_errors ($message);
90         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
91         return ($display);
92       }
93       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
94       gosa_log ("Password for '".$user->dn."' has been changed");
96     } else {
98       /* Missing permissions, show message */
99       print_red (_("You are not allowed to set your password!"));
100     }
102     del_lock ($ui->dn);
103   }
105   /* save changes to LDAP and disable edit mode */
106   if (isset($_POST['edit_finish'])){
108     /* Perform checks */
109     $message= $user->check ();
111     /* No errors, save object */
112     if (count ($message) == 0){
113       $user->save ();
114       gosa_log ("User/generic object'".$ui->dn."' has been saved");
115       del_lock ($ui->dn);
116       sess_del ('edit');
118       /* Save object */
119       $_SESSION['user']= $user;
121       /* Need to reset the password? */
122       if($user->password_change_needed()){
123         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
124         return ($display);
125       }
127     } else {
128       /* Errors found, show message */
129       show_errors ($message);
130     }
131   }
133   /* Execute formular */
134   $display.= $user->execute ();
136   /* Store changes  in session */
137   if (isset ($_SESSION['edit'])){
138     $_SESSION['user']= $user;
139   }
141   $info = "";
143   /* Show page footer depending on the mode */
144   if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
145     $display.= "<p class=\"plugbottom\">";
147     /* Are we in edit mode? */
148     if (isset($_SESSION['edit'])){
149       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
150       $display.= "&nbsp;";
151       $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
153       $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
154              "\"> ".$ui->dn."&nbsp;";
155     } else {
156       /* 'viewid' may be set by i.e. the phonelist plugin. This
157          means that we want to go back... */
158       if (isset ($viewid)){
159         $str= _("Back");
160         $fn = "back";
161       } else {
162         $str= _("Edit");
163         $fn = "edit";
164         $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
165                "\"> ".$ui->dn."&nbsp;";
166       }
168       /* Only display edit button if there is at least one attribute editable */
169       if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
170         if ($fn == "edit"){
171           $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
172             _("Click the 'Edit' button below to change informations in this dialog");
173           $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
174         }
175       }
177       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
178     }
179     $display.= "</p>\n";
180   }
182   /* Page header*/
183   $display= print_header(get_template_path('images/personal.png'),
184                          _("Generic user information"), $info).$display;
188 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
189 ?>