Code

Initial acl handling for MyAccount user.
[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   $user->MyAccount_mode = true;
62   if (isset($_SESSION['edit'])){
63     $user->edit_mode = true;
64   } else {
65     $user->edit_mode = false;
66   }
68   /* Perform password change */
69   if (isset($_POST['password_finish'])){
71     /* For security reasons, check if user is allowed to set password again */
72     if (chkacl($user->acl, "password") == "" || chkacl($user->acl, "create")){
74       /* Check input and feed errors into 'message' */
75       $message= array();
77       /* Sanity checks... */
78       if ($_POST['new_password'] != $_POST['repeated_password']){
80         /* Matching passwords in new and repeated? */
81         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
82       } else {
84         /* Empty password is not permitted by default. */
85         if ($_POST['new_password'] == ""){
86           $message[]= _("The password you've entered as 'New password' is empty.");
87         }
88       }
90       /* Errors, or change password? */
91       if (count($message) != 0){
93         /* Show error message and continue editing */
94         show_errors ($message);
95         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
96         return ($display);
97       }
98       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
99       gosa_log ("Password for '".$user->dn."' has been changed");
101     } else {
103       /* Missing permissions, show message */
104       print_red (_("You are not allowed to set your password!"));
105     }
107     $user->acl= "#none#";
108     del_lock ($ui->dn);
109   }
111   /* save changes to LDAP and disable edit mode */
112   if (isset($_POST['edit_finish'])){
114     /* Perform checks */
115     $message= $user->check ();
117     /* No errors, save object */
118     if (count ($message) == 0){
119       $user->save ();
120       gosa_log ("User/generic object'".$ui->dn."' has been saved");
121       $user->acl= "#none#";
122       del_lock ($ui->dn);
123       sess_del ('edit');
125       /* Save object */
126       $_SESSION['user']= $user;
128       /* Need to reset the password? */
129       if($user->password_change_needed()){
130         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
131         return ($display);
132       }
134     } else {
135       /* Errors found, show message */
136       show_errors ($message);
137     }
138   }
140   /* Execute formular */
141   $display.= $user->execute ();
143   /* Store changes  in session */
144   if (isset ($_SESSION['edit'])){
145     $_SESSION['user']= $user;
146   }
148   $info = "";
149   /* Show page footer depending on the mode */
150   if (!$user->cert_dialog && !$user->picture_dialog && $user->is_account){
151     $display.= "<p class=\"plugbottom\">";
153     /* Are we in edit mode? */
154     if (isset($_SESSION['edit'])){
155       $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
156       $display.= "&nbsp;";
157       $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
158       $display.="<script language='javascript'>";
160       $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/closedlock.png').
161              "\"> ".$ui->dn."&nbsp;";
162     } else {
163       /* 'viewid' may be set by i.e. the phonelist plugin. This
164          means that we want to go back... */
165       if (isset ($viewid)){
166         $str= _("Back");
167         $fn = "back";
168       } else {
169         $str= _("Edit");
170         $fn = "edit";
171         $info= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/openlock.png').
172                "\"> ".$ui->dn."&nbsp;";
173       }
174       if ($fn == "edit"){
175         $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
176                 _("Click the 'Edit' button below to change informations in this dialog");
177         $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
178       }
179       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
180     }
181     $display.= "</p>\n";
182   }
184   /* Page header*/
185   $display= print_header(get_template_path('images/personal.png'),
186                          _("Generic user information"), $info).$display;
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>