Repository navigation
Expand file tree
/
Copy pathdashboard.php
More file actions
161 lines (152 loc) · 6.96 KB
/
Copy pathdashboard.php
File metadata and controls
161 lines (152 loc) · 6.96 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
<?php
include './api/users/contribution.php';
include './api/task/functions.php';
include './api/points/functions.php';
include './api/goals/functions.php';
include './api/credentials.php';
include './api/users/functions.php';
enforce_role('user');
$tasks = task_fetch_daily_tasks();
$globalGoals = goals_contributions_global();
$completionRates = goals_completion_rate();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <meta name="viewport" content="initial-scale=1, maximum-scale=1"> -->
<title>Dashboard | EcoQuest</title>
<link rel="stylesheet" href="./styles/style.css">
<link rel="stylesheet" href="./styles/dashboard.css">
</head>
<body>
<div id="page">
<div id="parent">
<div id="header">
<div id="stats">
<div id="leaves">
<h4>
<?php echo points_get_current($username); ?>
</h4>
<img src="./assets/leaf.svg">
</div>
<div id="streak">
<img src="./assets/fire.svg">
<h4>
<?php echo user_get_streak($username) ?>
</h4>
</div>
</div>
<img onclick="toggleNavbar()" id="burger" src="./assets/burger.svg">
</div>
<div id="streak-info" class="border">
<h6 class="box-title">CURRENT STREAK</h6>
<img src="./assets/fire.svg" class="border">
<div id="details">
<h2>
<?php echo user_get_streak($username) . " day" . (user_get_streak($username) == 1 ? "" : "s") ?>
</h2>
<h5>
better than <?php echo user_get_streak_percentile($username) ?>% of users!
</h5>
</div>
</div>
<div id="fun-fact" class="border" data-state='loading' data-payload='<?php echo htmlspecialchars(json_encode(user_get_contribution_total_worded($username))); ?>'>
<div id="data">
<h4>Fun fact!</h4>
<h5></h5>
<!-- <h5>You saved 10kg of plastic and 5kWh of electricity. That is equivalent to 500 lego bricks and 3 bags of coal!</h5> -->
</div>
<div id="loading">
<div id="spinner"></div>
<h5>generating fun fact with AI...</h5>
</div>
<div id="failure">
<h4>oh no</h4>
<h5>something went wrong trying to generate. maybe try again later?</h5>
</div>
</div>
<div id="tasks">
<div id="title">
<h3>DAILY TASKS</h3>
<a href="./tasks.php" id="view-all" class="border">
<h5>view all</h5>
<img src="./assets/arrow_right.svg">
</a>
</div>
<div id="task-container">
<?php foreach (
array_filter($tasks, function ($v, $_) {
global $username;
return !task_already_submitted($v['ID'], $username); // TODO: REPLACE WITH SESSION
}, ARRAY_FILTER_USE_BOTH) as $row
): ?>
<a class="task-card" id="<?php echo $row['occurance_type'] ?>" href="./task_submission.php?ID=<?php echo urlencode($row['ID']) ?>">
<img id="icon" class="border" src="./assets/leaf.svg">
<div id="details">
<h4><?php echo $row['title'] ?></h4>
<h6><?php echo $row['description'] ?></h6>
</div>
<div id="points">
<h6><?php echo $row['target'] * $row['reward_rate'] ?></h6>
<img src="./assets/leaf.svg">
</div>
</a>
<?php endforeach; ?>
<div id="finished-all">
<h5>wow, you completed all your daily tasks!</h5>
<h6 class="countdown-finished"></h6>
</div>
</div>
<div id="timer">
<h6>new tasks in</h6>
<h6 class="countdown"></h6>
</div>
</div>
<div id="goals">
<h3 id="title">GLOBAL GOALS</h3>
<?php foreach ($globalGoals as $goal):
$progress = $goal['goal'] > 0 ? ($goal['total'] / $goal['goal']) * 100 : 0;
$completionRate = isset($completionRates[$goal['ID']]) ? $completionRates[$goal['ID']] : 0;
?>
<div id="goal-container">
<div class="goal-card">
<div id="header">
<img src="<?php echo htmlspecialchars($goal['media']); ?>" class="border">
<div id="details">
<h4>
<?php echo htmlspecialchars($goal['title']); ?>
</h4>
<h5>
<?php echo htmlspecialchars($goal['description']); ?>
</h5>
</div>
</div>
<div id="data">
<div>
<div id="details">
<h2 id="target">
<?php echo number_format($goal['total'], 1); ?>
</h2>
<h5>/ <?php echo number_format($goal['goal'], 0); ?> <?php echo $goal['goal_type']; ?></h5>
</div>
<h6><?php echo round($progress); ?>% progress</h6>
</div>
<div class="progressbar">
<div id="thumb" style="width: <?php echo min(100, $progress); ?>%;"></div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php include './components/navbar.php' ?>
</div>
<script src="./scripts/script.js"></script>
<script src="./scripts/cohere.js"></script>
<script src="./scripts/navbar.js" defer></script>
<script src="./scripts/dashboard.js"></script>
</body>
</html>