Code

Do not remove invalid user accounts.
[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   }
38   $user= $_SESSION['user'];
40   /* save changes back to object */
41   if (isset ($_SESSION['edit'])){
42     $user->save_object ();
43   }
45   /* Enter edit mode? */
46   if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit']))){
48     /* Check locking */
49     if (($username= get_lock($ui->dn)) != ""){
50       $_SESSION['back_plugin']= $plug;
51       gen_locked_message ($username, $ui->dn);
52       exit ();
53     }
55     /* Lock the current entry */
56     add_lock ($ui->dn, $ui->dn);
57     $_SESSION['dn']= $ui->dn;
58     $_SESSION['edit']= TRUE;
59   }
61   /* Adjust acl's to mode */
62   if (isset($_SESSION['edit'])){
63     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
64     $user->acl= get_module_permission($acl, "user", $ui->dn);
65   } else {
66     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
67     $editacl= get_module_permission($acl, "user", $ui->dn);
68     $user->acl= "#none#";
69   }
71   /* Perform password change */
72   if (isset($_POST['password_finish'])){
74     /* For security reasons, check if user is allowed to set password again */
75     if (chkacl($user->acl, "password") == "" || chkacl($user->acl, "create")){
77       /* Check input and feed errors into 'message' */
78       $message= array();
80       /* Sanity checks... */
81       if ($_POST['new_password'] != $_POST['repeated_password']){
83         /* Matching passwords in new and repeated? */
84         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
85       } else {
87         /* Empty password is not permitted by default. */
88         if ($_POST['new_password'] == ""){
89           $message[]= _("The password you've entered as 'New password' is empty.");
90         }
91       }
93       /* Errors, or change password? */
94       if (count($message) != 0){
96         /* Show error message and continue editing */
97         show_errors ($message);
98         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
99         return ($display);
100       }
101       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
102       gosa_log ("Password for '".$user->dn."' has been changed");
104     } else {
106       /* Missing permissions, show message */
107       print_red (_("You are not allowed to set your password!"));
108     }
110     $user->acl= "#none#";
111     del_lock ($ui->dn);
112     sess_del ('user');
113   }
115   /* save changes to LDAP and disable edit mode */
116   if (isset($_POST['edit_finish'])){
118     /* Perform checks */
119     $message= $user->check ();
121     /* No errors, save object */
122     if (count ($message) == 0){
123       $user->save ();
124       gosa_log ("User/generic object'".$ui->dn."' has been saved");
125       $user->acl= "#none#";
126       $editacl= get_module_permission($acl, "user", $ui->dn);
127       del_lock ($ui->dn);
128       sess_del ('edit');
130       /* Need to reset the password? */
131       if($user->password_change_needed()){
132         /* Save object */
133         $_SESSION['user']= $user;
135         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
136         return ($display);
137       } else {
138         sess_del ('user');
139       }
141     } else {
142       /* Errors found, show message */
143       show_errors ($message);
144     }
145   }
147   /* Execute formular */
148   $display.= $user->execute ();
150   /* Store changes  in session */
151   if (isset ($_SESSION['edit'])){
152     $_SESSION['user']= $user;
153   }
155   $info = "";
156   /* Show page footer depending on the mode */
157   if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
158     $display.= "<p class=\"plugbottom\">";
160     /* Are we in edit mode? */
161     if (isset($_SESSION['edit'])){
162       $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
163       $display.= "&nbsp;";
164       $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
166       $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
167              "\"> ".$ui->dn."&nbsp;";
168     } else {
169       /* 'viewid' may be set by i.e. the phonelist plugin. This
170          means that we want to go back... */
171       if (isset ($viewid)){
172         $str= _("Back");
173         $fn = "back";
174       } else {
175         $str= _("Edit");
176         $fn = "edit";
177         $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
178                "\"> ".$ui->dn."&nbsp;";
179       }
181       if ($fn == "edit" && isset($editacl) && $editacl != "#none#"){
182         $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
183                 _("Click the 'Edit' button below to change informations in this dialog");
184         $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
185       }
186       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
187     }
188     $display.= "</p>\n";
189   }
191   /* Page header*/
192   $display= print_header(get_template_path('images/personal.png'),
193                          _("Generic user information"), $info).$display;
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>