This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadventcalendar.php
More file actions
144 lines (126 loc) · 4.48 KB
/
Copy pathadventcalendar.php
File metadata and controls
144 lines (126 loc) · 4.48 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
<?php
exit;
include 'header.php';
function hasOpenedToday($userId)
{
global $db;
$today = date('Y-m-d');
$db->query("SELECT COUNT(id) as account FROM `advent_calendar` WHERE `user_id` = ? AND `date_opened` = ?");
return (int) $db->fetch_row(false, [$userId, $today])[0]['account'] > 0;
}
function awardItem($userId)
{
global $db;
$prizesIndexedOnDate = array(
'2024-12-01' => 277, // Mission Pass
'2024-12-02' => 290, // Toffee Apple
'2024-12-03' => 283, // Gold Rush Token Chest
'2024-12-04' => 277, // Mission Pass
'2024-12-05' => 277, // Mission Pass
'2024-12-06' => 271, // Sofa
'2024-12-07' => 276, // Research Token
'2024-12-08' => 277, // Mission Pass
'2024-12-09' => 277, // Mission Pass
'2024-12-10' => 277, // Mission Pass
'2024-12-11' => 283, // Gold Rush Token Chest
'2024-12-12' => 290, // Toffee Apple
'2024-12-13' => 276, // Research Token
'2024-12-14' => 283, // Gold Rush Token Chest
'2024-12-15' => 295, // Christmas Gift
'2024-12-16' => 290, // Toffee Apple
'2024-12-17' => 295, // Christmas Gift
'2024-12-18' => 283, // Gold Rush Token Chest
'2024-12-19' => 276, // Research Token
'2024-12-20' => 295, // Christmas Gift
'2024-12-21' => 271, // Sofa
'2024-12-22' => 277, // Mission Pass
'2024-12-23' => 295, // Christmas Gift
'2024-12-24' => 283, // Gold Rush Token Chest
'2024-12-25' => 278, // Sound System
);
$today = date('Y-m-d');
$itemId = $prizesIndexedOnDate[$today];
$db->query("INSERT INTO `advent_calendar` (`user_id`, `date_opened`, `item_awarded`) VALUES (?, ?, ?)");
$db->execute([$userId, $today, $itemId]);
// Logic to actually give the item to the user
Give_Item($itemId, $userId, 1);
return $itemId;
}
function displayCalendar($userId)
{
$today = date('j');
echo '<div class="row">';
for ($day = 1; $day <= 25; $day++) {
if ($day == $today) {
if (hasOpenedToday($userId)) {
echo "<div class='day opened'>Day $day: Already opened</div>";
} else {
echo "<div class='day today'><a href='?open=$day'>Open Day $day</a></div>";
}
} else {
echo "<div class='day'>Day $day</div>";
}
}
echo '</div>';
}
if (isset($_GET['open']) && $_GET['open'] == date('j')) {
if (!hasOpenedToday($user_class->id)) {
$item = awardItem($user_class->id);
echo "
<div class='alert alert-success'>
You have been awarded: 1 x " . Item_Name($item) . "
</div>
";
} else {
echo "<div class='alert alert-danger'>You have already opened today's calendar.</div>";
}
}
$today = date('j');
?>
<div class='box_top'>
<h1>Advent Calendar</h1>
</div>
<div class='box_middle'>
<div class='pad'>
<div class="row">
<?php for ($day = 1; $day <= 25; $day++): ?>
<?php
$divClass = 'bg-info';
if ($day == $today) {
if (hasOpenedToday($user_class->id)) {
$divClass = 'bg-success';
} else {
$divClass = 'bg-danger';
}
}
?>
<div class="col-md-4">
<div class="card text-white <?php echo $divClass ?> mb-3">
<div class="card-body">
<h2 class="card-text">
<center>
<strong>Day <?php echo $day ?></strong><br />
<?php
if ($day == $today) {
if (hasOpenedToday($userId)) {
} else {
echo '<a href="?open=' . $day . '" class="btn btn-primary">Claim</a>';
}
}
?>
</center>
</p>
</div>
</div>
</div>
<?php if ($day % 3 == 1): ?>
</div>
<div class="row">
<?php endif; ?>
<?php endfor; ?>
</div>
</div>
</div>
<?php
include 'footer.php';
?>