From ca7f5831fafcdc3fbd142f24089c4e922554e850 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 7 Nov 2025 06:42:26 +0000 Subject: [PATCH] Contacts --- api/send_message.php | 32 +++++ assets/css/custom.css | 54 +------- dashboard.php | 146 ++++++++++++++------ db/migrations/001_create_messages_table.php | 21 +++ db/setup.php | 9 +- footer.php | 6 +- header.php | 32 ++++- login.php | 6 +- 8 files changed, 195 insertions(+), 111 deletions(-) create mode 100644 api/send_message.php create mode 100644 db/migrations/001_create_messages_table.php diff --git a/api/send_message.php b/api/send_message.php new file mode 100644 index 0000000..30c4b45 --- /dev/null +++ b/api/send_message.php @@ -0,0 +1,32 @@ + false, 'error' => 'Not logged in']); + exit(); +} + +if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + echo json_encode(['success' => false, 'error' => 'Invalid request method']); + exit(); +} + +require_once '../db/config.php'; + +$sender_id = $_SESSION['user_id']; +$receiver_id = isset($_POST['receiver_id']) ? (int)$_POST['receiver_id'] : 0; +$message = isset($_POST['message']) ? trim($_POST['message']) : ''; + +if ($receiver_id && !empty($message)) { + try { + $pdo = db(); + $stmt = $pdo->prepare('INSERT INTO messages (sender_id, receiver_id, message) VALUES (?, ?, ?)'); + $stmt->execute([$sender_id, $receiver_id, $message]); + echo json_encode(['success' => true]); + } catch (PDOException $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + } +} else { + echo json_encode(['success' => false, 'error' => 'Invalid input']); +} diff --git a/assets/css/custom.css b/assets/css/custom.css index eaac7b1..c3d6751 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -1,51 +1,3 @@ - -body { - font-family: 'Inter', sans-serif; - background-color: #121212; - color: #E0E0E0; -} - -.navbar-dark .navbar-nav .nav-link { - color: rgba(255, 255, 255, .75); -} - -.navbar-dark .navbar-nav .nav-link.active, -.navbar-dark .navbar-nav .nav-link:hover { - color: #fff; -} - -.card { - background-color: #1E1E1E; - border: 1px solid rgba(255, 255, 255, 0.1); -} - -.form-control { - background-color: #2a2a2a; - color: #fff; - border: 1px solid #444; -} - -.form-control:focus { - background-color: #2a2a2a; - color: #fff; - border-color: #0D6EFD; - box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, .25); -} - -.form-control::placeholder { - color: #888; -} - -.btn-primary { - background-color: #0D6EFD; - border-color: #0D6EFD; -} - -.text-muted { - color: #A0A0A0 !important; -} - -.feature-icon { - font-size: 2.5rem; - color: #0D6EFD; -} +html, body { + height: 100%; +} \ No newline at end of file diff --git a/dashboard.php b/dashboard.php index baae238..bab83bc 100644 --- a/dashboard.php +++ b/dashboard.php @@ -1,58 +1,112 @@ -
-
-
-
-
- Conversations -
- -
-
-
-
-
- Chat with User 1 -
-
- -
-
- Hello! -
-
-
-
- Hi there! -
-
-
-
+ + + diff --git a/db/migrations/001_create_messages_table.php b/db/migrations/001_create_messages_table.php new file mode 100644 index 0000000..84b547b --- /dev/null +++ b/db/migrations/001_create_messages_table.php @@ -0,0 +1,21 @@ +exec($sql); + echo "Table 'messages' created successfully (if it didn't exist).\n"; +} catch (PDOException $e) { + die("DB MIGRATION ERROR: " . $e->getMessage()); +} + diff --git a/db/setup.php b/db/setup.php index 2fd5d6a..3298fbf 100644 --- a/db/setup.php +++ b/db/setup.php @@ -22,7 +22,14 @@ try { created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );"; $pdo->exec($sql); - echo "Table 'users' created successfully (if it didn't exist).\n"; + echo "Table 'users' created successfully (if it didn\'t exist).\n"; + + // 4. Run migrations + $migration_files = glob(__DIR__ . '/migrations/*.php'); + foreach ($migration_files as $file) { + require_once $file; + echo "Ran migration: $file\n"; + } } catch (PDOException $e) { die("DB SETUP ERROR: " . $e->getMessage()); diff --git a/footer.php b/footer.php index 62c2604..7365701 100644 --- a/footer.php +++ b/footer.php @@ -1,9 +1,5 @@ - + diff --git a/header.php b/header.php index 7c5e038..a1d4f5b 100644 --- a/header.php +++ b/header.php @@ -23,14 +23,14 @@ \ No newline at end of file + + +
+
+
Chats
+ +
+
+
+ Select a user to start a conversation. +
+ +
+
diff --git a/login.php b/login.php index 861c80e..c610f44 100644 --- a/login.php +++ b/login.php @@ -15,7 +15,7 @@ include 'header.php'; // If user is already logged in, redirect to dashboard if (isset($_SESSION['user_id'])) { - echo ''; + header("Location: dashboard.php"); exit; } @@ -47,8 +47,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($user && password_verify($password, $user['password_hash'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['display_name'] = $user['display_name']; - // Use JS redirect for consistency - echo ''; + // Standard PHP redirect + header("Location: dashboard.php"); exit; } else { $errors[] = 'Invalid email or password.';