Code

3fcb3ef2640f6b72834a3f6c2142ade275b164fd
[gosa.git] / gosa-core / plugins / personal / myaccount / main.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: main.inc 15315 2010-01-26 13:00:52Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
24 /* Remove locks created by this plugin
25 */
26 $lock_msg="";
27 if ($remove_lock || isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
28   del_lock($ui->dn);
29   if(session::is_set('MyAccountTabs') && session::is_set('edit')){
30       session::un_set('MyAccountTabs');
31   }
32 }
34 /* Reset requested? */
35 if (isset($_POST['edit_cancel']) || $cleanup){
36     session::un_set ('edit');
37     session::un_set ('MyAccountTabs');
38 }
40 /* Remove this plugin from session
41  */
42 if (! $cleanup ){
44     /* Create MyAccountTabs object on demand */
45     if (!session::is_set('MyAccountTabs') || (isset($_GET['reset']) && $_GET['reset'] == 1)){
47         // Check if the base plugin is available - it is mostly responsible for object creation and removal.
48         $first  = $config->data['TABS']['MYACCOUNTTABS'][0];
49         if(!class_available($first['CLASS'])){
50             msg_dialog::display(_("Internal error"),
51                     sprintf(_("Cannot instantiate tabbed-plugin, the base plugin (%s) is not available!"), $first['CLASS']),
52                     ERROR_DIALOG);
53         }else{
55             $MyAccountTabs= new MyAccountTabs($config,$config->data['TABS']['MYACCOUNTTABS'], $ui->dn, "users", true, true); 
56             $MyAccountTabs->setReadOnly(TRUE);
57             session::set('MyAccountTabs',$MyAccountTabs);
58         }
59     }
61     if(session::is_set('MyAccountTabs')){
62         $MyAccountTabs = session::get('MyAccountTabs');
64         /* Enter edit mode? */
65         if ((isset($_POST['edit'])) && (!session::is_set('edit'))){
67             /* Check locking */
68             if (($username= get_lock($ui->dn)) != ""){
69                 session::set('back_plugin',$plug);
70                 session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/"));
71                 $lock_msg =  gen_locked_message ($username, array($ui->dn));
73             }else{
75                 /* Lock the current entry */
76                 add_lock ($ui->dn, $ui->dn);
77                 session::set('edit',TRUE);
78                 $MyAccountTabs->setReadOnly(FALSE);
79             }
80         }
82         $info= "";
83         if (isset($_POST['edit_finish'])){
84             $message= $MyAccountTabs->check ();
85             if (count ($message) == 0){
86                 $MyAccountTabs->save ();
87                 del_lock ($ui->dn);
88                 session::un_set ('edit');
89                 $MyAccountTabs->setReadOnly(TRUE);
90                 if(isset($MyAccountTabs->by_object['user']) && $MyAccountTabs->by_object['user']->password_change_needed()){
91                     $MyAccountTabs->password_change_needed = TRUE;
92                 }else{
93                     session::un_set ('MyAccountTabs');
94                 }
95             } else {
96                 msg_dialog::displayChecks($message);
97             }
98         }
100         // Build up password class to make password-hash changes 
101         //  effective, by setting a new password.
102         if($MyAccountTabs->password_change_needed){
103             if(!isset($MyAccountTabs->passwordClass)){
104                 $user = $MyAccountTabs->by_object['user'];
105                 $MyAccountTabs->passwordClass= new password($config, $ui->dn);
106                 $MyAccountTabs->passwordClass->forceHash($user->pw_storage);
107             }
108             $display.= $MyAccountTabs->passwordClass->execute();
109         }
111         /* Execute formular */
112         if(!$MyAccountTabs->password_change_needed){
113             pathNavigator::registerPlugin(_("My account"));
114             if($lock_msg){
115                 $display = $lock_msg;
116             }else{
117                 $display.= $MyAccountTabs->execute ();
118             }
119         }
121         /* Store changes  in session */
122         if (session::is_set('edit')){
123             session::set('MyAccountTabs',$MyAccountTabs);
124         }
126         /* Show page footer depending on the mode */
127         if (!$MyAccountTabs->is_modal_dialog() && empty($lock_msg) && !$MyAccountTabs->password_change_needed){
129             $display.= "<div class='plugin-actions'>";
131             /* Are we in edit mode? */
132             if (session::is_set('edit')){
133                 $display.= "<button class='button' type='submit' name='edit_finish'>".msgPool::okButton()."</button>\n";
134                 $display.= "<button class='button' type='submit' name='edit_cancel'>".msgPool::cancelButton()."</button>\n";
135             } else {
136                 if(preg_match("/r/",$ui->get_category_permissions($ui->dn,"users"))){
137                     $display.= "<button class='button' type='submit' name='edit'>".msgPool::editButton()."</button>\n";
138                 }
139                 $display.= "<input type='hidden' name='ignore'>\n";
140             }
141             $display.= "</div>\n";
142         }
143     }
146 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
147 ?>