-
Notifications
You must be signed in to change notification settings - Fork 0
/
kalender.cpp
186 lines (161 loc) · 6.62 KB
/
kalender.cpp
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
#include <httplib.h>
#include <iostream>
#include <string>
using namespace httplib;
std::string generate_calendar_html() {
std::string html_content = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Membuat Kalender dengan JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
</head>
<body>
<div class="container col-sm-4 col-md-7 col-lg-9 mt-9">
<div class="card">
<h3 class="card-header" id="monthAndYear"></h3>
<table class="table table-bordered table-responsive-sm" id="calendar">
<thead>
<tr>
<th>Min</th>
<th>Sen</th>
<th>Sel</th>
<th>Rab</th>
<th>Kam</th>
<th>Jum</th>
<th>Sab</th>
</tr>
</thead>
<tbody id="calendar-body">
</tbody>
</table>
<div class="form-inline">
<button class="btn btn-outline-primary col-sm-6" id="previous">Sebelumnya</button>
<button class="btn btn-outline-primary col-sm-6" id="next">Selanjutnya</button>
</div>
<br/>
<form class="form-inline">
<label class="lead mr-2 ml-2" for="month">Loncat ke: </label>
<select class="form-control col-sm-4" name="month" id="month">
<option value=0>Jan</option>
<option value=1>Feb</option>
<option value=2>Mar</option>
<option value=3>Apr</option>
<option value=4>Mei</option>
<option value=5>Jun</option>
<option value=6>Jul</option>
<option value=7>Agu</option>
<option value=8>Sep</option>
<option value=9>Okt</option>
<option value=10>Nov</option>
<option value=11>Des</option>
</select>
<label for="year"></label>
<select class="form-control col-sm-4" name="year" id="year">
<!-- Populate dynamically -->
</select>
</form>
</div>
</div>
<!-- JavaScript -->
<script>
let today = new Date();
let currentMonth = today.getMonth();
let currentYear = today.getFullYear();
let selectYear = document.getElementById("year");
let selectMonth = document.getElementById("month");
let months = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"];
let monthAndYear = document.getElementById("monthAndYear");
showCalendar(currentMonth, currentYear);
document.getElementById("next").addEventListener("click", next);
document.getElementById("previous").addEventListener("click", previous);
function next() {
currentYear = (currentMonth === 11) ? currentYear + 1 : currentYear;
currentMonth = (currentMonth + 1) % 12;
showCalendar(currentMonth, currentYear);
}
function previous() {
currentYear = (currentMonth === 0) ? currentYear - 1 : currentYear;
currentMonth = (currentMonth === 0) ? 11 : currentMonth - 1;
showCalendar(currentMonth, currentYear);
}
function jump() {
currentYear = parseInt(selectYear.value);
currentMonth = parseInt(selectMonth.value);
showCalendar(currentMonth, currentYear);
}
function showCalendar(month, year) {
let today = new Date();
let firstDay = (new Date(year, month)).getDay();
let daysInMonth = 32 - new Date(year, month, 32).getDate();
let tbl = document.getElementById("calendar-body"); // body of the calendar
tbl.innerHTML = "";
monthAndYear.innerHTML = months[month] + " " + year;
selectYear.value = year;
selectMonth.value = month;
let date = 1;
for (let i = 0; i < 6; i++) {
let row = document.createElement("tr");
for (let j = 0; j < 7; j++) {
if (i === 0 && j < firstDay) {
let cell = document.createElement("td");
let cellText = document.createTextNode("");
cell.appendChild(cellText);
row.appendChild(cell);
} else if (date > daysInMonth) {
break;
} else {
let cell = document.createElement("td");
let cellText = document.createTextNode(date);
if (date === today.getDate() && year === today.getFullYear() && month === today.getMonth()) {
cell.classList.add("bg-info");
}
cell.appendChild(cellText);
row.appendChild(cell);
date++;
}
}
tbl.appendChild(row);
}
}
// Populate the year dropdown
let yearOptions = document.getElementById("year");
for (let i = 1990; i <= 2030; i++) {
let option = document.createElement("option");
option.value = i;
option.text = i;
yearOptions.appendChild(option);
}
document.getElementById("month").addEventListener("change", jump);
document.getElementById("year").addEventListener("change", jump);
</script>
<!-- Optional JavaScript for bootstrap -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"
integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"
integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm"
crossorigin="anonymous"></script>
</body>
</html>
)";
return html_content;
}
int main() {
Server svr;
svr.Get("/", [](const Request& /*req*/, Response& res) {
res.set_content(generate_calendar_html(), "text/html");
});
int port = 8181; // Ganti port jika dibutuhkan!
std::cout << "Sedang membuka kalender di server http://localhost:" << port << std::endl; //terserah anda jika ingin ubah pesan nya
svr.listen("localhost", port); //biarkan saja
return 0;
}