-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
168 lines (135 loc) · 6.01 KB
/
Copy pathdashboard.php
File metadata and controls
168 lines (135 loc) · 6.01 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
<?php
include_once("backend/session.php");
if(!isset($_SESSION['userid'])) {
echo "<script>location.href = 'login_main.php';</script>";
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<link rel="shortcut icon" type="image/icon" href="assets/logo/favicon.png"/>
<link rel="stylesheet" type="text/css" href="assets/css/dashboard.css">
<script src="assets/js/dashboard.js"></script>
</head>
<body>
<script>
function topUp(targetid) {
var amount = window.prompt('Enter the amount to top up:', '');
if (amount !== null) {
if (isNaN(amount) || amount <= 0) {
alert('Invalid amount.');
} else {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'backend/topup.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send('targetid=' + targetid + '&amount=' + amount);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById('balance').innerText = xhr.responseText;
} else if (xhr.readyState == 4 && xhr.status != 200) {
alert('Top up failed.');
}
}
}
}
}
window.onload = function() {
var buttons = document.querySelectorAll('.btn-menu');
// Function to reset all buttons
function resetButtons() {
buttons.forEach(function(button) {
button.style.color = "";
button.style.backgroundColor = "";
button.classList.remove('defaultButton');
});
}
// Add event listener to each button (menu)
buttons.forEach(function(button) {
button.addEventListener('click', function() {
resetButtons();
this.style.color = "white";
this.style.backgroundColor = "black";
});
});
}
</script>
<section id="collection-1602">
<div class="cs-container">
<div class="cs-content">
<h2 class="cs-title">Welcome back,
<?php echo $_SESSION["fullname"] ?>
</h2>
<div class="cs-button-group">
<div class='flex-container'>
<?php
$userid = $_SESSION['userid'];
$usertype = $_SESSION['usertype'];
$token = $_SESSION['token'];
include_once("backend/mylib.php");
if($_SESSION['usertype'] == 1) {
echo "<h3>";
echo "Balance: $";
echo "<label id='balance'>" . getStudentBalance($_SESSION['userid']) . "</label>";
echo "</h3>";
echo "<h3><button class='cs-button' onclick='topUp($userid)'>Top Up</button></h3>";
echo "<h3><button class='cs-button btn-menu defaultButton' onclick='document.getElementById(\"dashboard\").src=\"dashboard_student.php\"'>Shops</button></h3>";
echo "<h3><button class='cs-button btn-menu' onclick='document.getElementById(\"dashboard\").src=\"dashboard_records.php\"'>Transaction</button></h3>";
} else if ($_SESSION['usertype'] == 2){
echo "<h3><button class='cs-button btn-menu defaultButton' onclick='document.getElementById(\"dashboard\").src=\"dashboard_parent.php\"'>Your Students</button></h3>";
echo "<h3><button class='cs-button btn-menu' onclick='document.getElementById(\"dashboard\").src=\"dashboard_edit.php\"'>Management</button></h3>";
echo "<h3><button class='cs-button btn-menu' onclick='document.getElementById(\"dashboard\").src=\"dashboard_records.php\"'>Transactions</button></h3>";
} else {
echo "<h3><button class='cs-button btn-menu defaultButton' onclick='document.getElementById(\"dashboard\").src=\"dashboard_edit.php\"'>Management</button></h3>";
echo "<h3><button class='cs-button btn-menu' onclick='document.getElementById(\"dashboard\").src=\"dashboard_suppliers.php\"'>Suppliers</button></h3>";
echo "<h3><button class='cs-button btn-menu' onclick='document.getElementById(\"dashboard\").src=\"dashboard_records.php\"'>Transactions</button></h3>";
}
?>
</h3>
<button class="cs-button" onclick="location.href='backend/logout.php'">
Logout
</button>
</div>
</div>
</div>
</div>
</section>
<style>
body {
overflow: auto;
scrollbar-width: none; /* For Firefox */
-ms-overflow-style: none; /* For Internet Explorer and Edge */
}
body::-webkit-scrollbar {
width: 0px; /* For Chrome, Safari, and Opera */
}
iframe {
height: 100%;
width: 100%;
}
#balance {
padding-right: 10px;
}
.flex-container {
display: flex;
align-items: center;
justify-content: flex-end;
}
.defaultButton {
color: white !important;
background-color: black !important;
}
</style>
<iframe src="dashboard_student.php" id="dashboard"></iframe>
<?php
// set startup page based on usertype
if($_SESSION['usertype'] == 1) {
echo "<script>document.getElementById('dashboard').src = 'dashboard_student.php';</script>";
} else if ($_SESSION['usertype'] == 2) {
echo "<script>document.getElementById('dashboard').src = 'dashboard_parent.php';</script>";
} else {
echo "<script>document.getElementById('dashboard').src = 'dashboard_edit.php';</script>";
}
?>
</body>
</html>