summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/hw_schedule2_backend.php176
-rw-r--r--hw_schedule2.css128
-rw-r--r--hw_schedule2.js513
-rw-r--r--hw_schedule2.php208
4 files changed, 1025 insertions, 0 deletions
diff --git a/backend/hw_schedule2_backend.php b/backend/hw_schedule2_backend.php
new file mode 100644
index 0000000..55d3588
--- /dev/null
+++ b/backend/hw_schedule2_backend.php
@@ -0,0 +1,176 @@
+<?php
+
+include "config.php";
+
+if($_REQUEST['type'] == "save_class"){
+ print htmlspecialchars( $_REQUEST['add_class_desc'] );
+
+ print "Will add<br>";
+
+ $name = empty($_REQUEST['add_class_desc']) ? "" : $_REQUEST['add_class_desc'];
+ $code = empty($_REQUEST['add_class_id']) ? "" : $_REQUEST['add_class_id'];
+ $location = empty($_REQUEST['add_class_location']) ? "left" : $_REQUEST['add_class_location'];
+ $link = empty($_REQUEST['add_class_link']) ? "" : $_REQUEST['add_class_link'];
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+
+ if(!$code) print "Missing inputs<br>";
+ else{
+ $location = $location == "left" ? 0 : 1;
+
+ $name = mysqli_real_escape_string($db, $name);
+ $code = mysqli_real_escape_string($db, $code);
+ //$location = mysqli_real_escape_string($db, $location);
+ $link = mysqli_real_escape_string($db, $link);
+ $id = mysqli_real_escape_string($db, $id);
+
+ //if $id exists, this should be an update query, instead of an insert query
+ if($id) $q = "UPDATE Classes SET Name = '$name', Code = '$code', Location = '$location', Link = '$link' WHERE id = '$id'";
+ else $q = "INSERT INTO Classes (Name, Code, Location, Link) VALUES ('$name', '$code', '$location', '$link')";
+ if(mysqli_query($db, $q)) print "Success";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+
+}
+
+elseif($_REQUEST['type'] == "load_classes"){
+ $q = "SELECT * FROM Classes WHERE Hidden = '0'";
+
+ //allow for selection of specific id
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+ if($id){
+ $id = mysqli_real_escape_string($db, $id);
+ $q .= "AND id = $id";
+ }
+
+ $res = mysqli_query($db, $q);
+ if(mysqli_num_rows($res) > 0) print json_encode(mysqli_fetch_all($res));
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+}
+
+elseif($_REQUEST['type'] == "delete_class"){
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+ if(!$id) print "Missing inputs<br>";
+ else{
+ $id = mysqli_real_escape_string($db, $id);
+ $q = "UPDATE Classes Set Hidden = '1' WHERE id = '$id'";
+ if(mysqli_query($db, $q)) print "Success";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+
+ //also need to hide corresponding assignments
+ $q = "UPDATE Assignments Set Hidden = '1' WHERE Class_id = '$id'";
+ if(mysqli_query($db, $q)) print "Success";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+}
+
+
+elseif($_REQUEST['type'] == "save_assignment"){
+ print htmlspecialchars( $_REQUEST['add_desc'] );
+
+ print "Will add<br>";
+
+ $class_id = empty($_REQUEST['add_class_id']) ? "" : $_REQUEST['add_class_id'];
+ $due_date = empty($_REQUEST['add_due_date']) ? "" : $_REQUEST['add_due_date'];
+ $due_date_alt = empty($_REQUEST['add_due_date_alt']) ? "" : $_REQUEST['add_due_date_alt'];
+ $desc = empty($_REQUEST['add_desc']) ? "" : $_REQUEST['add_desc'];
+ $color = empty($_REQUEST['add_color']) ? "" : $_REQUEST['add_color'];
+ $highlight = empty($_REQUEST['add_highlight']) ? "" : $_REQUEST['add_highlight'];
+ $link = empty($_REQUEST['add_link']) ? "" : $_REQUEST['add_link'];
+ $done = 0;
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+
+ if(!$desc) print "Missing inputs<br>";
+ else{
+ $class_id = mysqli_real_escape_string($db, $class_id);
+ $due_date = mysqli_real_escape_string($db, $due_date);
+ $due_date_alt = mysqli_real_escape_string($db, $due_date_alt);
+ $desc = mysqli_real_escape_string($db, $desc);
+ $color = mysqli_real_escape_string($db, $color);
+ $highlight = mysqli_real_escape_string($db, $highlight);
+ $link = mysqli_real_escape_string($db, $link);
+ $id = mysqli_real_escape_string($db, $id);
+
+ //if $id exists, this should be an update query, instead of an insert query
+ if($id) $q = "UPDATE Assignments SET Due_date = " . ($due_date ? "'$due_date'" : "NULL") . ", Alt_due_date = '$due_date_alt', Description = '$desc', Color = '$color', Highlight = '$highlight', Link = '$link' WHERE id = '$id'";
+ else $q = "INSERT INTO Assignments (Class_ID, Due_date, Alt_due_date, Description, Color, Highlight, Done, Link) VALUES ('$class_id', " . ($due_date ? "'$due_date'" : "NULL") . ", '$due_date_alt', '$desc', '$color', '$highlight', '$done', '$link')";
+ if(mysqli_query($db, $q)) print "Success $q";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+}
+
+elseif($_REQUEST['type'] == "load_assignments"){
+ $q = "SELECT * FROM Assignments WHERE Hidden != 1 ";
+
+ //allow for selection of specific id
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+ if($id){
+ $id = mysqli_real_escape_string($db, $id);
+ $q .= "AND id = $id ";
+ }
+ $q .= "ORDER BY Due_date";
+
+ $res = mysqli_query($db, $q);
+ if(mysqli_num_rows($res) > 0) print json_encode(mysqli_fetch_all($res));
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+}
+
+elseif($_REQUEST['type'] == "clone_assignment"){
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+
+ if(!$id) print "Missing inputs<br>";
+ else{
+ $id = mysqli_real_escape_string($db, $id);
+
+ $q = "SELECT * FROM Assignments WHERE id = '$id'";
+ $res = mysqli_query($db, $q);
+ if(mysqli_num_rows($res) > 0){
+ $row = mysqli_fetch_assoc($res);
+ }
+ else{
+ print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ return;
+ }
+
+ if(!$row["Due_date"]) $row["Due_date"] = "NULL";
+ $q = "INSERT INTO Assignments (";
+ for($i = 1; $i < count($row); ++$i){
+ $q .= array_keys($row)[$i];
+ if($i+1 < count($row)) $q .= ", ";
+ }
+ $q .= ") VALUES (";
+ for($i = 1; $i < count($row); ++$i){
+ $q .= (array_values($row)[$i] == "NULL" ? "NULL" : "'" . array_values($row)[$i] . "'");
+ if($i+1 < count($row)) $q .= ", ";
+ }
+ $q .= ")";
+ if(mysqli_query($db, $q)) print "Success $q";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+}
+
+elseif($_REQUEST['type'] == "toggle_done"){
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+
+ if(!$id) print "Missing inputs<br>";
+ else{
+ $id = mysqli_real_escape_string($db, $id);
+ $q = "UPDATE Assignments SET Done = (Done + 1) % 2 WHERE id = '$id'";
+ if(mysqli_query($db, $q)) print "Success";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+}
+
+elseif($_REQUEST['type'] == "delete_assignment"){
+ $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id'];
+ if(!$id) print "Missing inputs<br>";
+ else{
+ $id = mysqli_real_escape_string($db, $id);
+ $q = "UPDATE Assignments Set Hidden = '1' WHERE id = '$id'";
+ if(mysqli_query($db, $q)) print "Success";
+ else print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+}
+
+else print "Errors: Unknown headers " . print_r($_REQUEST,1);
+
+?>
diff --git a/hw_schedule2.css b/hw_schedule2.css
new file mode 100644
index 0000000..d6c388d
--- /dev/null
+++ b/hw_schedule2.css
@@ -0,0 +1,128 @@
+/*
+#add_class_dialog {
+ background-color: lightgray;
+ margin: auto;
+ margin-top: 10px;
+ width: 400px;
+}
+
+#add_class_dialog>div {
+ display: flex;
+ justify-content: space-between;
+ padding: 5px;
+}
+*/
+
+#bg {
+ z-index: -1;
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ opacity: 1;
+ background-size: contain;
+ background-repeat: no-repeat;
+ background-position: 50% 0;
+ animation:2s hide forwards;
+ animation-delay: .1s;
+}
+@keyframes hide{ 0%{opacity:1;} 100%{opacity:.1;}}
+
+#hw_div {
+ margin-top: 30px;
+ margin-bottom: 30px;
+ display: flex;
+}
+
+#notes_link{
+ text-align: right;
+ font-size: 12px;
+}
+
+.add_dialog {
+ background-color: lightgray;
+ margin: auto;
+ margin-top: 10px;
+ width: 400px;
+}
+
+.add_dialog>div {
+ display: flex;
+ justify-content: space-between;
+ padding: 5px;
+}
+
+.banner {
+ font-size: 24px;
+ margin: 15px;
+ font-weight: bold;
+ text-decoration: underline;
+}
+
+.banner_box {
+ text-align: center;
+}
+
+.cancel {
+ background-color: pink;
+}
+
+.cancel:hover {
+ background-color: red;
+}
+
+.column {
+ width: 50%;
+ padding-left: 5%;
+ padding-right: 5%;
+}
+
+.container:hover button {
+ display: inline;
+}
+
+
+.course {
+ text-decoration: underline;
+ font-weight: bold;
+ margin-right: 15px;
+}
+
+.entries {
+ font-size: 18px;
+ list-style: square;
+ margin-right: 15px;
+}
+
+.entry_box {
+ margin-bottom: 15px;
+}
+
+a{
+ color: inherit;
+}
+
+button.add {
+ background-color: skyblue;
+}
+
+button.add,button.edit,button.delete,button.mark_done {
+ display: none;
+ margin-left: 2px;
+ margin-right: 2px;
+}
+
+/*
+button.add:hover,button.edit:hover,button.delete:hover,button.mark_done:hover {
+ font-weight: bold;
+}
+*/
+
+button.delete {
+ background-color: red;
+}
+
+button.edit_assignment {
+ margin-left: 10px;
+}
diff --git a/hw_schedule2.js b/hw_schedule2.js
new file mode 100644
index 0000000..5bc7a96
--- /dev/null
+++ b/hw_schedule2.js
@@ -0,0 +1,513 @@
+//set background image
+const bg_image = ["rubber_duck_PNG33.png", "dice.png"];
+document.getElementById("bg").style.backgroundImage = "url(" + bg_image[Math.floor(Math.random() * bg_image.length)] + ")";
+
+//Function to get date
+function get_day(d){
+ if(!d) d = new Date();
+ const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+ const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
+ let output = days[d.getDay()] + ", " + months[d.getMonth()] + " " + d.getDate();
+ switch(d.getDate()){
+ case 1:
+ output += "st";
+ break;
+ case 2:
+ output += "nd";
+ break;
+ case 3:
+ output += "rd";
+ break;
+ default:
+ output += "th";
+ }
+
+ return output;
+}
+
+function day_of_year(date){
+ //get milliseconds
+ console.log(date);
+ console.log(Math.floor(date.getTime() / 1000 / 60 / 60 / 24));
+ return Math.round(date.getTime() / 1000 / 60 / 60 / 24);
+}
+
+function hide_dialog(selector){
+ const obj = document.querySelector(selector);
+ if(obj) obj.innerHTML = "";
+ else console.log("hide_dialog: bad selector: \"" + selector + "\"");
+}
+
+document.querySelector(".banner").innerText = get_day();
+
+function clear_all(){
+ for(const element of document.querySelectorAll(".column")){
+ element.innerHTML = "";
+ }
+}
+
+/* Load from database */
+
+function draw_class(entry){
+ if(!(entry instanceof Array)){
+ console.log(entry);
+ console.log("Error loading classes");
+ return;
+ }
+
+ const id = entry[0];
+ const description = entry[1];
+ const code = entry[2];
+ const column_bool = entry[3];
+ const url = entry[4];
+
+ const columns = document.querySelectorAll(".column");
+ const insert_column = columns[column_bool];
+
+ //class_html
+ /*
+ <div class="container course_box">
+ <span class="course"></span>
+ <button class="add add_assignment">add assignment</button>
+ <button class="edit edit_class">edit</button>
+ <button class="delete delete_class">delete</button>
+ </div>
+ */
+
+ let class_html = "<div class='container course_box' id='course_" + id + "_container'>" +
+ "<span class='course' id='course_" + id + "'>";
+ if(url != "") class_html += "<a href='" + url + "'>";
+ class_html += code;
+ if(url != "") class_html += "</a>";
+ class_html += "</span>" +
+ "<button class=\"add add_assignment\" onclick=\"draw_add_assignment(" + id + ")\">add assignment</button>" +
+ "<button class=\"edit edit_class\" onclick=\"draw_edit_class(" + id + ")\">edit</button>" +
+ "<button class=\"delete delete_class\" onclick=\"delete_class(" + id + ")\">delete</button>" +
+ "</div>" +
+ "<div class=\"add_assignment_box\" id=\"add_assignment_box_" + id + "\"></div>" + //box to draw add_assignment dialog in
+ "<ul class=\"assignment_list\" id=\"assignment_list_" + id + "\"></ul>"; //ul box to draw assignments in
+
+ insert_column.innerHTML += class_html;
+}
+
+function draw_assignment(entry){
+ if(!(entry instanceof Array)){
+ console.log(entry);
+ console.log("Error loading assignment");
+ return;
+ }
+
+ let id = entry[0];
+ let class_id = entry[1];
+ let due_date = entry[2];
+ let due_date_alt = entry[3];
+ let desc = entry[4];
+ let color = entry[5];
+ let highlight = entry[6];
+ let done = entry[7];
+ let link = entry[8];
+
+ //custom element handling (based on php)
+ /*
+ if($due_date != "ASAP" && $due_date != ""){
+ $due_date_pieces = explode(" ", $due_date);
+ $due_date_num = date('z', mktime(0, 0, 0, substr($due_date_pieces[1], 0, 2), substr($due_date_pieces[1], 3, 2), date('Y')));
+
+ if($due_date_num - date('z') <= 1 && $color != "black" && $color != "brown") $color = "red";
+ if((!$done && ($due_date_num - date('z') <= 0)) || ($highlight == "orange" && ($due_date_num - date('z') <= 7))) $highlight = "yellow";
+ }
+ if($highlight != "none" && $color == "gray") $color = "black";
+ if($done){
+ $color = "green";
+ $highlight = "none";
+ }
+ */
+
+ if(!highlight) highlight = "none";
+ let due_date_pieces;
+ let current_date;
+ let due_date_object;
+ if(due_date){
+ due_date_pieces = due_date.split("-");
+ current_date = new Date();
+ due_date_object = new Date(due_date_pieces[0], due_date_pieces[1]-1, due_date_pieces[2]);
+ if(day_of_year(due_date_object) - day_of_year(current_date) <= 0 && color != "black" && color != "brown") color = "red";
+ if((done == 0 && (day_of_year(due_date_object) - day_of_year(current_date) <= -1)) || (highlight == "orange" && (day_of_year(due_date_object) - day_of_year(current_date) <= 6))) highlight = "yellow";
+ }
+ if(highlight != "none" && color == "gray") color = "black";
+ if(done == 1){
+ color = "green";
+ highlight = "none";
+ }
+
+ const box = document.querySelector("#assignment_list_" + class_id);
+
+ /* reference:
+ print "<li class=\"entries\" style=\"color: $color;" . (!$done && $color != 'black' && $highlight != 'none' ? "font-weight: bold" : "") . "\">";
+ if($done) print "<span style=\"color: green; font-weight: bold\"> &#10004;</span>"; // "&#9989;";
+ print "<span style=\"background-color: $highlight; text-decoration: " . ($done ? "line-through" : "none") . "\">";
+ print ($due_date != "" ? "$due_date: " : "") . "<span style=\"background-color: $highlight\">$desc</span>";
+ print "</span>";
+ print "</li>";
+ */
+
+ const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
+
+ let assignment_html = "<div class='container entry_box' id='entry_box_" + id + "'><li class='entries' id='entry_" + id + "' style='color: " + color + ";";
+ if(done == 0 && color != "black" && highlight != "none") assignment_html += "font-weight: bold";
+ assignment_html += "'>";
+ if(done == 1) assignment_html += "<span style='color: green; font-weight: bold'> &#10004;</span>";
+ assignment_html += "<span style='background-color: " + highlight + "; text-decoration: ";
+ if(done == 1) assignment_html += "line-through";
+ else assignment_html += "none";
+ assignment_html += "'>";
+ if(due_date){
+ assignment_html += days[due_date_object.getDay()] + ", ";
+ if(due_date_object.getMonth()+1 < 10) assignment_html += "0";
+ assignment_html += due_date_object.getMonth()+1 + "/";
+ if(due_date_object.getDate()+1 < 10) assignment_html += "0";
+ assignment_html += due_date_object.getDate()
+ }
+ else assignment_html += due_date_alt;
+ assignment_html += ": <span style='background-color: " + highlight + "'>";
+ if(link) assignment_html += "<a href='" + link + "'>";
+ assignment_html += desc;
+ if(link) assignment_html += "</a>";
+ assignment_html += "</span></span>" +
+ "<button class=\"edit edit_assignment\" onclick=\"draw_edit_assignment(" + class_id + ", " + id + ")\">edit</button>" +
+ "<button class=\"add add_assignment\" onclick=\"clone_assignment(" + id + ")\">clone</button>" +
+ "<button class=\"mark_done\" onclick=\"toggle_done(" + id + ")\" style=\"background-color: " + (done == 1 ? "hotpink" : "lightgreen") + "\">" + (done == 1 ? "not done" : "done") + "</button>" +
+ "<button class=\"delete delete_assignment\" onclick=\"delete_assignment(" + id + ")\">delete</button>" +
+ "</div></li>" +
+ "<div class=\"add_assignment_box\" id=\"edit_assignment_box_" + id + "\"></div></div>"; //box to draw add_assignment dialog in
+
+ box.innerHTML += assignment_html;
+}
+
+function load_data(mode){
+ let type;
+ if(mode == "classes") type = "load_classes";
+ else if(mode == "assignments") type = "load_assignments";
+ else{
+ console.log("Error: Unknown data to load. Only \"classes\" and \"assignments\" are supported arguments");
+ return;
+ }
+
+ let url = "backend/hw_schedule2_backend.php";
+ let data = "type=" + type;
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ console.log(JSON.parse(this.response));
+ for(const entry of JSON.parse(this.response)){
+ if(mode == "classes") draw_class(entry);
+ else if(mode == "assignments") draw_assignment(entry);
+ }
+ }
+ xhttp.send(data);
+}
+
+/* add a new class */
+
+//show dialog
+function draw_add_class(id){
+ let box;
+ if(!id) box = document.querySelector("#add_class_box");
+ else box = document.querySelector("#add_assignment_box_" + id);
+ const add_class_html = document.querySelector("#add_class_html").innerHTML;
+ const buttons = "<input class=\"cancel\" id=\"add_class_cancel\" onclick=\"hide_add_class(" + id + ")\" type=\"button\" value=\"Cancel\">" +
+ "<button class=\"submit\" onclick=\"submit_add_class(" + id + ")\" type=\"button\">Submit</button>";
+
+ box.innerHTML = add_class_html;
+ box.querySelector(".submit_box").innerHTML = buttons;
+}
+
+//hide dialog
+function hide_add_class(id){
+ if(!id) hide_dialog("#add_class_box");
+ else hide_dialog("#add_assignment_box_" + id);
+}
+
+//submit dialog
+function submit_add_class(id){
+ const code = document.querySelector("[name = add_class_id]").value;
+ const name = document.querySelector("[name = add_class_desc]").value;
+ const link = document.querySelector("[name = add_class_link]").value;
+ const location = document.querySelector("[name = add_class_location]").value;
+
+ //check that class ID is not null
+ if(code == ""){
+ alert("Missing Class ID");
+ return;
+ }
+
+ //TODO create array instead
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=save_class" +
+ "&add_class_desc=" + encodeURIComponent(name) +
+ "&add_class_id=" + encodeURIComponent(code) +
+ "&add_class_location=" + encodeURIComponent(location) +
+ "&add_class_link=" + encodeURIComponent(link);
+
+ if(id) data += "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, true);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ if(!id) alert("Successfully added class '" + code + "'");
+ hide_add_class(id);
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+
+}
+
+/* add assignment to class */
+
+//show dialog
+function draw_add_assignment(id, ass_id){
+ let box;
+ if(!ass_id) box = document.querySelector("#add_assignment_box_" + id);
+ else box = document.querySelector("#edit_assignment_box_" + ass_id);
+ const add_assignment_html = document.querySelector("#add_assignment_html").innerHTML;
+ const buttons = "<input class=\"cancel\" onclick=\"hide_add_assignment(" + id + ", " + ass_id + ")\" type=\"button\" value=\"Cancel\">" +
+ "<button class=\"submit\" onclick=\"submit_add_assignment(" + id + ", " + ass_id + ")\" type=\"button\">Submit</button>";
+
+ box.innerHTML = add_assignment_html;
+ box.querySelector(".submit_box").innerHTML = buttons;
+}
+
+//hide dialog
+function hide_add_assignment(id, ass_id){
+ if(!ass_id) hide_dialog("#add_assignment_box_" + id);
+ else hide_dialog("#edit_assignment_box_" + ass_id);
+}
+
+//submit dialog
+function submit_add_assignment(id, ass_id){
+ let box;
+ if(!ass_id) box = document.querySelector("#add_assignment_box_" + id);
+ else box = document.querySelector("#edit_assignment_box_" + ass_id);
+
+ const class_id = id;
+ const due_date = box.querySelector("[name = add_due_date]").value; //formatted YYYY-MM-DD
+ const due_date_alt = box.querySelector("[name = add_due_date_alt]").value;
+ const desc = box.querySelector("[name = add_desc]").value;
+ const color = box.querySelector("[name = add_color]").value;
+ const highlight = box.querySelector("[name = add_highlight]").value;
+ const link = box.querySelector("[name = add_link]").value;
+
+ //check that desc is not null
+ if(desc == ""){
+ alert("Missing Assignment Description/Title");
+ return;
+ }
+
+ let url = "backend/hw_schedule2_backend.php";
+
+ //TODO create array instead
+ let data = "type=save_assignment" +
+ "&add_class_id=" + encodeURIComponent(class_id) +
+ "&add_due_date=" + encodeURIComponent(due_date) +
+ "&add_due_date_alt=" + encodeURIComponent(due_date_alt) +
+ "&add_desc=" + encodeURIComponent(desc) +
+ "&add_color=" + encodeURIComponent(color) +
+ "&add_highlight=" + encodeURIComponent(highlight) +
+ "&add_link=" + encodeURIComponent(link);
+
+ if(ass_id) data += "&id=" + encodeURIComponent(ass_id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, true);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ if(!id) alert("Successfully added assignment '" + desc + "'");
+ hide_add_assignment(id);
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* edit a class */
+function draw_edit_class(id){
+ draw_add_class(id);
+
+ //load values
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=load_classes" +
+ "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ const response = JSON.parse(this.response);
+ if(response[0] instanceof Array){
+ document.querySelector("[name = add_class_id]").value = response[0][2];
+ document.querySelector("[name = add_class_desc]").value = response[0][1];
+ document.querySelector("[name = add_class_link]").value = response[0][4];
+ document.querySelector("[name = add_class_location]").value = (response[0][3] == "0" ? "left" : "right");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* delete a class */
+function delete_class(id){
+ let prompt = confirm("Are you sure you want to delete this class?");
+ if(!prompt) return;
+
+ //note that classes are not deleted, just set to hidden
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=delete_class" +
+ "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* edit an assignment */
+function draw_edit_assignment(id, ass_id){
+ draw_add_assignment(id, ass_id);
+
+ //load values
+ const box = document.querySelector("#edit_assignment_box_" + ass_id);
+
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=load_assignments" +
+ "&id=" + encodeURIComponent(ass_id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ console.log(this.response);
+ const response = JSON.parse(this.response);
+ if(response[0] instanceof Array){
+ box.querySelector("[name = add_due_date]").value = response[0][2];
+ box.querySelector("[name = add_due_date_alt]").value = response[0][3];
+ box.querySelector("[name = add_desc]").value = response[0][4];
+ box.querySelector("[name = add_color]").value = response[0][5];
+ box.querySelector("[name = add_highlight]").value = response[0][6];
+ box.querySelector("[name = add_link]").value = response[0][8];
+ }
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* clone an assignment */
+function clone_assignment(id){
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=clone_assignment" +
+ "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* toggle assignment complete */
+function toggle_done(id){
+ const box = document.querySelector("#edit_assignment_box_" + id);
+
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=toggle_done" +
+ "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+/* delete an assignment */
+function delete_assignment(id){
+ let prompt = confirm("Are you sure you want to delete this assignment?");
+ if(!prompt) return;
+
+ //note that classes are not deleted, just set to hidden
+ let url = "backend/hw_schedule2_backend.php";
+
+ let data = "type=delete_assignment" +
+ "&id=" + encodeURIComponent(id);
+
+ console.log(data);
+ let xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, false);
+ xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhttp.onload = function(){
+ if(this.response.indexOf("Success") > -1){
+ clear_all();
+ load_data("classes");
+ load_data("assignments");
+ }
+ console.log(this.response);
+ };
+ xhttp.send(data);
+ return false;
+}
+
+load_data("classes");
+load_data("assignments");
diff --git a/hw_schedule2.php b/hw_schedule2.php
new file mode 100644
index 0000000..e333cf1
--- /dev/null
+++ b/hw_schedule2.php
@@ -0,0 +1,208 @@
+<?php
+ini_set('display_errors', 1);
+error_reporting(-1);
+
+/*
+//Restrict Access to Outside IPs
+$allowedip = array("172.114.94.2", "129.210.115.225", "129.210.115.226", "129.210.115.227", "129.210.115.228", "129.210.115.229", "129.210.115.8", "129.210.115.230");
+$allowed = false;
+$ip = $_SERVER['REMOTE_ADDR'];
+for($i = 0; $i < sizeof($allowedip); ++$i){
+ if($allowedip[$i] == $ip){
+ $allowed = true;
+ break;
+ }
+}
+
+if(!$allowed) exit("$ip: Access Denied");
+*/
+
+date_default_timezone_set("America/Los_Angeles");
+
+/*
+$db = mysqli_connect("localhost", "louie", "louie2000", "louie_school");
+if(!$db) die("Failed to connect to database: " . mysqli_connect_error());
+
+if(isset($_REQUEST['add_class_desc'])){
+ print htmlspecialchars( $_REQUEST['add_class_desc'] );
+
+ print "Will add<br>";
+
+ $name = empty($_REQUEST['add_class_desc']) ? "" : $_REQUEST['add_class_desc'];
+ $code = empty($_REQUEST['add_class_id']) ? "" : $_REQUEST['add_class_id'];
+ $location = empty($_REQUEST['add_class_location']) ? "left" : $_REQUEST['add_class_location'];
+ $link = empty($_REQUEST['add_class_link']) ? "" : $_REQUEST['add_class_link'];
+
+ if(!$code) print "Missing inputs<br>";
+ else{
+ $location = $location == "left" ? 0 : 1;
+
+ $name = mysqli_real_escape_string($db, $name);
+ $code = mysqli_real_escape_string($db, $code);
+ //$location = mysqli_real_escape_string($db, $location);
+ $link = mysqli_real_escape_string($db, $link);
+ $q = "INSERT INTO Classes (Name, Code, Location, Link) VALUES ('$name', '$code', '$location', '$link')";
+ if(!mysqli_query($db, $q)) print "$q<br>Insertion Failed: " . mysqli_error($db) . "<br>";
+ }
+
+}
+ */
+
+$day = date("l, F jS");
+$bg_image_arr = array("rubber_duck_PNG33.png",
+"dice.png");
+
+function entry($due_date, $desc, $color, $highlight, $done){
+ if($due_date != "ASAP" && $due_date != ""){
+ $due_date_pieces = explode(" ", $due_date);
+ $due_date_num = date('z', mktime(0, 0, 0, substr($due_date_pieces[1], 0, 2), substr($due_date_pieces[1], 3, 2), date('Y')));
+
+ if($due_date_num - date('z') <= 1 && $color != "black" && $color != "brown") $color = "red";
+ if((!$done && ($due_date_num - date('z') <= 0)) || ($highlight == "orange" && ($due_date_num - date('z') <= 7))) $highlight = "yellow";
+ }
+ if($highlight != "none" && $color == "gray") $color = "black";
+ if($done){
+ $color = "green";
+ $highlight = "none";
+ }
+
+ print "<li class=\"entries\" style=\"color: $color;" . (!$done && $color != 'black' && $highlight != 'none' ? "font-weight: bold" : "") . "\">";
+ if($done) print "<span style=\"color: green; font-weight: bold\"> &#10004;</span>"; // "&#9989;";
+ print "<span style=\"background-color: $highlight; text-decoration: " . ($done ? "line-through" : "none") . "\">";
+ print ($due_date != "" ? "$due_date: " : "") . "<span style=\"background-color: $highlight\">$desc</span>";
+ print "</span>";
+ print "</li>";
+}
+
+/* Conceptual **
+
+class Entry{
+ public static $num_hw = 0;
+ public static $hw_strings = [];
+ //$hw_string[0] = HW description
+ //$hw_string[1] = HW due Date (0 to 365)
+
+ function add_hw(){
+ $hw_string[] = readline("What is the HW?\n");
+ $days_til_due = readline("In how many days is the HW due?\n");
+ $hw_strings[] = $days_til_due + date('z');
+ $num_hw++;
+ }
+}
+
+function list_hw($entry){
+ if(!$entry->num_hw){
+ print "The test is have work";
+ return;
+ }
+ else{
+ print "<ul> class=\"entries\"";
+ for($i = 0; $i < $num_hw; $i++){
+ print "<li> WIP </li>";
+ }
+ print "</ul>";
+ }
+
+ return;
+}
+
+$ENGL2A = new Entry();
+$MATH13 = new Entry();
+$COEN11 = new Entry();
+$PHYS31 = new Entry();
+$COEN11L = new Entry();
+$ENGR1 = new Entry();
+$PHYS31L = new Entry();
+
+$ENGL2A->add_hw();
+print "TEST: num_hw = $ENGL2A->num_hw";
+
+ */
+
+?>
+
+<html>
+ <head>
+ <title>Daily Homework Schedule</title>
+ <link rel="stylesheet" href="hw_schedule2.css">
+ <script defer src="hw_schedule2.js"></script>
+ </head>
+
+ <body>
+ <div id=bg></div>
+ <div id=notes_link><a href="notes/notes_home.php">SCU Class Notes</a></div>
+ <div class="container banner_box">
+ <span class="banner"></span>
+ <button id="add_class" class="add" onclick="draw_add_class()">add class</button>
+ <div id="add_class_box">
+ </div>
+ </div>
+ <div id="hw_div">
+ <div class="column" id="column_left">
+ </div>
+ <div class="column" id="column_right">
+ </div>
+
+ </div>
+
+ <!-- templates -->
+ <template id='add_class_html'>
+ <div class="add_dialog" id="add_class_dialog">
+ <div>
+ <label for="add_class_id">Class ID:</label>
+ <input name="add_class_id"/>
+ </div>
+ <div>
+ <label for="add_class_desc">Description/Title:</label>
+ <input name="add_class_desc"/>
+ </div>
+ <div>
+ <label for="add_class_link">Class URL:</label>
+ <input type="url" name="add_class_link"/>
+ </div>
+ <div>
+ <label for="add_class_location">Column:</label>
+ <select name="add_class_location">
+ <option value="left">left</option>
+ <option value="right">right</option>
+ </select>
+ </div>
+ <div class="submit_box">
+ <!-- Add cancel and submit buttons in javascript -->
+ </div>
+ </div>
+ </template>
+
+ <template id='add_assignment_html'>
+ <div class="add_dialog">
+ <div>
+ <label for="add_due_date">Due Date:</label>
+ <input name="add_due_date" type="date"/>
+ </div>
+ <div>
+ <label for="add_due_date_alt">Alt Due Date:</label>
+ <input name="add_due_date_alt"/>
+ </div>
+ <div>
+ <label for="add_desc">Description/Title:</label>
+ <input name="add_desc"/>
+ </div>
+ <div>
+ <label for="add_color">Color:</label>
+ <input name="add_color"/>
+ </div>
+ <div>
+ <label for="add_highlight">Highlight:</label>
+ <input name="add_highlight"/>
+ </div>
+ <div>
+ <label for="add_link">Assignment URL:</label>
+ <input type="url" name="add_link"/>
+ </div>
+ <div class="submit_box">
+ <!-- Add cancel and submit buttons in javascript -->
+ </div>
+ </div>
+ </template>
+ </body>
+</html>