-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_account.php
More file actions
235 lines (208 loc) · 9.17 KB
/
Copy pathadmin_account.php
File metadata and controls
235 lines (208 loc) · 9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* Admin Account Route
* Displays admin profile and password management page
*/
require_once 'bootstrap.php';
use App\Models\Admin;
use App\Models\CompanySettings;
use App\Core\Auth;
// Require admin authentication
if (!Auth::check() || !Auth::isAdmin()) {
header('Location: login.php');
exit;
}
$adminModel = new Admin();
$settingsModel = new CompanySettings();
$username = $_SESSION['username'];
$admin_data = $adminModel->findByUsername($username);
if (!$admin_data) {
header('Location: login.php');
exit;
}
// Handle form submission for profile update
if (isset($_POST['update_profile'])) {
$data = [
'username' => trim($_POST['username']),
'first_name' => trim($_POST['first_name']),
'last_name' => trim($_POST['last_name']),
'email' => trim($_POST['email']),
'phone' => trim($_POST['phone']),
'address' => trim($_POST['address'])
];
// Check if username is taken (if changed)
if ($data['username'] != $username && $adminModel->usernameExists($data['username'], $admin_data['id'])) {
$profile_error = "<div class='alert alert-danger alert-bold-border fade in alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Username already taken!
</div>";
} else {
$adminModel->update($admin_data['id'], $data);
// Update session if username changed
if ($data['username'] != $username) {
$_SESSION['username'] = $data['username'];
}
$_SESSION['profile_msg'] = "<div class='alert alert-success alert-bold-border fade in alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Profile Updated Successfully!
</div>";
header('Location: admin_account.php');
exit;
}
}
// Handle password change
if (isset($_POST['change_password'])) {
$current_password = $_POST['current_password'];
$new_password = $_POST['new_password'];
$confirm_password = $_POST['confirm_password'];
if (!$adminModel->verifyPassword($username, $current_password)) {
$password_error = "<div class='alert alert-warning alert-bold-border fade in alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Current Password Is Incorrect!
</div>";
} elseif ($new_password != $confirm_password) {
$password_error = "<div class='alert alert-warning alert-bold-border fade in alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
New Passwords Do Not Match!
</div>";
} else {
$adminModel->changePassword($admin_data['id'], $new_password);
$_SESSION['password_msg'] = "<div class='alert alert-success alert-bold-border fade in alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Password Changed Successfully!
</div>";
header('Location: admin_account.php');
exit;
}
}
// Refresh admin data after potential updates
$admin_data = $adminModel->findByUsername($_SESSION['username']);
$company_name = $settingsModel->getCompanyName();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title><?= htmlspecialchars($company_name) ?> - Admin Account</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="starter-template.css" rel="stylesheet">
<link href="theme.php" rel="stylesheet" type="text/css">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include('navbar.php'); ?>
<div class="container">
<div class="starter-template">
<h2>Admin Account Settings</h2>
<p class="lead">Manage your administrator account information and password</p>
<div class="row">
<!-- Profile Information Section -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Profile Information</h3>
</div>
<div class="panel-body">
<?php
if (isset($_SESSION['profile_msg'])) {
echo $_SESSION['profile_msg'];
unset($_SESSION['profile_msg']);
}
if (isset($profile_error)) {
echo $profile_error;
}
?>
<form method="post" action="admin_account.php">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control" value="<?= htmlspecialchars($admin_data['username']) ?>" required>
</div>
<div class="form-group">
<label>First Name</label>
<input type="text" name="first_name" class="form-control" value="<?= htmlspecialchars($admin_data['first_name']) ?>">
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" name="last_name" class="form-control" value="<?= htmlspecialchars($admin_data['last_name']) ?>">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" value="<?= htmlspecialchars($admin_data['email']) ?>">
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" name="phone" class="form-control" value="<?= htmlspecialchars($admin_data['phone']) ?>">
</div>
<div class="form-group">
<label>Address</label>
<textarea name="address" class="form-control" rows="3"><?= htmlspecialchars($admin_data['address']) ?></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit" name="update_profile">Update Profile</button>
</div>
</form>
</div>
</div>
</div>
<!-- Change Password Section -->
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Change Password</h3>
</div>
<div class="panel-body">
<?php
if (isset($_SESSION['password_msg'])) {
echo $_SESSION['password_msg'];
unset($_SESSION['password_msg']);
}
if (isset($password_error)) {
echo $password_error;
}
?>
<form method="post" action="admin_account.php">
<div class="form-group">
<label>Current Password</label>
<input type="password" name="current_password" class="form-control" required>
</div>
<div class="form-group">
<label>New Password</label>
<input type="password" name="new_password" class="form-control" required>
</div>
<div class="form-group">
<label>Confirm New Password</label>
<input type="password" name="confirm_password" class="form-control" required>
</div>
<div class="form-group">
<button class="btn btn-warning" type="submit" name="change_password">Change Password</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="dist/js/jquery.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>