Files
selmer-bot-website/HTML/calendar.html
T
2022-12-24 09:24:24 -08:00

316 lines
14 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<span id="IMPORTS">
<link rel="shortcut icon" href="https://github.com/ION606/selmer-bot-website/blob/main/assets/favicon.ico?raw=true" type="image/x-icon">
<script src="https://kit.fontawesome.com/728e740903.js" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://js.stripe.com/v3/"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cinzel&family=Rajdhani:wght@300&family=Rouge+Script&family=Share+Tech+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/CSS/cal.css">
</span>
<title>Selmer Bot Web Dashboard</title>
<!-- Calendar -->
<script>
async function openNewCalWindow(evjs, day) {
const ev = JSON.parse(evjs);
await new Promise((res, rej) => { res(window.open('https://selmerbot.com/calEvent','popUpWindow','loaction=no,width=600,height=300,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')); })
.then((w) => {
if (!w) { w.close(); return alert("Your browser has JavaScript Disabled!"); }
w.sessionStorage.setItem("evlist", evjs);
w.sessionStorage.setItem('day', day);
w.sessionStorage.setItem('ref', 'user');
w.location.reload();
w.document.write('<title>Editing ${(new Date(Number(ev.time)))}</title>');
})
}
async function createCalEvent(day) {
await new Promise((res, rej) => { res(window.open('https://selmerbot.com/newCalEvent','popUpWindow','loaction=no,width=400,height=350,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')); })
.then((w) => {
if (!w) { w.close(); return alert("Your browser has JavaScript Disabled!"); }
w.sessionStorage.setItem("day", day);
w.sessionStorage.setItem("ref", 'user');
w.location.reload();
// w.document.write('<title>Editing ${(' + String(day) + ')}</title>');
});
}
//Month + 1 because the 0 will set the date back a month
function daysInMonth (d) {
return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
}
function calSetup(calList) {
const d = new Date((new Date()).getFullYear(), (new Date()).getMonth());
const startDay = new Date(d.getFullYear(), d.getMonth(), 1).getDay() + 1;
var cal = document.getElementById('calbody');
var tr = document.createElement('tr');
var dayint = 1;
const ll = daysInMonth(d);
for (let i = 1; i <= 42; i ++) {
var td = document.createElement('td');
if (i >= startDay && dayint <= ll) {
let btn = document.createElement('button');
btn.innerText = dayint.toString();
btn.classList.add('calbtn');
if (calList.has(Number(dayint.toString()))) { btn.classList.add('green'); }
else { btn.classList.add('red'); }
btn.onclick = function(event) {
const timestamp = new Date(new Date().getFullYear(), new Date().getMonth(), Number(this.innerText));
event.preventDefault();
if (calList.has(Number(this.innerText))) {
const ev = calList.get(Number(this.innerText));
openNewCalWindow(JSON.stringify(ev), Number(this.innerText));
} else {
// Check if the day has already passed
if (Number(this.innerText) >= (new Date()).getDate()) {
createCalEvent(Number(this.innerText));
} else {
alert("Please pick a future date!");
}
}
}
td.appendChild(btn);
dayint ++;
}
tr.appendChild(td);
if (i % 7 == 0) {
let tr2 = document.createElement('tr');
cal.appendChild(tr);
cal.appendChild(tr2);
tr2 = document.createElement('tr');
tr = document.createElement('tr');
}
}
cal.appendChild(tr);
if (window.innerWidth < 1020) {
//Calendar resize
const calSpacing = document.getElementById("spaceId");
calSpacing.cellSpacing = 1;
calSpacing.cellPadding = 1;
}
document.getElementById('calHeader').style = "";
}
</script>
<script>
function getSessionData() {
return new Promise((resolve, reject) => {
var xhrsess = new XMLHttpRequest();
xhrsess.open('post', 'https://selmerbot.com/getSessionInfo/', true);
xhrsess.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhrsess.setRequestHeader('session', window.localStorage.getItem('sessionId'));
//Reminder that this will return a map of strings (you'll have to use JSON.parse() again)
xhrsess.onloadend = (e) => {
resolve(JSON.parse(xhrsess.response));
}
xhrsess.send();
});
}
window.onload = () => {
var sessionId = window.localStorage.getItem('sessionId');
if (!sessionId) {
alert("Please log in to continue");
if (window.location.href.indexOf('localhost') != -1) {
window.location = 'https://discord.com/api/oauth2/authorize?client_id=926551095352901632&redirect_uri=http%3A%2F%2Flocalhost%3A53134%2F&response_type=token&scope=identify%20guilds';
} else {
window.location = 'https://discord.com/api/oauth2/authorize?client_id=944046902415093760&redirect_uri=https%3A%2F%2Fselmerbot.com%2F&response_type=token&scope=identify%20guilds';
}
}
//Get serverId
// const id = serverSettings.Id; // window.localStorage.getItem('Id').toString();
const session = getSessionData();
session.then((sessionInfo) => {
const id = sessionInfo.userId;
//Check if the user has premium
var xhrverify = new XMLHttpRequest();
xhrverify.open('post', 'https://selmerbot.com/verifypremium/', true);
xhrverify.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//Use the guild Id as the userId
xhrverify.setRequestHeader('userId', id);
xhrverify.onloadend = (e) => {
if (xhrverify.response == "Unauthorized") {
document.getElementById("unauth").style.display = "block";
return;
}
var xhr2 = new XMLHttpRequest();
xhr2.open('get', 'https://selmerbot.com/getCal/', true);
xhr2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//Use the guild Id as the userId
xhr2.setRequestHeader('userId', id);
// //import ics file
// const form = document.createElement("span");
// const label = document.createElement("label");
// label.innerText = "Upload File";
// label.className = "inpBtn";
// document.getElementsByTagName("body")[0].appendChild(label);
// const uploadICS = document.createElement('input');
// uploadICS.type = "file";
// form.appendChild(uploadICS);
// document.getElementsByTagName("body")[0].appendChild(form);
xhr2.onloadend = (e) => {
const calList = new Map();
const res = JSON.parse(xhr2.response);
const times = res[0];
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.getElementById('monthName').innerText = `Editing Reminders for the Month of ${monthNames[(new Date()).getMonth()]}`;
times.forEach((time, ind) => {
const fullDate = new Date(Number(time));
const month = fullDate.getMonth();
const day = fullDate.getDate();
//Make sure it's the right month (old ones should be removed, this is just a catch)
if (month == (new Date()).getMonth()) {
if (calList.has(day)) {
var temp = calList.get(day);
temp.push(res[1][ind]);
calList.set(day, temp);
} else {
calList.set(day, [res[1][ind]]);
}
}
});
calSetup(calList);
}
xhr2.send();
}
xhrverify.send();
});
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-fixed-top">
<div class="container-fluid mx-auto">
<a class="navbar-brand" href="/">
<img src="https://github.com/ION606/selmer-bot-website/blob/main/assets/Selmer-icon.png?raw=true" alt="Selmer Icon" style="width: 50px;">
</a>
<!-- <li class="nav-item">
<a href="index.html" style="color: white" class="nav-link"><i class="fa-solid fa-house-chimney", alt="Home" style="scale: 2;"></i></a>
</li> -->
<ul class="navbar-nav">
<li class="nav-item">
<a href="myGuilds" id="guildslink" class="nav-link"><i class="fa-solid fa-server" alt="Servers" style="scale: 2; color: rgb(11, 189, 189);"></i></a>
</li>
<li class="nav-item">
<a href="calendar" id="callink" class="nav-link"><i class="fa-solid fa-calendar" alt="Calendar" style="scale: 2; color: lightgrey;"></i></a>
</li>
<li class="nav-item">
<a href="https://docs.selmerbot.com" target="_blank" class="nav-link"><i class="fa-solid fa-book" style="scale: 2; color: white;" alt="WIKI"></i></a>
</li>
<li class="nav-item">
<a href="premium" class="nav-link"><i class="fa-solid fa-crown" style="scale: 2; color: gold;" alt="PREMIUM"></i></a>
</li>
<li class="nav-item">
<a href="team" class="nav-link"><i class="fa-solid fa-user-gear" style="scale: 2; color: rgb(12, 216, 5);" alt="AUTHOR"></i></a>
</li>
</ul>
<!-- <button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="Hooray!">Hover over me!</button> -->
<div class="container" style="font-family: 'Rajdhani', sans-serif; color: white;"><h1>Selmer Bot Web Dashboard</h1></div>
<span class="ms-auto" style="margin-right: 1%;">
<button onclick="logout()" id="logoutbtn" class="logoutbtn"><i class="fa-solid fa-arrow-right-from-bracket" alt="Log Out"></i></button>
</span>
</div>
</nav>
<div id="cal" class="wc" style="margin-top: 20px;">
<h1 id="monthName" style="text-align: center; margin-top: 50px; margin-bottom: 25px;"></h1>
<form>
<table id="spaceId" style="background-color: lightgrey;"
cellspacing="15" cellpadding="15" class="mx-auto">
<caption style="caption-side: top;"></caption>
<div id="unauth" style="display: none;" class="text-center">
<h1 style="margin-bottom: 20px;">You have to be a premium subscriber to use this feature!</h1>
<h3 style="margin-bottom: 50px;">vvv GET PREMIUM NOW vvv</h3>
<a href="premium"><i class="fa-solid fa-crown" style="scale: 4; color: gold;" alt="PREMIUM"></i></a>
</div>
<thead>
<tr id="calHeader" style="display: none;">
<th style="color: white; background: purple;">
Sun</th>
<th style="color: white; background: purple;">
Mon</th>
<th style="color: white; background: purple;">
Tue</th>
<th style="color: white; background: purple;">
Wed</th>
<th style="color: white; background: purple;">
Thu</th>
<th style="color: white; background: purple;">
Fri</th>
<th style="color: white; background: purple;">
Sat</th>
</tr>
</thead>
<tbody id="calbody" style="color: black;">
</tbody>
</table>
</form>
</body>
</html>