Code

Some main updates
[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'])){
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   /* MyAccount_mode tell class user that we are editing for my account section
62      edit_mode allows us to force the acls to be not writeable, when not in editing mode */
63   $user->MyAccount_mode = true;
64   if (isset($_SESSION['edit'])){
65     $user->edit_mode = true;
66   } else {
67     $user->edit_mode = false;
68   }
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 ($user->acl_is_writable("userPassword") || $user->acl_is_createable()){
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     del_lock ($ui->dn);
111   }
113   /* save changes to LDAP and disable edit mode */
114   if (isset($_POST['edit_finish'])){
116     /* Perform checks */
117     $message= $user->check ();
119     /* No errors, save object */
120     if (count ($message) == 0){
121       $user->save ();
122       gosa_log ("User/generic object'".$ui->dn."' has been saved");
123       del_lock ($ui->dn);
124       sess_del ('edit');
126       /* Save object */
127       $_SESSION['user']= $user;
129       /* Need to reset the password? */
130       if($user->password_change_needed()){
131         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
132         return ($display);
133       }
135     } else {
136       /* Errors found, show message */
137       show_errors ($message);
138     }
139   }
141   /* Execute formular */
142   $display.= $user->execute ();
144   /* Store changes  in session */
145   if (isset ($_SESSION['edit'])){
146     $_SESSION['user']= $user;
147   }
149   $info = "";
150   /* Show page footer depending on the mode */
151   if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
152     $display.= "<p class=\"plugbottom\">";
154     /* Are we in edit mode? */
155     if (isset($_SESSION['edit'])){
156       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
157       $display.= "&nbsp;";
158       $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
159       $display.="<script language='javascript'>";
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       }
175       if ($fn == "edit"){
176         $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
177                 _("Click the 'Edit' button below to change informations in this dialog");
178         $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
179       }
180       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
181     }
182     $display.= "</p>\n";
183   }
185   /* Page header*/
186   $display= print_header(get_template_path('images/personal.png'),
187                          _("Generic user information"), $info).$display;
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>