-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
<?php | ||
include_once(dirname(__FILE__) . "/database.php"); | ||
|
||
session_start(); | ||
|
||
ini_set('display_errors', '1'); | ||
ini_set('display_startup_errors', '1'); | ||
error_reporting(E_ALL); | ||
|
||
$teachingQualityRating = $_GET["teachingQuality"]; | ||
$kindnessRating = $_GET["kindness"]; | ||
$authorityRating = $_GET["authority"]; | ||
$humorRating = $_GET["humor"]; | ||
|
||
$teacherId = $_GET["teacherId"]; | ||
include_once(dirname(__FILE__) . "/database.php"); | ||
|
||
// if($_SESSION["alreadyVoted".$teacherId] == true){ | ||
// echo '<script>alert("Vous ne pouvez pas voter deux fois sur le même professeur!");</script>'; | ||
$db = new Database; | ||
$teachingQualityRating = $db->escapeStrings($_POST["teachingQuality"]); | ||
$kindnessRating = $db->escapeStrings($_POST["kindness"]); | ||
$authorityRating = $db->escapeStrings($_POST["authority"]); | ||
$humorRating = $db->escapeStrings($_POST["humor"]); | ||
|
||
// header("location: index.php"); | ||
// exit(); | ||
// } | ||
$teacherId = $db->escapeStrings($_POST["teacherId"]); | ||
|
||
if($teachingQualityRating > 10 || $teachingQualityRating <= 0 || $kindnessRating > 10 || $kindnessRating <= 0 || $authorityRating > 10 || $authorityRating <= 0 || $humorRating > 10 || $humorRating <= 0) { | ||
if($teachingQualityRating > 10 || $teachingQualityRating <= 0 || | ||
$kindnessRating > 10 || $kindnessRating <= 0 || | ||
$authorityRating > 10 || $authorityRating <= 0 || | ||
$humorRating > 10 || $humorRating <= 0) { | ||
echo "invalid values"; | ||
exit(); | ||
} | ||
$db = new Database; | ||
$db -> query("INSERT INTO cescoleaks_votes (teacher_ID, teaching_quality, kindness, authority, humor) VALUES | ||
('$teacherId', '$teachingQualityRating', '$kindnessRating', '$authorityRating', '$humorRating')"); | ||
|
||
header("location: index.php"); | ||
$db->query("INSERT INTO cescoleaks_votes (teacher_ID, teaching_quality, kindness, authority, humor) VALUES | ||
('$teacherId', '$teachingQualityRating', '$kindnessRating', '$authorityRating', '$humorRating')"); | ||
|
||
exit(); // Because we never know... | ||
?> | ||
exit(); // we never know | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
function openPopup(id) { | ||
const popup = document.getElementById(id); | ||
popup.classList.add("show"); | ||
localStorage.setItem("openPopupId", id); | ||
const popup = document.getElementById(id); | ||
popup.classList.add("show"); | ||
// localStorage.setItem("openPopupId", id); | ||
} | ||
|
||
function openRatingPopup(popupId, profId) { | ||
openPopup(popupId); | ||
|
||
const voteRatingButton = document.getElementById("voteRatingButton"); | ||
voteRatingButton.addEventListener("click", () => { | ||
sendVotes( | ||
profId, | ||
parseFloat(document.getElementById("ratingTeachingQuality").value), | ||
parseFloat(document.getElementById("ratingKindness").value), | ||
parseFloat(document.getElementById("ratingAuthority").value), | ||
parseFloat(document.getElementById("ratingHumor").value) | ||
).then(() => { | ||
closePopup(popupId); | ||
}); | ||
}); | ||
} | ||
|
||
function closePopup(id) { | ||
const popup = document.getElementById(id); | ||
popup.classList.add("closing"); | ||
setTimeout(() => { | ||
popup.classList.remove("show", "closing"); | ||
}, 250); | ||
localStorage.removeItem("openPopupId"); | ||
const popup = document.getElementById(id); | ||
popup.classList.add("closing"); | ||
setTimeout(() => { | ||
popup.classList.remove("show", "closing"); | ||
}, 250); | ||
// localStorage.removeItem("openPopupId"); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
const openPopupId = localStorage.getItem("openPopupId"); | ||
if (openPopupId) { | ||
openPopup(openPopupId); | ||
} | ||
}); | ||
// document.addEventListener("DOMContentLoaded", function () { | ||
// const openPopupId = localStorage.getItem("openPopupId"); | ||
// if (openPopupId) { | ||
// openPopup(openPopupId); | ||
// } | ||
// }); | ||
|
||
document.addEventListener("keydown", function (event) { | ||
if (event.key === "Escape") { | ||
const popups = document.querySelectorAll(".show"); | ||
popups.forEach(function (popup) { | ||
closePopup(popup.id); | ||
}); | ||
} | ||
if (event.key === "Escape") { | ||
const popups = document.querySelectorAll(".show"); | ||
popups.forEach(function (popup) { | ||
closePopup(popup.id); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
async function sendVotes(profId, teachingQuality, kindness, authority, humor) { | ||
const formData = new FormData(); | ||
|
||
let response = await fetch("api/newRating.php", { | ||
method: "POST", | ||
body: objectToFormData({ | ||
teacherId: profId, | ||
teachingQuality: teachingQuality, | ||
kindness: kindness, | ||
authority: authority, | ||
humor: humor, | ||
}), | ||
}); | ||
|
||
console.log(response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function objectToFormData(obj) { | ||
const formData = new FormData(); | ||
for (const key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
formData.append(key, obj[key]); | ||
} | ||
} | ||
return formData; | ||
} |