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

Commit 152cc6c

Browse files
Merge pull request #43 from noten-app/user-unique-ids
User unique ids
2 parents bd62f4e + 4c78f5d commit 152cc6c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

homework/add/add.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
// Create given-date
3939
$date_given = date("Y-m-d");
4040

41-
// Add subject to DB and get inserted ID
42-
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["homework"] . ' (user_id, subject, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?)')) {
43-
$stmt->bind_param('sisssss', $_SESSION["user_id"], $subject, $date_given, $date_due, $task, $type, $_SESSION["setting_years"]);
41+
// Generate id (8char random string)
42+
$entryId = bin2hex(random_bytes(4));
43+
44+
// Add subject to DB
45+
if ($stmt = $con->prepare('INSERT INTO ' . $config["db"]["tables"]["homework"] . ' (user_id, entry_id, subject, given, deadline, text, type, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
46+
$stmt->bind_param('ssssssss', $_SESSION["user_id"], $entryId, $subject, $date_given, $date_due, $task, $type, $_SESSION["setting_years"]);
4447
$stmt->execute();
4548
$stmt->close();
4649
exit("success");

homework/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
foreach ($hw_dategroup as $hw_entry) {
116116
echo '<div class="homework_entry">';
117117
echo '<div class="classname">';
118-
foreach ($subjects as $subject) if ($subject["id"] == $hw_entry["class"]) echo $subject["name"];
118+
foreach ($subjects as $subject) if ($subject["id"] == $hw_entry["subject"]) echo $subject["name"];
119119
echo '</div><div class="task" onclick="location.assign(\'./edit/?task=' . $hw_entry["entry_id"] . '\')"><span>' . $hw_entry["text"] . '</span></div>';
120120
echo '<div class="dot" id="dot-' . $hw_entry["entry_id"] . '" onclick="toggleState(\'' . $hw_entry["entry_id"] . '\')">';
121121
if ($hw_entry["status"] == 0) echo '<i class="fa-regular fa-circle"></i></div>';

0 commit comments

Comments
 (0)