-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
159 lines (135 loc) · 6.49 KB
/
Copy pathprofile.php
File metadata and controls
159 lines (135 loc) · 6.49 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
<?php
require_once __DIR__ . '/config/constants.php';
require_once __DIR__ . '/config/db.php';
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_id = intval($_SESSION['user_id']);
$user_sql = 'SELECT name, email, phone, image, created_at FROM users WHERE id = ?';
$user_stmt = mysqli_prepare($conn, $user_sql);
mysqli_stmt_bind_param($user_stmt, 'i', $user_id);
mysqli_stmt_execute($user_stmt);
$user_result = mysqli_stmt_get_result($user_stmt);
$user = mysqli_fetch_assoc($user_result);
$orders_sql = 'SELECT id, total_amount, status, payment_method, payment_status, created_at FROM orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 5';
$orders_stmt = mysqli_prepare($conn, $orders_sql);
mysqli_stmt_bind_param($orders_stmt, 'i', $user_id);
mysqli_stmt_execute($orders_stmt);
$orders_result = mysqli_stmt_get_result($orders_stmt);
$orders = [];
while ($row = mysqli_fetch_assoc($orders_result)) {
$orders[] = $row;
}
$payment_labels = [
'cod' => 'COD',
'esewa' => 'eSewa',
'khalti' => 'Khalti',
];
include __DIR__ . '/includes/header.php';
?>
<link rel="stylesheet" href="<?php echo CSS_PATH; ?>profile.css">
<h1 class="page-title">My Account</h1>
<?php if (isset($_SESSION['profile_success'])): ?>
<div class="auth-alert" style="max-width: 1100px; margin: 0 auto 20px;"><?php echo htmlspecialchars($_SESSION['profile_success']); ?></div>
<?php unset($_SESSION['profile_success']); ?>
<?php endif; ?>
<?php if (isset($_SESSION['profile_error'])): ?>
<div class="auth-alert" style="max-width: 1100px; margin: 0 auto 20px;"><?php echo htmlspecialchars($_SESSION['profile_error']); ?></div>
<?php unset($_SESSION['profile_error']); ?>
<?php endif; ?>
<div class="profile-wrapper">
<div class="profile-layout">
<div class="profile-card">
<form action="actions/update-avatar.php" method="POST" enctype="multipart/form-data" id="avatarForm">
<div class="avatar-wrapper">
<img class="profile-avatar" id="avatarPreview"
src="<?php echo htmlspecialchars(user_img($user['image'] ?? 'user.png')); ?>"
alt="<?php echo htmlspecialchars($user['name']); ?>">
<label for="avatarInput" class="avatar-change-btn" title="Change photo">
<i class="fas fa-camera"></i>
</label>
<input type="file" id="avatarInput" name="avatar" accept="image/jpeg,image/png,image/webp" style="display:none;">
</div>
</form>
<h2><?php echo htmlspecialchars($user['name']); ?></h2>
<p><?php echo htmlspecialchars($user['email']); ?></p>
<p>Member since <?php echo date('d M Y', strtotime($user['created_at'])); ?></p>
<a href="logout.php" class="logout-link"><i class="fas fa-sign-out-alt"></i> Logout</a>
</div>
<div class="profile-right">
<div class="profile-section">
<h3>Account Details</h3>
<form action="actions/update-profile.php" method="POST">
<div class="form-row">
<div class="form-group">
<label>Full Name</label>
<input type="text" name="name" value="<?php echo htmlspecialchars($user['name']); ?>" required>
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" name="phone" value="<?php echo htmlspecialchars($user['phone']); ?>" required>
</div>
</div>
<div class="form-row">
<div class="form-group full">
<label>Email Address</label>
<input type="email" name="email" value="<?php echo htmlspecialchars($user['email']); ?>" required>
</div>
</div>
<button type="submit" class="save-btn">Save Changes</button>
</form>
</div>
<div class="profile-section">
<h3>Order History <a href="my-orders.php" style="float:right;font-size:13px;">View All</a></h3>
<?php if (count($orders) > 0): ?>
<table class="order-table">
<tr>
<th>Order ID</th>
<th>Date</th>
<th>Payment</th>
<th>Total</th>
<th>Status</th>
</tr>
<?php foreach ($orders as $order):
$p_method = $payment_labels[$order['payment_method']] ?? ucfirst($order['payment_method']);
$p_status = ucfirst($order['payment_status'] ?? 'pending');
?>
<tr>
<td><strong>#<?php echo $order['id']; ?></strong></td>
<td><?php echo date('d M Y', strtotime($order['created_at'])); ?></td>
<td><?php echo htmlspecialchars($p_method); ?> (<?php echo htmlspecialchars($p_status); ?>)</td>
<td>Rs. <?php echo number_format($order['total_amount'], 2); ?></td>
<td><span class="order-status <?php echo strtolower($order['status']); ?>"><?php echo ucfirst($order['status']); ?></span></td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<p class="no-orders">You haven't placed any orders yet.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>
<script>
(function () {
const input = document.getElementById('avatarInput');
const preview = document.getElementById('avatarPreview');
const form = document.getElementById('avatarForm');
if (!input || !form) return;
input.addEventListener('change', function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (e) {
if (preview) preview.src = e.target.result;
};
reader.readAsDataURL(file);
form.submit();
});
})();
</script>