Repository navigation
Expand file tree
/
Copy patheditadmin.php
More file actions
195 lines (173 loc) · 8.85 KB
/
Copy patheditadmin.php
File metadata and controls
195 lines (173 loc) · 8.85 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
<?php
require 'function.php';
session_start();
if (!isset($_SESSION["login"])) {
header("location: login.php");
exit;
}
// Fetch the current admin details
$currentUsername = $_SESSION["login"];
$currentAdmin = query("SELECT * FROM admin WHERE username = ?", 's', $currentUsername);
// Check if any result is returned
if (!$currentAdmin || empty($currentAdmin)) {
// Handle the case where the current admin details are not found
echo "Error: Current admin details not found.";
exit;
}
// Use the first row (assuming there's only one admin with a given username)
$currentAdmin = $currentAdmin[0];
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get new password and password confirmation from the form
$newPassword = $_POST["new_password"];
$confirmPassword = $_POST["confirm_password"];
// Validate and update the admin details
if (!empty($newPassword)) {
// Check if the new password and confirmation match
if ($newPassword == $confirmPassword) {
// Update password (you might want to hash it before storing in the database)
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$updatePasswordResult = query("UPDATE admin SET password = ? WHERE adminid = ?", 'si', $hashedPassword, $currentAdmin['adminid']);
if ($updatePasswordResult === false) {
// Handle the error if the update fails
echo "Error updating password.";
} else {
// Bootstrap alert for successful password update
echo '<script>alert("Password updated successfully.");</script>';
header("Refresh: 1");
}
} else {
// Bootstrap alert for password mismatch
echo '<script>alert("Password and confirmation do not match.");</script>';
}
}
// Check if WhatsApp number is submitted and different from the current value
$newWhatsAppNumber = $_POST["whatsapp_number"];
if (!empty($newWhatsAppNumber) && $newWhatsAppNumber != $currentAdmin['whatsapp_number']) {
// Update WhatsApp number
$updateWhatsAppNumberResult = query("UPDATE admin SET whatsapp_number = ? WHERE adminid = ?", 'si', $newWhatsAppNumber, $currentAdmin['adminid']);
if ($updateWhatsAppNumberResult === false) {
// Handle the error if the update fails
echo '<div class="alert alert-danger" role="alert">Error updating WhatsApp number.</div>';
} else {
// Bootstrap alert for successful WhatsApp number update
echo '<script>alert("WhatsApp number updated successfully.");</script>';
header("Refresh: 1");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Brave ADV Lightbox</title>
<!-- Favicons -->
<link href="assets/img/brave-icon.png" rel="icon">
<link href="assets/img/brave-icon.png" rel="apple-touch-icon"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<section id="topbar" class="d-flex align-items-center">
<div class="contact-info d-flex align-items-center">
<img src="assets/img/bravera-logo.jpg" alt="Your Logo" height="40" style="margin-right: 40px; margin-left:40px;">
<span>
<i class="bi"></i> Brave ADV Lightbox - Gunung Kidul - DIY
</span>
</div>
<!--
<div class="social-links d-none d-md-block">
<a href="#" class="twitter"><i class="bi bi-twitter"></i></a>
<a href="#" class="facebook"><i class="bi bi-facebook"></i></a>
<a href="#" class="instagram"><i class="bi bi-instagram"></i></a>
<a href="#" class="linkedin"><i class="bi bi-linkedin"></i></i></a>
</div>
-->
</div>
</section>
<div class="container-fluid text-center">
<div class="row">
<!-- Left Sidebar -->
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block sidebar">
<div class="position-sticky">
<!-- Profile Picture -->
<div class="text-center mt-3">
<img src="assets\img\profilepic.png" alt="Profile Picture" class="rounded-circle" width="80">
</div><br>
<!-- Sidebar Menu -->
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="dashboard.php">
Dasbor
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="tambahproduk.php">
Tambah
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="admin.php">
Produk
</a>
</li>
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="editadmin.php">
Pengaturan
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="logout.php">
Keluar
</a>
</li>
</ul>
</div>
</nav>
<!-- Main Content -->
<main id="main-admin" class="col-md-9 ms-sm-auto col-lg-10 px-md-4 min-vh-100 overflow-auto">
<div class="container text-center">
<h2>Pengaturan Akun</h2>
<form method="post" action="">
<!-- Add an oninput event to the WhatsApp number input field -->
<div class="mb-3">
<label for="whatsapp_number" class="form-label">Nomor Whatsapp</label>
<div class="input-group">
<!-- Display the fixed prefix as text -->
<span class="input-group-text">+62</span>
<!-- Input field for the phone number -->
<input placeholder="contoh: 8186009833" type="number" class="form-control" id="whatsapp_number" name="whatsapp_number" oninput="addPrefix(this)" value="<?php echo htmlspecialchars(substr($currentAdmin['whatsapp_number'], 2)); ?>">
</div>
</div>
<!-- Add JavaScript function to automatically add the prefix -->
<script>
function addPrefix(input) {
// Ensure the input always begins with "62"
if (!input.value.startsWith('62')) {
input.value = '62' + input.value;
}
}
</script>
<div class="mb-3">
<label for="new_password" class="form-label">Password Baru</label>
<input placeholder="masukkan password baru" type="password" class="form-control" id="new_password" name="new_password">
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Konfirmasi Password Baru</label>
<input placeholder="masukkan konfirmasi password baru" type="password" class="form-control" id="confirm_password" name="confirm_password">
</div>
<button type="submit" class="btn btn-warning">Simpan</button>
</form>
</div>
</main>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous">
</body>
</html>