Skip to content

Instantly share code, notes, and snippets.

@mateuslacorte
Last active October 18, 2023 01:56
Show Gist options
  • Select an option

  • Save mateuslacorte/9068f95820ab473b34121ec80b904579 to your computer and use it in GitHub Desktop.

Select an option

Save mateuslacorte/9068f95820ab473b34121ec80b904579 to your computer and use it in GitHub Desktop.
<?php
$remote_addr = "your-ip-address";
$authorized = $_SERVER["REMOTE_ADDR"] === $remote_addr;
$uri = "mongodb+srv://your-user:your-password@your-mongodb-server/?retryWrites=true&w=majority";
$mongo = new MongoDB\Driver\Manager($uri);
$query = new MongoDB\Driver\Query([], []);
$activities_cursor = $mongo->executeQuery('schedule.schedule', $query);
$activities = [];
foreach ($activities_cursor as $activity) {
array_push($activities, [
"activity" => $activity->activity,
"date" => date("d M Y", $activity->date->toDateTime()->getTimestamp()),
"time" => date("h:i A", $activity->date->toDateTime()->getTimestamp()),
"link" => $activity->link
]);
}
function sort_date($a, $b) {
return strtotime($a["date"] . " " . $a["time"]) - strtotime($b["date"] . " " . $b["time"]);
}
usort($activities, "sort_date");
?>
<!doctype html>
<html lang=en>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Interview Schedule Management System</title>
<link href='https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css' rel='stylesheet'>
<style>
button:hover {
background-color: lightgray;
}
button:disabled {
background-color: black;
color: white;
}
</style>
</head>
<body oncontextmenu='return false' class='snippet-body'>
<div class="container rounded mt-5 bg-white p-md-5">
<div class="h2 font-weight-bold">Schedule</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="pt-3 text-center">Activity</th>
<th class="pt-3 text-center">Date</th>
<th class="pt-3 text-center">Time</th>
<th class="pt-3 text-center">Time Zone</th>
<th class="pt-3 text-center">Room</th>
</tr>
</thead>
<tbody>
<?php foreach ($activities as $index=>$activity) { ?>
<tr class="bg-blue <?php echo count($activities) > $index+1 ? "mb-3" : ""; ?>">
<td class="pt-3 text-center"><?php echo $activity["activity"] ?></td>
<td class="pt-3 mt-1 text-center"><?php echo $activity["date"] ?></td>
<td class="pt-3 text-center"><?php echo $activity["time"] ?></td>
<td class="pt-3 text-center">BRT (-3 UTC)</td>
<td class="pt-3 text-center"><button type="button" <?php echo $authorized && !empty($activity["link"]) ? "onclick=\"window.open('" . $activity["link"] . "', '_blank');\"" : "disabled" ?>><?php echo $authorized && !empty($activity["link"]) ? "Join" : "Not available" ?></button></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment