From 7ec4b054da422b5cee4e6d76b6fb7d7e90cf29a5 Mon Sep 17 00:00:00 2001 From: louie Date: Mon, 11 Apr 2022 18:45:55 -0700 Subject: First commit --- backend/hw_schedule2_backend.php | 176 ++++++++++++++ hw_schedule2.css | 128 ++++++++++ hw_schedule2.js | 513 +++++++++++++++++++++++++++++++++++++++ hw_schedule2.php | 208 ++++++++++++++++ 4 files changed, 1025 insertions(+) create mode 100644 backend/hw_schedule2_backend.php create mode 100644 hw_schedule2.css create mode 100644 hw_schedule2.js create mode 100644 hw_schedule2.php 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 @@ +"; + + $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
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + } + +} + +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
Insertion Failed: " . mysqli_error($db) . "
"; +} + +elseif($_REQUEST['type'] == "delete_class"){ + $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id']; + if(!$id) print "Missing inputs
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + + //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
Insertion Failed: " . mysqli_error($db) . "
"; + } +} + + +elseif($_REQUEST['type'] == "save_assignment"){ + print htmlspecialchars( $_REQUEST['add_desc'] ); + + print "Will add
"; + + $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
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + } +} + +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
Insertion Failed: " . mysqli_error($db) . "
"; +} + +elseif($_REQUEST['type'] == "clone_assignment"){ + $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id']; + + if(!$id) print "Missing inputs
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + } +} + +elseif($_REQUEST['type'] == "toggle_done"){ + $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id']; + + if(!$id) print "Missing inputs
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + } +} + +elseif($_REQUEST['type'] == "delete_assignment"){ + $id = empty($_REQUEST['id']) ? "" : $_REQUEST['id']; + if(!$id) print "Missing inputs
"; + 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
Insertion Failed: " . mysqli_error($db) . "
"; + } +} + +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 + /* +
+ + + + +
+ */ + + let class_html = "
" + + ""; + if(url != "") class_html += ""; + class_html += code; + if(url != "") class_html += ""; + class_html += "" + + "" + + "" + + "" + + "
" + + "
" + //box to draw add_assignment dialog in + ""; //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 "
  • "; + if($done) print ""; // "✅"; + print ""; + print ($due_date != "" ? "$due_date: " : "") . "$desc"; + print ""; + print "
  • "; + */ + + const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + + let assignment_html = "
  • "; + if(done == 1) assignment_html += ""; + 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 += ": "; + if(link) assignment_html += ""; + assignment_html += desc; + if(link) assignment_html += ""; + assignment_html += "" + + "" + + "" + + "" + + "" + + "
  • " + + "
    "; //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 = "" + + ""; + + 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 = "" + + ""; + + 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 @@ +"; + + $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
    "; + 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
    Insertion Failed: " . mysqli_error($db) . "
    "; + } + +} + */ + +$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 "
  • "; + if($done) print ""; // "✅"; + print ""; + print ($due_date != "" ? "$due_date: " : "") . "$desc"; + print ""; + print "
  • "; +} + +/* 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 ""; + } + + 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"; + + */ + +?> + + + + Daily Homework Schedule + + + + + +
    + + +
    +
    +
    +
    +
    + +
    + + + + + + + -- cgit