Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from noten-app/#49-School-year-null-on-login
Browse files Browse the repository at this point in the history
🐛 Unify session var name
  • Loading branch information
CuzImBisonratte authored Dec 1, 2023
2 parents 10fcd42 + eb6fa3b commit 1a94d2b
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion homework/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

// Add subject to DB
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["homework"] . ' (user_id, entry_id, subject, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssssss', $_SESSION["user_id"], $entryId, $subject, $date_given, $date_due, $task, $type, $_SESSION["setting_years"]);
$stmt->bind_param('ssssssss', $_SESSION["user_id"], $entryId, $subject, $date_given, $date_due, $task, $type, $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();
exit("success");
Expand Down
2 changes: 1 addition & 1 deletion homework/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// Get all subjects
$subjectlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($subject_name, $subject_color, $subject_id, $subject_last_used, $subject_grade_average);
while ($stmt->fetch()) {
Expand Down
4 changes: 2 additions & 2 deletions homework/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

// Get all tasks
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["homework"] . " WHERE user_id = ? AND year = ?" . $showall_text)) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$homework = $result->fetch_all(MYSQLI_ASSOC);
}

// Get all subjects
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? and year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$subjects = $result->fetch_all(MYSQLI_ASSOC);
Expand Down
12 changes: 6 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Count homework status
// Count for status 0,1 or 2 seperately
if ($stmt = $con->prepare("SELECT status FROM " . $config["db"]["tables"]["homework"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($status);
$status_list = [];
Expand All @@ -44,7 +44,7 @@
if (date("N") == 5 && date("H") >= 15) $tomorrow = date("Y-m-d", strtotime("+3 day"));
else if (date("N") == 6) $tomorrow = date("Y-m-d", strtotime("+2 day"));
else $tomorrow = date("Y-m-d", strtotime("+1 day"));
$stmt->bind_param("sss", $_SESSION["user_id"], $tomorrow, $_SESSION["setting_years"]);
$stmt->bind_param("sss", $_SESSION["user_id"], $tomorrow, $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$homework = $result->fetch_all(MYSQLI_ASSOC);
Expand All @@ -53,14 +53,14 @@

// Get all subjects
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$subjects = $result->fetch_all(MYSQLI_ASSOC);
}
// Count grades
if ($stmt = $con->prepare("SELECT COUNT(*) FROM " . $config["db"]["tables"]["grades"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($num_of_grades);
$stmt->fetch();
Expand All @@ -69,7 +69,7 @@

// Get last inserted grade
if ($stmt = $con->prepare("SELECT grade FROM " . $config["db"]["tables"]["grades"] . " WHERE user_id = ? AND year = ? ORDER BY id DESC LIMIT 1")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($last_grade);
$stmt->fetch();
Expand All @@ -78,7 +78,7 @@

// Calculate average
if ($stmt = $con->prepare("SELECT average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($average);
$average_list = [];
Expand Down
4 changes: 2 additions & 2 deletions settings/add-year/add-year.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
$sql_string .= ")";
}
if ($stmt = $con->prepare($sql_string)) {
$stmt->bind_param($sql_types, $_SESSION["setting_years"], $_SESSION["user_id"], ...$transfer_subjects);
$stmt->bind_param($sql_types, $_SESSION["setting_year"], $_SESSION["user_id"], ...$transfer_subjects);
$stmt->execute();
$result = $stmt->get_result();
$subjects = $result->fetch_all(MYSQLI_ASSOC);
Expand Down Expand Up @@ -94,6 +94,6 @@
}

// Set as current year
$_SESSION["setting_years"] = $year_id;
$_SESSION["setting_year"] = $year_id;

exit("success");
6 changes: 3 additions & 3 deletions settings/add-year/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

// Get subjects
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$subjects = $result->fetch_all(MYSQLI_ASSOC);
Expand Down Expand Up @@ -80,7 +80,7 @@
foreach ($school_years as $year) {
echo '<div class="dropdown_container container_item"';
echo 'onclick="loadYear(\'' . $year["id"] . '\');"';
if ($_SESSION["setting_years"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
if ($_SESSION["setting_year"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
echo '><div class="dropdown_container-name">';
echo "<span>" . htmlspecialchars($year["name"]) . "</span>";
echo '</div></div>';
Expand All @@ -92,7 +92,7 @@
<div class="group_container" id="current-year" onclick="open_overlay('overlay_schoolyears');">
<div class="current-year">
<span id="current-year-title">Current School Year</span><br>
<span id="current-year-name"><?php foreach ($school_years as $year) if ($_SESSION["setting_years"] == $year["id"]) echo htmlspecialchars($year["name"]); ?></span>
<span id="current-year-name"><?php foreach ($school_years as $year) if ($_SESSION["setting_year"] == $year["id"]) echo htmlspecialchars($year["name"]); ?></span>
</div>
<div class="calendar-icon">
<i class="fas fa-calendar-day"></i>
Expand Down
4 changes: 2 additions & 2 deletions settings/export_grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// Get all subjects
$subjectlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ? ORDER BY average ASC")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($subject_name, $subject_color, $subject_id, $subject_last_used, $subject_grade_average);
while ($stmt->fetch()) {
Expand All @@ -38,7 +38,7 @@

// Get year title
if ($stmt = $con->prepare("SELECT name FROM " . $config["db"]["tables"]["accounts"] . " WHERE id = ?")) {
$stmt->bind_param("s", $_SESSION["setting_years"]);
$stmt->bind_param("s", $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($year_name);
$stmt->fetch();
Expand Down
2 changes: 1 addition & 1 deletion settings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
foreach ($school_years as $year) {
echo '<div class="dropdown_container container_item"';
echo 'onclick="loadYear(\'' . $year["id"] . '\');"';
if ($_SESSION["setting_years"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
if ($_SESSION["setting_year"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
echo '><div class="dropdown_container-name">';
echo "<span>" . htmlspecialchars($year["name"]) . "</span>";
echo '</div></div>';
Expand Down
8 changes: 4 additions & 4 deletions settings/manage-year/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@

// Delete all grades
if ($stmt = $con->prepare("DELETE FROM " . $config["db"]["tables"]["grades"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();
}

// Delete all subjects
if ($stmt = $con->prepare("DELETE FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();
}

// Delete homework
if ($stmt = $con->prepare("DELETE FROM " . $config["db"]["tables"]["homework"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();
}

// Delete year
if ($stmt = $con->prepare("DELETE FROM " . $config["db"]["tables"]["years"] . " WHERE id = ? AND owner = ?")) {
$stmt->bind_param("ss", $_SESSION["setting_years"], $_SESSION["user_id"]);
$stmt->bind_param("ss", $_SESSION["setting_year"], $_SESSION["user_id"]);
$stmt->execute();
$stmt->close();
}
Expand Down
6 changes: 3 additions & 3 deletions settings/manage-year/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
foreach ($school_years as $year) {
echo '<div class="dropdown_container container_item"';
echo 'onclick="loadYear(\'' . $year["id"] . '\');"';
if ($_SESSION["setting_years"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
if ($_SESSION["setting_year"] == $year["id"]) echo 'style="background-color: var(--background3-color);"';
echo '><div class="dropdown_container-name">';
echo "<span>" . htmlspecialchars($year["name"]) . "</span>";
echo '</div></div>';
Expand All @@ -84,7 +84,7 @@
<div class="group_container" id="current-year" onclick="open_overlay('overlay_schoolyears');">
<div class="current-year">
<span id="current-year-title">Current School Year</span><br>
<span id="current-year-name"><?php foreach ($school_years as $year) if ($_SESSION["setting_years"] == $year["id"]) echo htmlspecialchars($year["name"]); ?></span>
<span id="current-year-name"><?php foreach ($school_years as $year) if ($_SESSION["setting_year"] == $year["id"]) echo htmlspecialchars($year["name"]); ?></span>
</div>
<div class="calendar-icon">
<i class="fas fa-calendar-day"></i>
Expand All @@ -103,7 +103,7 @@
</div>
<div id="nextyear" style="display:none;visibility:hidden;" hidden>
<?php
foreach ($school_years as $year) if ($_SESSION["setting_years"] != $year["id"]) {
foreach ($school_years as $year) if ($_SESSION["setting_year"] != $year["id"]) {
echo htmlspecialchars($year["id"]);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions settings/manage-year/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

// Update year
if ($stmt = $con->prepare("UPDATE " . $config["db"]["tables"]["years"] . " SET name = ? WHERE id = ? AND owner = ?")) {
$stmt->bind_param("sss", $_POST["year_name"], $_SESSION["setting_years"], $_SESSION["user_id"]);
$stmt->bind_param("sss", $_POST["year_name"], $_SESSION["setting_year"], $_SESSION["user_id"]);
$stmt->execute();
$stmt->close();
}

// Set new year
$_SESSION["setting_years"] = isset($_POST["next"]) ? $_POST["next"] : "";
$_SESSION["setting_year"] = isset($_POST["next"]) ? $_POST["next"] : "";

exit("success");
4 changes: 2 additions & 2 deletions settings/school_years.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
}

// Set school year
$_SESSION["setting_years"] = $_POST["school_year"];
$_SESSION["setting_year"] = $_POST["school_year"];
if ($stmt = $con->prepare("UPDATE " . $config["db"]["tables"]["accounts"] . " SET school_year = ? WHERE id = ?")) {
$stmt->bind_param("ss", $_POST["school_year"], $_SESSION["user_id"]);
$stmt->execute();

// Redirect
// header("Location: /settings");
echo "UPDATE" . $config["db"]["tables"]["accounts"] . " SET school_year = " . $_SESSION["school_year"] . " WHERE id = " . $_SESSION["user_id"];
echo "UPDATE" . $config["db"]["tables"]["accounts"] . " SET school_year = " . $_SESSION["setting_year"] . " WHERE id = " . $_SESSION["user_id"];
}
2 changes: 1 addition & 1 deletion subjects/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

// Add subject to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["subjects"] . ' (id, name, color, user_id, weight_exam, weight_oral, weight_test, weight_other, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssiisis', $subjectID, $subjectName, $subjectColor, $_SESSION["user_id"], $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $_SESSION["setting_years"]);
$stmt->bind_param('ssssiisis', $subjectID, $subjectName, $subjectColor, $_SESSION["user_id"], $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();
exit(json_encode(array("success" => true, "subjectID" => $subjectID)));
Expand Down
2 changes: 1 addition & 1 deletion subjects/grades/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

// Add grade
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["grades"] . ' (user_id, id, subject, note, type, date, grade, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('ssssssss', $_SESSION["user_id"], $gradeID, $subject_id, $note, $type, $date, $grade_float, $_SESSION["setting_years"]);
$stmt->bind_param('ssssssss', $_SESSION["user_id"], $gradeID, $subject_id, $note, $type, $date, $grade_float, $_SESSION["setting_year"]);
$stmt->execute();
$stmt->close();

Expand Down
2 changes: 1 addition & 1 deletion subjects/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Get all subjects
$subjectlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?" . $sorting_appendix)) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($subject_name, $subject_color, $subject_id, $subject_last_used, $subject_grade_average);
while ($stmt->fetch()) {
Expand Down

0 comments on commit 1a94d2b

Please sign in to comment.