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 #27 from noten-app/#19-Use-config-as-array
Browse files Browse the repository at this point in the history
✨ Transcribed config to be an array
  • Loading branch information
CuzImBisonratte authored Sep 24, 2023
2 parents a237b3e + c263b0a commit 7da0e73
Show file tree
Hide file tree
Showing 34 changed files with 183 additions and 183 deletions.
10 changes: 5 additions & 5 deletions classes/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand Down Expand Up @@ -44,7 +44,7 @@
$classColor = str_replace("#", "", $classColor);

// Add class to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . config_table_name_classes . ' (name, color, user_id, grade_k, grade_m, grade_t, grade_s, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["classes"] . ' (name, color, user_id, grade_k, grade_m, grade_t, grade_s, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
$stmt->bind_param('sssiisis', $className, $classColor, $_SESSION["user_id"], $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $_SESSION["setting_years"]);
$stmt->execute();
$classID = $stmt->insert_id;
Expand Down
8 changes: 4 additions & 4 deletions classes/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

Expand Down
8 changes: 4 additions & 4 deletions classes/edit/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand Down
8 changes: 4 additions & 4 deletions classes/edit/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

Expand Down
14 changes: 7 additions & 7 deletions classes/edit/modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand All @@ -39,7 +39,7 @@
if (!isset($classID)) die("missing-classid");

