Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
4ff4f98255 Basic 2025-11-28 15:28:25 +00:00
10 changed files with 523 additions and 147 deletions

112
assets/css/custom.css Normal file
View File

@ -0,0 +1,112 @@
/* General Body Styles */
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
/* Light Mode Palette */
body[data-bs-theme="light"] {
background-color: #F8F9FA;
color: #212529;
}
/* Dark Mode Palette */
body[data-bs-theme="dark"] {
background-color: #121212;
color: #E0E0E0;
}
body[data-bs-theme="dark"] .navbar {
background-color: #1E1E1E !important;
border-bottom: 1px solid #333;
}
body[data-bs-theme="dark"] .note-card {
background-color: #1E1E1E;
border-color: #333;
}
body[data-bs-theme="dark"] .note-card .card-title {
color: #FFF;
}
body[data-bs-theme="dark"] .note-card .card-text {
color: #AEAEAE;
}
body[data-bs-theme="dark"] .badge {
border: 1px solid #555;
}
/* Navbar */
.navbar-brand {
font-weight: 700;
font-size: 1.5rem;
}
/* Theme Switcher */
.theme-switch {
cursor: pointer;
font-size: 1.2rem;
}
/* Note Grid */
.notes-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1.5rem;
}
/* Note Card */
.note-card {
border-radius: 0.75rem;
border: 1px solid #E0E0E0;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
transition: transform 0.2s ease, box-shadow 0.2s ease;
position: relative;
overflow: hidden;
padding-bottom: 2.5rem; /* Space for footer */
}
.note-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
.note-card .card-body {
padding: 1.5rem;
}
.note-card .card-title {
font-weight: 600;
}
.note-card .card-text {
color: #6c757d;
font-size: 0.95rem;
}
.note-card .card-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 0.75rem 1.5rem;
background: transparent;
border-top: none;
}
.note-card .badge {
font-size: 0.75rem;
padding: 0.4em 0.6em;
font-weight: 500;
}
.color-label {
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 100%;
}

26
assets/js/main.js Normal file
View File

@ -0,0 +1,26 @@
document.addEventListener('DOMContentLoaded', () => {
const themeSwitch = document.getElementById('theme-switch');
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : 'light';
if (currentTheme) {
document.body.setAttribute('data-bs-theme', currentTheme);
if (themeSwitch) {
themeSwitch.innerHTML = currentTheme === 'dark' ? '<i class="bi bi-sun-fill"></i>' : '<i class="bi bi-moon-fill"></i>';
}
}
if(themeSwitch) {
themeSwitch.addEventListener('click', () => {
let theme = document.body.getAttribute('data-bs-theme');
if (theme === 'dark') {
document.body.setAttribute('data-bs-theme', 'light');
localStorage.setItem('theme', 'light');
themeSwitch.innerHTML = '<i class="bi bi-moon-fill"></i>';
} else {
document.body.setAttribute('data-bs-theme', 'dark');
localStorage.setItem('theme', 'dark');
themeSwitch.innerHTML = '<i class="bi bi-sun-fill"></i>';
}
});
}
});

75
create_note.php Normal file
View File

@ -0,0 +1,75 @@
<?php
session_start();
require_once 'db/config.php';
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$content = $_POST['content'] ?? '';
$color = $_POST['color'] ?? '#FFDDC1';
$tags = $_POST['tags'] ?? '';
$user_id = $_SESSION['user_id'];
if (empty($title)) {
$error = 'Title is required.';
} else {
try {
$db = db();
$stmt = $db->prepare('INSERT INTO notes (user_id, title, content, color, tags) VALUES (?, ?, ?, ?, ?)');
$stmt->execute([$user_id, $title, $content, $color, $tags]);
header('Location: index.php?note_created=1');
exit;
} catch (PDOException $e) {
$error = 'Database error: ' . $e->getMessage();
}
}
}
?>
<?php require_once 'header.php'; ?>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h3 class="card-title text-center">Create a New Note</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form action="create_note.php" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="content" class="form-label">Content</label>
<textarea class="form-control" id="content" name="content" rows="5"></textarea>
</div>
<div class="mb-3">
<label for="color" class="form-label">Color</label>
<input type="color" class="form-control form-control-color" id="color" name="color" value="#FFDDC1">
</div>
<div class="mb-3">
<label for="tags" class="form-label">Tags (comma-separated)</label>
<input type="text" class="form-control" id="tags" name="tags">
</div>
<button type="submit" class="btn btn-primary w-100">Create Note</button
</form>
</div>
</div>
</div>
</div>
<?php require_once 'footer.php'; ?>

View File

