Code

Updated macro class. Added check -> Empty macros can't be saved.
[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 = "";
26 if (!$remove_lock){
27   /* Reset requested? */
28   if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || 
29       (isset($_GET['reset']) && $_GET['reset'] == 1)){
30     del_lock ($ui->dn);
31     sess_del ('edit');
32     sess_del ('user');
33   }
35   /* Create user object on demand */
36   if (!isset($_SESSION['user']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
37     $_SESSION['user']= new user ($config, $ui->dn);
38     $_SESSION['user']->set_acl_base($ui->dn);
39     $_SESSION['user']->set_acl_category("users");
40   }
41   $user= $_SESSION['user'];
43   /* save changes back to object */
44   if (isset ($_SESSION['edit'])){
45     $user->save_object ();
46   }
48   /* Enter edit mode? */
49   if ((isset($_POST['edit'])) && (!isset( $_SESSION['edit'])) &&preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
51     /* Check locking */
52     if (($username= get_lock($ui->dn)) != ""){
53       $_SESSION['back_plugin']= $plug;
54       $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit$/","/^plug$/");
55       $lock_msg =  gen_locked_message ($username, $ui->dn);
56   
57     }else{
59       /* Lock the current entry */
60       add_lock ($ui->dn, $ui->dn);
61       $_SESSION['dn']= $ui->dn;
62       $_SESSION['edit']= TRUE;
63     }
64   }
66   /* Perform password change */
67   if (isset($_POST['password_finish'])){
69     /* For security reasons, check if user is allowed to set password again */
70     if ($user->acl_is_writable("userPassword") || $user->acl_is_createable()){
72       /* Check input and feed errors into 'message' */
73       $message= array();
75       /* Sanity checks... */
76       if ($_POST['new_password'] != $_POST['repeated_password']){
78         /* Matching passwords in new and repeated? */
79         $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
80       } else {
82         /* Empty password is not permitted by default. */
83         if ($_POST['new_password'] == ""){
84           $message[]= _("The password you've entered as 'New password' is empty.");
85         }
86       }
88       /* Errors, or change password? */
89       if (count($message) != 0){
91         /* Show error message and continue editing */
92         show_errors ($message);
93         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
94         return ($display);
95       }
96       change_password ($user->dn, $_POST['new_password'], 0, $user->pw_storage);
97       gosa_log ("Password for '".$user->dn."' has been changed");
99     } else {
101       /* Missing permissions, show message */
102       print_red (_("You are not allowed to set your password!"));
103     }
105     del_lock ($ui->dn);
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       gosa_log ("User/generic object'".$ui->dn."' has been saved");
118       del_lock ($ui->dn);
119       sess_del ('edit');
121       /* Save object */
122       $_SESSION['user']= $user;
124       /* Need to reset the password? */
125       if($user->password_change_needed()){
126         $display.= $smarty->fetch(get_template_path('password.tpl', TRUE));
127         return ($display);
128       }
130     } else {
131       /* Errors found, show message */
132       show_errors ($message);
133     }
134   }
136   /* Execute formular */
137   if($lock_msg){
138     $display.= $lock_msg;
139   }else{
140     $display.= $user->execute ();
141   }
143   /* Store changes  in session */
144   if (isset ($_SESSION['edit'])){
145     $_SESSION['user']= $user;
146   }
148   $info = "";
150   /* Show page footer depending on the mode */
151   if (!$user->cert_dialog && !$user->picture_dialog && !$user->dialog && $user->is_account && empty($lock_msg)){
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";
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       }
175       /* Only display edit button if there is at least one attribute editable */
176       if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/user"))){
177         if ($fn == "edit"){
178           $info.= "<img class=\"center\" alt=\"\" align=\"middle\" src=\"".get_template_path('images/lamp.png')."\"> ".
179             _("Click the 'Edit' button below to change informations in this dialog");
180           $display.= "<input type=submit name=\"$fn\" value=\"$str\">\n";
181         }
182       }
184       $display.= "<input type=\"hidden\" name=\"ignore\">\n";
185     }
186     $display.= "</p>\n";
187   }
189   /* Page header*/
190   $display= print_header(get_template_path('images/personal.png'),
191                          _("Generic user information"), $info).$display;
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>