// Check if class exists and belongs to user
if ($stmt = $con->prepare('SELECT user_id FROM ' . config_table_name_classes . ' WHERE id = ?')) {
if ($stmt = $con->prepare('SELECT user_id FROM ' . $config["db"]["tables"]["classes"] . ' WHERE id = ?')) {
$stmt->bind_param('i', $classID);
$stmt->execute();
$stmt->store_result();
Expand All @@ -57,10 +57,10 @@
$classColor = str_replace("#", "", $classColor);

// Make an sql statement to update the class
// exit("UPDATE ".config_table_name_classes." SET name = '".$className."', color = '".$classColor."', grade_k = ".$gradingTypeK.", grade_m = ".$gradingTypeM.", grade_t = '".$gradingTypeT."', grade_s = ".$gradingTypeS." WHERE id = ".$classID);
// exit("UPDATE ".$config["db"]["tables"]["classes"]." SET name = '".$className."', color = '".$classColor."', grade_k = ".$gradingTypeK.", grade_m = ".$gradingTypeM.", grade_t = '".$gradingTypeT."', grade_s = ".$gradingTypeS." WHERE id = ".$classID);

// Update class in DB
if ($stmt = $con->prepare('UPDATE ' . config_table_name_classes . ' SET name = ?, color = ?, grade_k = ?, grade_m = ?, grade_t = ?, grade_s = ? WHERE id = ?')) {
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["classes"] . ' SET name = ?, color = ?, grade_k = ?, grade_m = ?, grade_t = ?, grade_s = ? WHERE id = ?')) {
$stmt->bind_param('ssiisii', $className, $classColor, $gradingTypeK, $gradingTypeM, $gradingTypeT, $gradingTypeS, $classID);
$stmt->execute();
$stmt->close();
Expand Down
14 changes: 7 additions & 7 deletions classes/grades/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand All @@ -33,7 +33,7 @@
if (!isset($class_id)) die("missing-class");

// Check if class is owned by user
if ($stmt = $con->prepare('SELECT user_id FROM ' . config_table_name_classes . ' WHERE id = ?')) {
if ($stmt = $con->prepare('SELECT user_id FROM ' . $config["db"]["tables"]["classes"] . ' WHERE id = ?')) {
$stmt->bind_param('i', $class_id);
$stmt->execute();
$stmt->store_result();
Expand Down Expand Up @@ -67,13 +67,13 @@
if (strlen($note) > 25) die("invalid-note");

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

// Change class last used
if ($stmt = $con->prepare('UPDATE ' . config_table_name_classes . ' SET last_used = ? WHERE id = ?')) {
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["classes"] . ' SET last_used = ? WHERE id = ?')) {
$stmt->bind_param('si', $date, $class_id);
$stmt->execute();
$stmt->close();
Expand Down
8 changes: 4 additions & 4 deletions classes/grades/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

Expand Down
14 changes: 7 additions & 7 deletions classes/grades/edit/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

// Get input
$grade_id = $_POST["grade_id"];

// Check if grade is owned by user
if ($stmt = $con->prepare('SELECT user_id FROM ' . config_table_name_grades . ' WHERE id = ?')) {
if ($stmt = $con->prepare('SELECT user_id FROM ' . $config["db"]["tables"]["grades"] . ' WHERE id = ?')) {
$stmt->bind_param('i', $grade_id);
$stmt->execute();
$stmt->store_result();
Expand All @@ -35,13 +35,13 @@
}

// Delete grade
if ($stmt = $con->prepare('DELETE FROM ' . config_table_name_grades . ' WHERE id = ?')) {
if ($stmt = $con->prepare('DELETE FROM ' . $config["db"]["tables"]["grades"] . ' WHERE id = ?')) {
$stmt->bind_param('s', $grade_id);
$stmt->execute();
$stmt->close();

// Change class last used
if ($stmt = $con->prepare('UPDATE ' . config_table_name_classes . ' SET last_used = ? WHERE id = ?')) {
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["classes"] . ' SET last_used = ? WHERE id = ?')) {
$stmt->bind_param('si', $date, $class_id);
$stmt->execute();
$stmt->close();
Expand Down
14 changes: 7 additions & 7 deletions classes/grades/edit/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand All @@ -36,7 +36,7 @@
if (!isset($grade)) die("missing-grade");

// Check if grade is owned by user
if ($stmt = $con->prepare('SELECT user_id FROM ' . config_table_name_grades . ' WHERE id = ?')) {
if ($stmt = $con->prepare('SELECT user_id FROM ' . $config["db"]["tables"]["grades"] . ' WHERE id = ?')) {
$stmt->bind_param('i', $grade_id);
$stmt->execute();
$stmt->store_result();
Expand Down Expand Up @@ -70,13 +70,13 @@
if (strlen($note) > 25) die("invalid-note");

// Add grade
if ($stmt = $con->prepare('UPDATE ' . config_table_name_grades . ' SET note = ?, type = ?, date = ?, grade = ? WHERE id = ?')) {
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["grades"] . ' SET note = ?, type = ?, date = ?, grade = ? WHERE id = ?')) {
$stmt->bind_param('sssss', $note, $type, $date, $grade_float, $grade_id);
$stmt->execute();
$stmt->close();

// Change class last used
if ($stmt = $con->prepare('UPDATE ' . config_table_name_classes . ' SET last_used = ? WHERE id = ?')) {
if ($stmt = $con->prepare('UPDATE ' . $config["db"]["tables"]["classes"] . ' SET last_used = ? WHERE id = ?')) {
$stmt->bind_param('si', $date, $class_id);
$stmt->execute();
$stmt->close();
Expand Down
10 changes: 5 additions & 5 deletions classes/grades/edit/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

// Get grade
if ($stmt = $con->prepare('SELECT user_id, class, note, type, date, grade FROM ' . config_table_name_grades . ' WHERE id = ?')) {
if ($stmt = $con->prepare('SELECT user_id, class, note, type, date, grade FROM ' . $config["db"]["tables"]["grades"] . ' WHERE id = ?')) {
$stmt->bind_param('s', $grade_id);
$stmt->execute();
$stmt->store_result();
Expand Down
8 changes: 4 additions & 4 deletions classes/grades/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

Expand Down
10 changes: 5 additions & 5 deletions classes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");

Expand All @@ -29,7 +29,7 @@

// Get all classes
$classlist = array();
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . config_table_name_classes . " WHERE user_id = ? AND year = ?" . $sorting_appendix)) {
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["classes"] . " WHERE user_id = ? AND year = ?" . $sorting_appendix)) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_years"]);
$stmt->execute();
$stmt->bind_result($class_name, $class_color, $class_id, $class_last_used, $class_grade_average);
Expand Down
10 changes: 5 additions & 5 deletions homework/add/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand All @@ -39,7 +39,7 @@
$date_given = date("Y-m-d");

// Add class to DB and get inserted ID
if ($stmt = $con->prepare('INSERT INTO ' . config_table_name_homework . ' (user_id, class, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?)')) {
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"]);
$stmt->execute();
$stmt->close();
Expand Down
10 changes: 5 additions & 5 deletions homework/add/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
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_table_name_classes . " WHERE user_id = ?")) {
if ($stmt = $con->prepare("SELECT name, color, id, last_used, average FROM " . $config["db"]["tables"]["classes"] . " 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);
Expand Down
10 changes: 5 additions & 5 deletions homework/edit/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

// Get taskID
$task_id = $_POST["task_id"];

// Update task in DB
if ($stmt = $con->prepare('DELETE FROM ' . config_table_name_homework . ' WHERE entry_id = ? AND user_id = ?')) {
if ($stmt = $con->prepare('DELETE FROM ' . $config["db"]["tables"]["homework"] . ' WHERE entry_id = ? AND user_id = ?')) {
$stmt->bind_param('is', $task_id, $_SESSION["user_id"]);
$stmt->execute();
$stmt->close();
Expand Down
10 changes: 5 additions & 5 deletions homework/edit/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// DB Connection
$con = mysqli_connect(
config_db_host,
config_db_user,
config_db_password,
config_db_name
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) die("Error with the Database");

Expand All @@ -40,7 +40,7 @@
$date_given = date("Y-m-d");

// Update task in DB
if ($stmt = $con->prepare('UPDATE ' . config_table_name_homework . ' SET class = ?, given = ?, deadline = ?, text = ?, type = ? WHERE entry_id = ? AND user_id = ?')) {
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"]);
$stmt->execute();
$stmt->close();
Expand Down
Loading

0 comments on commit 7da0e73

Please sign in to comment.