Fixed minor things and added missing file
[vanilla-miry.git] / account.php
blobb06c4424ad095b8d073103ccd01a06fd247a5b2d
1 <?php
2 /*
3 * Copyright 2003 Mark O'Sullivan
4 * This file is part of Vanilla.
5 * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6 * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
7 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8 * The latest source code for Vanilla is available at www.lussumo.com
9 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
11 * Description: Display and manipulate user account information
14 include("appg/settings.php");
15 $Configuration['SELF_URL'] = 'account.php';
16 include("appg/init_vanilla.php");
18 // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE
20 // Ensure the user is allowed to view this page
21 $Context->Session->Check($Context);
23 // Make sure that any existing $UserManager object is destroyed so that
24 // extensions using delegation to perform actions on this page's $UserManager
25 // object work as they should.
26 if (!@$UserManager) unset($UserManager);
27 $UserManager = $Context->ObjectFactory->NewContextObject($Context, "UserManager");
28 $AccountUserID = ForceIncomingInt("u", $Context->Session->UserID);
29 if (!@$AccountUser) $AccountUser = $UserManager->GetUserById($AccountUserID);
30 if (!$AccountUser) $Context->WarningCollector->Add($Context->GetDefinition('ErrUserNotFound'));
31 if ($Context->Session->User && $Context->Session->User->Permission("PERMISSION_EDIT_USERS")) {
32 // Allow anything
33 } else {
34 if ($AccountUser && $AccountUser->RoleID == 1) {
35 $Context->WarningCollector->Add($Context->GetDefinition("ErrUserNotFound"));
36 $AccountUser = false;
40 // If a user id was not supplied, assume that this user doesn't have an active account and kick them back to the index
41 if ($AccountUserID == 0) {
42 Redirect(GetUrl($Configuration, "index.php"));
43 die();
46 // Define properties of the page controls that are specific to this page
47 $Head->BodyId = 'AccountPage';
48 $Menu->CurrentTab = "account";
49 $Panel->CssClass = "AccountPanel";
50 $Panel->BodyCssClass = "AccountPageBody";
51 if ($AccountUser) {
52 if ($AccountUser->UserID == $Context->Session->UserID) {
53 $Context->PageTitle = $Context->GetDefinition("MyAccount");
54 } else {
55 $Context->PageTitle = $AccountUser->Name;
57 } else {
58 $Context->PageTitle = $Context->GetDefinition("ErrUserNotFound");
61 // 2. BUILD PAGE CONTROLS
63 // Build the control panel
64 if ($Context->Session->UserID > 0) {
65 $ApplicantOptions = $Context->GetDefinition("ApplicantOptions");
66 $AccountOptions = $Context->GetDefinition("AccountOptions");
67 $Panel->AddList($AccountOptions, 10);
68 $Panel->AddList($ApplicantOptions, 11);
69 if ($AccountUser && $Context->Session->User) {
70 if ($AccountUser->UserID == $Context->Session->UserID) {
71 $Panel->AddListItem($AccountOptions, $Context->GetDefinition("ChangeYourPersonalInformation"), GetUrl($Configuration, $Context->SelfUrl, "", "", "", "", "PostBackAction=Identity"), "", "", 10);
72 if ($Configuration["ALLOW_PASSWORD_CHANGE"]) $Panel->AddListItem($AccountOptions, $Context->GetDefinition("ChangeYourPassword"), GetUrl($Context->Configuration, $Context->SelfUrl, "", "", "", "", "PostBackAction=Password"), "", "", 20);
73 } elseif ($AccountUser->UserID != $Context->Session->UserID && $Context->Session->User->Permission("PERMISSION_EDIT_USERS") && $AccountUser) {
74 $Panel->AddListItem($AccountOptions, $Context->GetDefinition("ChangePersonalInformation"), GetUrl($Context->Configuration, $Context->SelfUrl, "", "u", $AccountUser->UserID, "", "PostBackAction=Identity"), "", "", 10);
76 if ($Context->Session->User->Permission("PERMISSION_CHANGE_USER_ROLE")) {
77 if ($AccountUser->RoleID > 0) {
78 $Panel->AddListItem($AccountOptions, $Context->GetDefinition("ChangeRole"), GetUrl($Context->Configuration, $Context->SelfUrl, "", "u", $AccountUser->UserID, "", "PostBackAction=Role"), "", "", 40);
82 if ( $AccountUser
83 && $AccountUser->UserID == $Context->Session->UserID
84 ) {
85 $Panel->AddListItem($AccountOptions, $Context->GetDefinition("ChangeForumFunctionality"), GetUrl($Context->Configuration, $Context->SelfUrl, "", "", "", "", "PostBackAction=Functionality"), "", "", 40);
89 // Create the account profile
90 $AccountProfile = $Context->ObjectFactory->CreateControl($Context, "Account", $AccountUser);
91 $AccountProfileEnd = $Context->ObjectFactory->CreateControl($Context, 'Filler', 'account_profile_end.php');
93 // Forms
94 $IdentityForm = $Context->ObjectFactory->CreateControl($Context, "IdentityForm", $UserManager, $AccountUser);
95 if ($Configuration["ALLOW_PASSWORD_CHANGE"]) $PasswordForm = $Context->ObjectFactory->CreateControl($Context, "PasswordForm", $UserManager, $AccountUserID);
96 $PreferencesForm = $Context->ObjectFactory->CreateControl($Context, "PreferencesForm", $UserManager, $AccountUser);
97 $AccountRoleForm = $Context->ObjectFactory->CreateControl($Context, "AccountRoleForm", $UserManager, $AccountUser);
99 // 3. ADD CONTROLS TO THE PAGE
101 $Page->AddRenderControl($Head, $Configuration["CONTROL_POSITION_HEAD"]);
102 $Page->AddRenderControl($Menu, $Configuration["CONTROL_POSITION_MENU"]);
103 $Page->AddRenderControl($Panel, $Configuration["CONTROL_POSITION_PANEL"]);
104 $Page->AddRenderControl($NoticeCollector, $Configuration['CONTROL_POSITION_NOTICES']);
105 $Page->AddRenderControl($AccountProfile, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
106 $Page->AddRenderControl($AccountProfileEnd, $Configuration["CONTROL_POSITION_BODY_ITEM"]+90);
107 $Page->AddRenderControl($IdentityForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
108 if ($Configuration["ALLOW_PASSWORD_CHANGE"]) $Page->AddRenderControl($PasswordForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
109 $Page->AddRenderControl($PreferencesForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
110 $Page->AddRenderControl($AccountRoleForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
111 $Page->AddRenderControl($Foot, $Configuration["CONTROL_POSITION_FOOT"]);
112 $Page->AddRenderControl($PageEnd, $Configuration["CONTROL_POSITION_PAGE_END"]);
114 // 4. FIRE PAGE EVENTS
116 $Page->FireEvents();