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 #30 from noten-app/22-rename-classes-subjects
Browse files Browse the repository at this point in the history
🎨 22 Rename classes -> Subject
  • Loading branch information
CuzImBisonratte authored Oct 31, 2023
2 parents 31e2c8c + 8edab80 commit 21e408c
Show file tree
Hide file tree
Showing 60 changed files with 433 additions and 418 deletions.
13 changes: 0 additions & 13 deletions classes/edit/delete-class.js

This file was deleted.

8 changes: 4 additions & 4 deletions homework/add/add-class.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const class_selector = document.getElementById('class-selector');
const subject_selector = document.getElementById('subject-selector');
const task_input = document.getElementById('task-input');
const date_input_input = document.getElementById('date_input-input');
const class_add_button = document.querySelector('.class_add');
const subject_add_button = document.querySelector('.subject_add');

class_add_button.addEventListener('click', () => {
subject_add_button.addEventListener('click', () => {
// check if task is empty
if (task_input.value == "") {
task_input.style.border = "1px solid red";
Expand All @@ -15,7 +15,7 @@ class_add_button.addEventListener('click', () => {
url: './add.php',
type: 'POST',
data: {
class: class_selector.value,
subject: subject_selector.value,
type: type,
date_due: date_input_input.value,
task: task_input.value
Expand Down
10 changes: 5 additions & 5 deletions homework/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
if (mysqli_connect_errno()) die("Error with the Database");

// Get input
$class = $_POST["class"];
$subject = $_POST["subject"];
$type = $_POST["type"];
$date_due = $_POST["date_due"];
$task = $_POST["task"];

// Check if necessary input is given
if (!isset($class) || strlen($class) == 0) die("missing-class");
if (!isset($subject) || strlen($subject) == 0) die("missing-subject");
if (!isset($type)) die("missing-type");
if (!($type == "b" || $type == "v" || $type == "w" || $type == "o")) die("invalid-type");
if (!isset($date_due) || strlen($date_due) == 0) die("missing-date_due");
Expand All @@ -38,9 +38,9 @@
// Create given-date
$date_given = date("Y-m-d");

// Add class to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["homework"] . ' (user_id, class, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('sisssss', $_SESSION["user_id"], $class, $date_given, $date_due, $task, $type, $_SESSION["setting_years"]);
// Add subject to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["homework"] . ' (user_id, subject, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('sisssss', $_SESSION["user_id"], $subject, $date_given, $date_due, $task, $type, $_SESSION["setting_years"]);
$stmt->execute();
$stmt->close();
exit("success");
Expand Down
40 changes: 20 additions & 20 deletions homework/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
);
if (mysqli_connect_errno()) exit("Error with the Database");

// Get all classes
$classlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["classes"] . " WHERE user_id = ?")) {
// Get all subjects
$subjectlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ?")) {
$stmt->bind_param("s", $_SESSION["user_id"]);
$stmt->execute();
$stmt->bind_result($class_name, $class_color, $class_id, $class_last_used, $class_grade_average);
$stmt->bind_result($subject_name, $subject_color, $subject_id, $subject_last_used, $subject_grade_average);
while ($stmt->fetch()) {
$classlist[] = array(
"name" => $class_name,
"color" => $class_color,
"id" => $class_id,
"last_used" => $class_last_used,
"average" => $class_grade_average
$subjectlist[] = array(
"name" => $subject_name,
"color" => $subject_color,
"id" => $subject_id,
"last_used" => $subject_last_used,
"average" => $subject_grade_average
);
}
$stmt->close();
Expand Down Expand Up @@ -82,16 +82,16 @@
</a>
</nav>
<main id="main">
<div class="class-main_content">
<div class="class">
<div class="class-title">
Class
<div class="subject-main_content">
<div class="subject">
<div class="subject-title">
Subject
</div>
<div class="class-container">
<select name="class-selector" id="class-selector">
<div class="subject-container">
<select name="subject-selector" id="subject-selector">
<?php
foreach ($classlist as $class) {
echo '<option value="' . $class["id"] . '">' . $class["name"] . '</option>';
foreach ($subjectlist as $subject) {
echo '<option value="' . $subject["id"] . '">' . $subject["name"] . '</option>';
}
?>
</select>
Expand Down Expand Up @@ -135,14 +135,14 @@
</div>
</div>
</div>
<div class="class_add">
<div class="subject_add">
<div>Add task <i class="fas fa-plus"></i></div>
</div>
</main>
<script src="https://assets.noten-app.de/js/jquery/jquery-3.6.1.min.js"></script>
<script src="https://assets.noten-app.de/js/themes/themes.js"></script>
<script src="./type-switch.js"></script>
<script src="./add-class.js"></script>
<script src="./add-subject.js"></script>
<?php if ($config["tracking"]["matomo"]["on"]) echo ($config["tracking"]["matomo"]["code"]); ?>
</body>

Expand Down
24 changes: 12 additions & 12 deletions homework/add/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ main {
grid-template-rows: 1fr min-content;
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas: "class-main_content" "class_add";
grid-template-areas: "subject-main_content" "subject_add";
}

#view_toggle {
transition: 0.5s;
}

.class-main_content {
grid-area: class-main_content;
.subject-main_content {
grid-area: subject-main_content;
overflow-x: hidden;
overflow-y: auto;
}
Expand Down Expand Up @@ -47,9 +47,9 @@ main {
}


/* Class section */
/* subject section */

.class {
.subject {
display: flex;
flex-direction: column;
background-color: var(--background2-color);
Expand All @@ -58,16 +58,16 @@ main {
padding: 1rem;
}

.class-title {
.subject-title {
font-size: 1.5rem;
margin-bottom: 0.5rem;
}

.class-container {
.subject-container {
display: flex;
}

.class-container>select {
.subject-container>select {
flex-grow: 1;
resize: vertical;
border-radius: 0.5rem;
Expand Down Expand Up @@ -199,11 +199,11 @@ main {


/*
Button to add classes
Button to add subjects
*/

.class_add {
grid-area: class_add;
.subject_add {
grid-area: subject_add;
display: grid;
place-items: center;
padding: 1rem;
Expand All @@ -213,6 +213,6 @@ Button to add classes
cursor: pointer;
}

.class_add>div>i {
.subject_add>div>i {
color: var(--accent-color);
}
10 changes: 5 additions & 5 deletions homework/edit/edit-class.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const class_selector = document.getElementById('class-selector');
const subject_selector = document.getElementById('subject-selector');
const task_input = document.getElementById('task-input');
const date_input_input = document.getElementById('date_input-input');
const class_edit_button = document.getElementById('task_save');
const subject_edit_button = document.getElementById('task_save');
const task_mark_undone_button = document.getElementById('task_mark_undone');
const task_delete_button = document.getElementById('task_delete');

class_edit_button.addEventListener('click', () => {
subject_edit_button.addEventListener('click', () => {
// check if task is empty
if (task_input.value == "") {
task_input.style.border = "1px solid red";
Expand All @@ -17,7 +17,7 @@ class_edit_button.addEventListener('click', () => {
url: './edit.php',
type: 'POST',
data: {
class: class_selector.value,
subject: subject_selector.value,
type: type,
task_id: task_id,
date_due: date_input_input.value,
Expand Down Expand Up @@ -48,7 +48,7 @@ task_mark_undone_button.addEventListener('click', () => {
url: './edit.php',
type: 'POST',
data: {
class: class_selector.value,
subject: subject_selector.value,
type: type,
task_id: task_id,
date_due: date_input_input.value,
Expand Down
8 changes: 4 additions & 4 deletions homework/edit/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
if (mysqli_connect_errno()) die("Error with the Database");

// Get input
$class = $_POST["class"];
$subject = $_POST["subject"];
$type = $_POST["type"];
$date_due = $_POST["date_due"];
$task = $_POST["task"];
$task_id = $_POST["task_id"];

// Check if necessary input is given
if (!isset($class) || strlen($class) == 0) die("missing-class");
if (!isset($subject) || strlen($subject) == 0) die("missing-subject");
if (!isset($type)) die("missing-type");
if (!($type == "b" || $type == "v" || $type == "w" || $type == "o")) die("invalid-type");
if (!isset($date_due) || strlen($date_due) == 0) die("missing-date_due");
Expand All @@ -40,8 +40,8 @@
$date_given = date("Y-m-d");

// Update task in DB
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["homework"] . ' SET class = ?, given = ?, deadline = ?, text = ?, type = ? WHERE entry_id = ? AND user_id = ?')) {
$stmt->bind_param('sssssis', $class, $date_given, $date_due, $task, $type, $task_id, $_SESSION["user_id"]);
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["homework"] . ' SET subject = ?, given = ?, deadline = ?, text = ?, type = ? WHERE entry_id = ? AND user_id = ?')) {
$stmt->bind_param('sssssis', $subject, $date_given, $date_due, $task, $type, $task_id, $_SESSION["user_id"]);
$stmt->execute();
$stmt->close();
exit("success");
Expand Down
44 changes: 22 additions & 22 deletions homework/edit/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if (!isset($_GET["task"])) header("Location: /homework");
$task_id = htmlspecialchars($_GET["task"]);
// Check if task is a-z or 0-9
if (!preg_match("/^[a-z0-9]*$/", $task_id)) header("Location: /classes");
if (!preg_match("/^[a-z0-9]*$/", $task_id)) header("Location: /subjects");


// Get config
Expand All @@ -25,26 +25,26 @@
);
if (mysqli_connect_errno()) exit("Error with the Database");

// Get all classes
$classlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["classes"] . " WHERE user_id = ?")) {
// Get all subjects
$subjectlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ?")) {
$stmt->bind_param("s", $_SESSION["user_id"]);
$stmt->execute();
$stmt->bind_result($class_name, $class_color, $class_id, $class_last_used, $class_grade_average);
$stmt->bind_result($subject_name, $subject_color, $subject_id, $subject_last_used, $subject_grade_average);
while ($stmt->fetch()) {
$classlist[] = array(
"name" => $class_name,
"color" => $class_color,
"id" => $class_id,
"last_used" => $class_last_used,
"average" => $class_grade_average
$subjectlist[] = array(
"name" => $subject_name,
"color" => $subject_color,
"id" => $subject_id,
"last_used" => $subject_last_used,
"average" => $subject_grade_average
);
}
$stmt->close();
}

// Get task
if ($stmt = $con->prepare("SELECT class, type, text, deadline FROM " . $config["db"]["tables"]["homework"] . " WHERE entry_id = ? AND user_id = ?")) {
if ($stmt = $con->prepare("SELECT subject, type, text, deadline FROM " . $config["db"]["tables"]["homework"] . " WHERE entry_id = ? AND user_id = ?")) {
$stmt->bind_param("is", $task_id, $_SESSION["user_id"]);
$stmt->execute();
$result = $stmt->get_result();
Expand Down Expand Up @@ -98,16 +98,16 @@
</a>
</nav>
<main id="main">
<div class="class-main_content">
<div class="class">
<div class="class-title">
Class
<div class="subject-main_content">
<div class="subject">
<div class="subject-title">
Subject
</div>
<div class="class-container">
<select name="class-selector" id="class-selector">
<div class="subject-container">
<select name="subject-selector" id="subject-selector">
<?php
foreach ($classlist as $class) {
if ($task["class"] == $class["id"]) echo '<option value="' . $class["id"] . '" selected>' . $class["name"] . '</option>';
foreach ($subjectlist as $subject) {
if ($task["subject"] == $class["id"]) echo '<option value="' . $class["id"] . '" selected>' . $class["name"] . '</option>';
else echo '<option value="' . $class["id"] . '">' . $class["name"] . '</option>';
}
?>
Expand Down Expand Up @@ -152,7 +152,7 @@
</div>
</div>
</div>
<div class="class_edit">
<div class="subject_edit">
<div id="task_save"><i class="fas fa-floppy-disk"></i></div>
<div id="task_mark_undone"><i class="fa-regular fa-circle-xmark"></i></div>
<div id="task_delete"><i class="fa-solid fa-trash-can"></i></div>
Expand All @@ -165,7 +165,7 @@
<script src="https://assets.noten-app.de/js/jquery/jquery-3.6.1.min.js"></script>
<script src="https://assets.noten-app.de/js/themes/themes.js"></script>
<script src="./type-switch.js"></script>
<script src="./edit-class.js"></script>
<script src="./edit-subject.js"></script>
<?php if ($config["tracking"]["matomo"]["on"]) echo ($config["tracking"]["matomo"]["code"]); ?>
</body>

Expand Down
Loading

0 comments on commit 21e408c

Please sign in to comment.