diff --git a/admin/add-task.php b/admin/add-task.php new file mode 100644 index 0000000..48f33f6 --- /dev/null +++ b/admin/add-task.php @@ -0,0 +1,84 @@ +prepare($sql); + $stmt->execute([$title, $icon, $description, $status]); + + // Redirect to tasks list + header("Location: tasks.php"); + exit; + } catch (PDOException $e) { + // Ideally, log this error + $errors['db'] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+

Add New Task

+
+ + +
+ + +
"> +
+ + + +
+ +
+
+ + + +
+ +
+
+ + +
+
+ + +
+ + Cancel +
+ +
+ + \ No newline at end of file diff --git a/admin/add-user.php b/admin/add-user.php new file mode 100644 index 0000000..61eaa60 --- /dev/null +++ b/admin/add-user.php @@ -0,0 +1,104 @@ +prepare("SELECT id FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors['email'] = 'Email already exists'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $sql = "INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, 'user')"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $hashed_password]); + + // Redirect to users list + header("Location: users.php"); + exit; + } + } catch (PDOException $e) { + // Ideally, log this error + $errors['db'] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+

Add New User

+
+ + +
+ + +
"> +
+ + + +
+ +
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + + +
+ +
+ + Cancel +
+ +
+ + diff --git a/admin/auth.php b/admin/auth.php new file mode 100644 index 0000000..b0b417b --- /dev/null +++ b/admin/auth.php @@ -0,0 +1,12 @@ +prepare($sql); + $stmt->execute([$id]); + + // Redirect back to task list + header("Location: tasks.php"); + exit; +} catch (PDOException $e) { + // For a real app, you'd log this error and show a user-friendly message. + die("Error: Could not delete task. " . $e->getMessage()); +} \ No newline at end of file diff --git a/admin/delete-user.php b/admin/delete-user.php new file mode 100644 index 0000000..b9c8170 --- /dev/null +++ b/admin/delete-user.php @@ -0,0 +1,25 @@ +prepare($sql); + $stmt->execute([$id]); + + // Redirect back to user list + header("Location: users.php"); + exit; +} catch (PDOException $e) { + // For a real app, you'd log this error and show a user-friendly message. + die("Error: Could not delete user. " . $e->getMessage()); +} diff --git a/admin/edit-task.php b/admin/edit-task.php new file mode 100644 index 0000000..0f3f5a5 --- /dev/null +++ b/admin/edit-task.php @@ -0,0 +1,104 @@ +prepare("SELECT * FROM tasks WHERE id = ?"); +$stmt->execute([$id]); +$task = $stmt->fetch(); + +if (!$task) { + // Optional: Add a flash message here + header("Location: tasks.php"); + exit; +} + +$title = $task['title']; +$icon = $task['icon']; +$description = $task['description']; +$status = $task['status']; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $title = trim($_POST['title']); + $icon = trim($_POST['icon']); + $description = trim($_POST['description']); + $status = trim($_POST['status']); + + if (empty($title)) { + $errors['title'] = 'Title is required'; + } + + if (empty($icon)) { + $errors['icon'] = 'Icon is required'; + } + + if (empty($errors)) { + try { + $sql = "UPDATE tasks SET title = ?, icon = ?, description = ?, status = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$title, $icon, $description, $status, $id]); + + header("Location: tasks.php"); + exit; + } catch (PDOException $e) { + $errors['db'] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+

Edit Task

+
+ + +
+ + +
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + +
+
+ + +
+ + Cancel +
+ +
+ + \ No newline at end of file diff --git a/admin/edit-user.php b/admin/edit-user.php new file mode 100644 index 0000000..d821531 --- /dev/null +++ b/admin/edit-user.php @@ -0,0 +1,124 @@ +prepare("SELECT * FROM users WHERE id = ?"); +$stmt->execute([$id]); +$user = $stmt->fetch(); + +if (!$user) { + // Optional: Add a flash message here + header("Location: users.php"); + exit; +} + +$name = $user['name']; +$email = $user['email']; + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $name = trim($_POST['name']); + $email = trim($_POST['email']); + $password = $_POST['password']; + $password_confirm = $_POST['password_confirm']; + + if (empty($name)) { + $errors['name'] = 'Name is required'; + } + + if (empty($email)) { + $errors['email'] = 'Email is required'; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $errors['email'] = 'Invalid email format'; + } + + if (!empty($password) && ($password !== $password_confirm)) { + $errors['password_confirm'] = 'Passwords do not match'; + } + + if (empty($errors)) { + try { + // Check if email already exists for another user + $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ? AND id != ?"); + $stmt->execute([$email, $id]); + if ($stmt->fetch()) { + $errors['email'] = 'Email already exists for another user'; + } else { + if (!empty($password)) { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $sql = "UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $hashed_password, $id]); + } else { + $sql = "UPDATE users SET name = ?, email = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $id]); + } + + header("Location: users.php"); + exit; + } + } catch (PDOException $e) { + $errors['db'] = "Database error: " . $e->getMessage(); + } + } +} +?> + +
+
+

Edit User

+
+ + +
+ + +
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + + +
+ +
+ + Cancel +
+ +
+ + diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..54a18ef --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,6 @@ + +
+
- - - -
- - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..e816bcb --- /dev/null +++ b/login.php @@ -0,0 +1,88 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_name'] = $user['name']; + $_SESSION['user_role'] = $user['role']; + + header("Location: admin/index.php"); + exit; + } else { + $errors['login'] = 'Invalid email or password'; + } + } catch (PDOException $e) { + $errors['db'] = "Database error: " . $e->getMessage(); + } + } +} + +$pageTitle = "Login"; +include 'partials/header.php'; +?> + +
+
+
+
+
+

Admin Login

+ +
+ + +
+ +
"> +
+ + + +
+ +
+
+ + + +
+ +
+ +
+
+
+
+
+
+ + diff --git a/partials/footer.php b/partials/footer.php new file mode 100644 index 0000000..8548d22 --- /dev/null +++ b/partials/footer.php @@ -0,0 +1,14 @@ +
+ +
+ + + + + + + diff --git a/partials/header.php b/partials/header.php new file mode 100644 index 0000000..58d68d1 --- /dev/null +++ b/partials/header.php @@ -0,0 +1,26 @@ + + + + + + <?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) : "OldHelp"; ?> + + + + + +