@ -0,0 +1,21 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL UNIQUE,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('student', 'teacher') NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `notes` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` INT NOT NULL,
`title` VARCHAR(255) NOT NULL,
`content` TEXT,
`color` VARCHAR(7),
`tags` VARCHAR(255),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
);

10
footer.php Normal file
View File

@ -0,0 +1,10 @@
</div> <!-- /container -->
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted">© <?php echo date("Y"); ?> NotesApp</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>

51
header.php Normal file
View File

@ -0,0 +1,51 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Notes</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">NotesApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item">
<a class="nav-link" href="create_note.php">Create Note</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
</ul>
</li>
<?php else: ?>
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">

214
index.php
View File

@ -1,150 +1,76 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
session_start();
require_once 'db/config.php';
if (isset($_SESSION['user_id'])) {
try {
$db = db();
$stmt = $db->prepare('SELECT * FROM notes WHERE user_id = ? ORDER BY created_at DESC');
$stmt->execute([$_SESSION['user_id']]);
$notes = $stmt->fetchAll();
} catch (PDOException $e) {
// For now, just show an empty array on DB error
$notes = [];
}
} else {
// Sample Data for Notes for non-logged-in users
$notes = [
[
'title' => 'Biology Lesson Plan',
'content' => 'Introduction to cell theory. Discuss Hooke and Leeuwenhoek...',
'tags' => 'science,lesson-plan,10th-grade',
'color' => '#D4EDDA',
],
[
'title' => 'Student Study Notes - History',
'content' => 'Key dates for the American Revolution: 1765 Stamp Act, 1770 Boston Massacre...',
'tags' => 'history,student-notes,exam-prep',
'color' => '#F8D7DA',
],
];
}
$note_created_success = isset($_GET['note_created']);
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
<?php require_once 'header.php'; ?>
<main class="container py-5">
<h1 class="mb-4">Your Notes</h1>
<?php if ($note_created_success): ?>
<div class="alert alert-success">Note created successfully!</div>
<?php endif; ?>
<?php if (empty($notes)): ?>
<div class="text-center">
<p>You don't have any notes yet. <a href="create_note.php">Create your first one!</a></p>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
<?php else: ?>
<div class="notes-grid">
<?php foreach ($notes as $note): ?>
<div class="card note-card">
<div class="color-label" style="background-color: <?php echo htmlspecialchars($note['color']); ?>;"></div>
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($note['title']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($note['content']); ?></p>
</div>
<div class="card-footer">
<?php
$tags = !empty($note['tags']) ? explode(',', $note['tags']) : [];
foreach ($tags as $tag):
?>
<span class="badge bg-secondary bg-opacity-10 text-secondary-emphasis rounded-pill">
<?php echo htmlspecialchars(trim($tag)); ?>
</span>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
</body>
</html>
<?php require_once 'footer.php'; ?>

67
login.php Normal file
View File

@ -0,0 +1,67 @@
<?php
require_once 'db/config.php';
session_start();
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email) || empty($password)) {
$error = 'Please fill in all fields.';
} else {
try {
$db = db();
$stmt = $db->prepare('SELECT id, username, password, role FROM users WHERE email = ?');
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
header('Location: index.php');
exit;
} else {
$error = 'Invalid email or password.';
}
} catch (PDOException $e) {
$error = 'Database error: ' . $e->getMessage();
}
}
}
?>
<?php require_once 'header.php'; ?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h3 class="card-title text-center">Login</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form action="login.php" method="POST">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'footer.php'; ?>

5
logout.php Normal file
View File

@ -0,0 +1,5 @@
<?php
session_start();
session_destroy();
header('Location: index.php');
exit;

83
register.php Normal file
View File

@ -0,0 +1,83 @@
<?php
require_once 'db/config.php';
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$role = $_POST['role'] ?? '';
if (empty($username) || empty($email) || empty($password) || empty($role)) {
$error = 'Please fill in all fields.';
} else {
try {
$db = db();
// Check for existing user
$stmt = $db->prepare('SELECT id FROM users WHERE username = ? OR email = ?');
$stmt->execute([$username, $email]);
if ($stmt->fetch()) {
$error = 'Username or email already exists.';
} else {
// Insert new user
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $db->prepare('INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)');
$stmt->execute([$username, $email, $hashed_password, $role]);
$success = 'Registration successful! You can now <a href="login.php">login</a>.';
}
} catch (PDOException $e) {
$error = 'Database error: ' . $e->getMessage();
}
}
}
?>
<?php require_once 'header.php'; ?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body">
<h3 class="card-title text-center">Register</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success"><?php echo $success; ?></div>
<?php else: ?>
<form action="register.php" method="POST">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option value="student">Student</option>
<option value="teacher">Teacher</option>
</select>
</div>
<button type="submit" class="btn btn-primary w-100">Register</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php require_once 'footer.php'; ?>