Moodle Sabbath Deadline Detection Javascript
<script>
// Moodle Sabbath Deadline Detection - Copyright 2021 Winelfred Pasamba - Free to use
function checkAroundSabbathDeadlines() {
if (typeof id_timeclose_enabled !== 'undefined' && id_timeclose_enabled.checked) {
var ds = document.getElementById("id_timeclose_year").value + "-" +
document.getElementById("id_timeclose_month").value + "-" +
document.getElementById("id_timeclose_day").value;
var hour = document.getElementById("id_timeclose_hour").value;
}
if (typeof id_duedate_enabled !== 'undefined' && id_duedate_enabled.checked) {
var ds = document.getElementById("id_duedate_year").value + "-" +
document.getElementById("id_duedate_month").value + "-" +
document.getElementById("id_duedate_day").value;
var hour = document.getElementById("id_duedate_hour").value;
}
if (typeof id_cutoffdate_enabled !== 'undefined' && id_cutoffdate_enabled.checked) {
var ds = document.getElementById("id_cutoffdate_year").value + "-" +
document.getElementById("id_cutoffdate_month").value + "-" +
document.getElementById("id_cutoffdate_day").value;
var hour = document.getElementById("id_cutoffdate_hour").value;
}
if (typeof id_submissionend_enabled !== 'undefined' && id_submissionend_enabled.checked) {
var ds = document.getElementById("id_submissionend_year").value + "-" +
document.getElementById("id_submissionend_month").value + "-" +
document.getElementById("id_submissionend_day").value;
var hour = document.getElementById("id_submissionend_hour").value;
}
console.log (ds);
var d = new Date (ds);
var dow = d.getDay();
if (dow == 5 && hour >= 13) {
console.log ("Friday Afternoon and beyond");
if (typeof id_submissionend_enabled !== 'undefined' && id_submissionend_enabled.checked) id_submissionend_enabled.click();
if (typeof id_timeclose_enabled !== 'undefined' && id_timeclose_enabled.checked) id_timeclose_enabled.click();
if (typeof id_cutoffdate_enabled !== 'undefined' && id_cutoffdate_enabled.checked) id_cutoffdate_enabled.click();
if (typeof id_duedate_enabled !== 'undefined' && id_duedate_enabled.checked) id_duedate_enabled.click();
alert ("Friday afternoon deadline detected. Since there are no classes & offices during Friday afternoon, so people can prepare for the Sabbath, please consider setting deadlines a long way clear of Sabbath hours to avoid tempting students into doing requirements on the Sabbath specially that not all students are in the same time zone. You may reload/refresh this page to try again.");
}
if (dow == 6) {
console.log ("Saturday");
if (typeof id_submissionend_enabled !== 'undefined' && id_submissionend_enabled.checked) id_submissionend_enabled.click();
if (typeof id_timeclose_enabled !== 'undefined' && id_timeclose_enabled.checked) id_timeclose_enabled.click();
if (typeof id_cutoffdate_enabled !== 'undefined' && id_cutoffdate_enabled.checked) id_cutoffdate_enabled.click();
if (typeof id_duedate_enabled !== 'undefined' && id_duedate_enabled.checked) id_duedate_enabled.click();
alert ("Saturday night deadline detected. Please consider setting deadlines a long way clear of Sabbath hours to avoid tempting students into doing requirements on the Sabbath specially that not all students are in the same time zone. You may reload/refresh this page to try again.");
}
if (dow == 0 && hour < 12) {
console.log ("Sunday morning");
if (typeof id_submissionend_enabled !== 'undefined' && id_submissionend_enabled.checked) id_submissionend_enabled.click();
if (typeof id_timeclose_enabled !== 'undefined' && id_timeclose_enabled.checked) id_timeclose_enabled.click();
if (typeof id_cutoffdate_enabled !== 'undefined' && id_cutoffdate_enabled.checked) id_cutoffdate_enabled.click();
if (typeof id_duedate_enabled !== 'undefined' && id_duedate_enabled.checked) id_duedate_enabled.click();
alert ("Sunday morning deadline detected. Please consider setting deadlines a long way clear of Sabbath hours to avoid tempting students into doing requirements on the Sabbath specially that not all students are in the same time zone. You may reload/refresh this page to try again.");
}
}
if (typeof id_timeclose_enabled !== 'undefined') {
document.getElementById("id_timeclose_enabled").addEventListener("click", checkAroundSabbathDeadlines);
document.getElementById("id_timeclose_hour").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_timeclose_minute").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_timeclose_year").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_timeclose_month").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_timeclose_day").addEventListener("change", checkAroundSabbathDeadlines);
}
if (typeof id_duedate_enabled !== 'undefined') {
document.getElementById("id_duedate_enabled").addEventListener("click", checkAroundSabbathDeadlines);
document.getElementById("id_duedate_hour").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_duedate_minute").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_duedate_year").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_duedate_month").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_duedate_day").addEventListener("change", checkAroundSabbathDeadlines);
}
if (typeof id_cutoffdate_enabled !== 'undefined') {
document.getElementById("id_cutoffdate_enabled").addEventListener("click", checkAroundSabbathDeadlines);
document.getElementById("id_cutoffdate_hour").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_cutoffdate_minute").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_cutoffdate_year").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_cutoffdate_month").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_cutoffdate_day").addEventListener("change", checkAroundSabbathDeadlines);
}
if (typeof id_submissionend_enabled !== 'undefined') {
document.getElementById("id_submissionend_enabled").addEventListener("click", checkAroundSabbathDeadlines);
document.getElementById("id_submissionend_hour").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_submissionend_minute").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_submissionend_year").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_submissionend_month").addEventListener("change", checkAroundSabbathDeadlines);
document.getElementById("id_submissionend_day").addEventListener("change", checkAroundSabbathDeadlines);
}
</script>