This commit is contained in:
Flatlogic Bot 2026-01-11 19:47:45 +00:00
parent f7094f0dcc
commit 7d6bbef5d2
18 changed files with 567 additions and 149 deletions

29
api/pexels.php Normal file
View File

@ -0,0 +1,29 @@
<?php
header('Content-Type: application/json');
require_once __DIR__.'/../includes/pexels.php';
$qs = isset($_GET['queries']) ? explode(',', $_GET['queries']) : ['math','algebra','teacher','student'];
$out = [];
foreach ($qs as $q) {
$u = 'https://api.pexels.com/v1/search?query=' . urlencode(trim($q)) . '&orientation=landscape&per_page=1&page=1';
$d = pexels_get($u);
if ($d && !empty($d['photos'])) {
$p = $d['photos'][0];
$src = $p['src']['large2x'] ?? null;
$dest = __DIR__.'/../assets/images/pexels/'.$p['id'].'.jpg';
if ($src) download_to($src, $dest);
$out[] = [
'src' => 'assets/images/pexels/'.$p['id'].'.jpg',
'photographer' => $p['photographer'] ?? 'Unknown',
'photographer_url' => $p['photographer_url'] ?? '',
];
} else {
// Fallback: Picsum
$out[] = [
'src' => 'https://picsum.photos/1200/800',
'photographer' => 'Random Picsum',
'photographer_url' => 'https://picsum.photos/'
];
}
}
echo json_encode($out);
?>

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

@ -0,0 +1,51 @@
body {
background-color: #F3F4F6;
font-family: 'Inter', sans-serif;
}
.sidebar {
background-color: #FFFFFF;
height: 100vh;
position: fixed;
top: 0;
left: 0;
width: 250px;
padding-top: 1rem;
}
.sidebar .nav-link {
color: #4B5563;
font-weight: 500;
}
.sidebar .nav-link.active,
.sidebar .nav-link:hover {
color: #4F46E5;
background-color: #E0E7FF;
}
.main-content {
margin-left: 250px;
padding: 2rem;
}
.card {
border: none;
border-radius: 0.5rem;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
#welcomeCarousel .carousel-item {
height: 500px;
}
#welcomeCarousel .carousel-item img {
height: 100%;
object-fit: cover;
}
#welcomeCarousel .carousel-caption {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 0.5rem;
padding: 1rem;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

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

@ -0,0 +1 @@
console.log('main.js loaded');

23
db/setup.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require_once 'config.php';
try {
$pdo = db();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('teacher', 'student') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
$pdo->exec($sql);
echo "Table 'users' created successfully.";
} catch (PDOException $e) {
die("ERROR: Could not execute $sql. " . $e->getMessage());
}
unset($pdo);
?>

99
db/setup_part2.php Normal file
View File

@ -0,0 +1,99 @@
<?php
require_once 'config.php';
try {
$pdo = db();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Create courses table
$sql_courses = "CREATE TABLE IF NOT EXISTS courses (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
teacher_id INT NOT NULL,
FOREIGN KEY (teacher_id) REFERENCES users(id)
)";
$pdo->exec($sql_courses);
echo "Table 'courses' created successfully.\n";
// Create enrollments table
$sql_enrollments = "CREATE TABLE IF NOT EXISTS enrollments (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
course_id INT NOT NULL,
FOREIGN KEY (student_id) REFERENCES users(id),
FOREIGN KEY (course_id) REFERENCES courses(id)
)";
$pdo->exec($sql_enrollments);
echo "Table 'enrollments' created successfully.\n";
// Create activities table
$sql_activities = "CREATE TABLE IF NOT EXISTS activities (
id INT AUTO_INCREMENT PRIMARY KEY,
enrollment_id INT NOT NULL,
activity_name VARCHAR(255) NOT NULL,
grade INT,
activity_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (enrollment_id) REFERENCES enrollments(id)
)";
$pdo->exec($sql_activities);
echo "Table 'activities' created successfully.\n";
// Sample Data
// Hash a default password
$password = password_hash('password', PASSWORD_DEFAULT);
// Truncate tables before inserting sample data to avoid duplicates on re-run
$pdo->exec("SET FOREIGN_KEY_CHECKS = 0");
$pdo->exec("TRUNCATE TABLE activities");
$pdo->exec("TRUNCATE TABLE enrollments");
$pdo->exec("TRUNCATE TABLE courses");
$pdo->exec("TRUNCATE TABLE users");
$pdo->exec("SET FOREIGN_KEY_CHECKS = 1");
echo "Tables truncated successfully.\n";
// Insert a teacher
$pdo->exec("INSERT INTO users (email, password, role) VALUES ('teacher@example.com', '$password', 'teacher')");
$teacher_id = $pdo->lastInsertId();
echo "Sample teacher inserted.\n";
// Insert courses for the teacher
$stmt = $pdo->prepare("INSERT INTO courses (name, teacher_id) VALUES (?, ?)");
$stmt->execute(['Algebra 101', $teacher_id]);
$course1_id = $pdo->lastInsertId();
$stmt->execute(['History of Algebra', $teacher_id]);
$course2_id = $pdo->lastInsertId();
echo "Sample courses inserted.\n";
// Insert students
$stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (?, ?, ?)");
$stmt->execute(['student1@example.com', $password, 'student']);
$student1_id = $pdo->lastInsertId();
$stmt->execute(['student2@example.com', $password, 'student']);
$student2_id = $pdo->lastInsertId();
echo "Sample students inserted.\n";
// Enroll students in courses
$stmt = $pdo->prepare("INSERT INTO enrollments (student_id, course_id) VALUES (?, ?)");
$stmt->execute([$student1_id, $course1_id]);
$enrollment1_id = $pdo->lastInsertId();
$stmt->execute([$student2_id, $course1_id]);
$enrollment2_id = $pdo->lastInsertId();
$stmt->execute([$student1_id, $course2_id]);
$enrollment3_id = $pdo->lastInsertId();
echo "Students enrolled in courses.\n";
// Add student activities
$stmt = $pdo->prepare("INSERT INTO activities (enrollment_id, activity_name, grade) VALUES (?, ?, ?)");
$stmt->execute([$enrollment1_id, 'Homework 1', 95]);
$stmt->execute([$enrollment1_id, 'Quiz 1', 88]);
$stmt->execute([$enrollment2_id, 'Homework 1', 72]);
$stmt->execute([$enrollment3_id, 'Research Paper', 92]);
echo "Student activities added.\n";
} catch (PDOException $e) {
die("ERROR: Could not able to execute script. " . $e->getMessage());
}
unset($pdo);
?>

5
footer.php Normal file
View File

@ -0,0 +1,5 @@
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

4
footer_login.php Normal file
View File

@ -0,0 +1,4 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

51
header.php Normal file
View File

@ -0,0 +1,51 @@
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AlgebraEase</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/heroicons@1.0.6/dist/outline.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="d-flex">
<div class="d-flex flex-column flex-shrink-0 p-3 text-white bg-dark" style="width: 280px; min-height: 100vh;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<span class="fs-4">AlgebraEase</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="index.php" class="nav-link text-white active" aria-current="page">
Dashboard
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Classes
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Students
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
Assignments
</a>
</li>
<?php if (isset($_SESSION['user_id'])): ?>
<li>
<a href="logout.php" class="nav-link text-white">
Logout
</a>
</li>
<?php endif; ?>
</ul>
</div>
<div class="flex-grow-1 p-4">

14
header_login.php Normal file
View File

@ -0,0 +1,14 @@
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Classroom - Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container mt-4">

26
includes/pexels.php Normal file
View File

@ -0,0 +1,26 @@
<?php
function pexels_key() {
$k = getenv('PEXELS_KEY');
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
}
function pexels_get($url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
CURLOPT_TIMEOUT => 15,
]);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
return null;
}
function download_to($srcUrl, $destPath) {
$data = file_get_contents($srcUrl);
if ($data === false) return false;
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
return file_put_contents($destPath, $data) !== false;
}
?>

267
index.php
View File

@ -1,150 +1,119 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
<?php include 'header.php'; ?>
$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'] ?? '';
?>
<?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>
</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>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
</body>
</html>
<div class="container-fluid">
<?php if (isset($_SESSION['user_id'])): ?>
<div class="d-flex justify-content-between align-items-center">
<h1 class="h2">Dashboard</h1>
<div>
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['role']); ?>!</span>
</div>
</div>
<?php
if (isset($_SESSION['role']) && $_SESSION['role'] == 'teacher') {
// Function to get teacher's courses
function getTeacherCourses($teacher_id) {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, name FROM courses WHERE teacher_id = ?");
$stmt->execute([$teacher_id]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Function to get student activities for a course
function getStudentActivities($course_id) {
$pdo = db();
$stmt = $pdo->prepare("
SELECT u.email, a.activity_name, a.grade, a.activity_date
FROM activities a
JOIN enrollments e ON a.enrollment_id = e.id
JOIN users u ON e.student_id = u.id
WHERE e.course_id = ?
ORDER BY a.activity_date DESC
");
$stmt->execute([$course_id]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$courses = getTeacherCourses($_SESSION['user_id']);
$activities = [];
foreach ($courses as $course) {
$activities[$course['name']] = getStudentActivities($course['id']);
}
}
?>
<div class="row mt-4">
<div class="col-md-8">
<div class="card">
<div class="card-body">
<h5 class="card-title">My Classes</h5>
<ul class="list-group list-group-flush">
<?php if (!empty($courses)): ?>
<?php foreach ($courses as $course):
echo "<li class=\"list-group-item\">" . htmlspecialchars($course['name']) . "</li>";
endforeach; ?>
<?php else: ?>
<li class="list-group-item">No classes found.</li>
<?php endif; ?>
</ul>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Upcoming Assignments</h5>
<p class="card-text">No upcoming assignments.</p>
</div>
</div>
</div>
</div>
<div class="row mt-4">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<h5 class="card-title">Assignment Submissions</h5>
<?php if (!empty($activities)): ?>
<?php foreach ($activities as $courseName => $studentActivities): ?>
<h6 class="mt-3"><?php echo htmlspecialchars($courseName); ?></h6>
<?php if (!empty($studentActivities)): ?>
<table class="table table-striped">
<thead>
<tr>
<th>Student</th>
<th>Assignment</th>
<th>Grade</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($studentActivities as $activity): ?>
<tr>
<td><?php echo htmlspecialchars($activity['email']); ?></td>
<td><?php echo htmlspecialchars($activity['activity_name']); ?></td>
<td><?php echo $activity['grade']; ?></td>
<td><?php echo date('M d, Y', strtotime($activity['activity_date'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>No assignment submissions for this course.</p>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<p class="card-text">No assignment submissions.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php else:
header('Location: login.php');
exit;
?>
<?php endif; ?>
</div>
<?php include 'footer.php'; ?>

66
login.php Normal file
View File

@ -0,0 +1,66 @@
<?php
include 'header_login.php';
require_once 'db/config.php';
$error = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, password FROM users WHERE email = ? AND role = ?");
$stmt->execute([$email, $role]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['role'] = $role;
header("Location: index.php");
exit;
} else {
$error = "Invalid credentials!";
}
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
}
}
?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card mt-5">
<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 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>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="teacher">Teacher</option>
<option value="student">Student</option>
</select>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
<div class="text-center mt-3">
<p>Don't have an account? <a href="register.php">Register here</a></p>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer_login.php'; ?>

7
logout.php Normal file
View File

@ -0,0 +1,7 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit;
?>

73
register.php Normal file
View File

@ -0,0 +1,73 @@
<?php
include 'header_login.php';
require_once 'db/config.php';
$error = '';
$success = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
try {
$pdo = db();
// Check if user already exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error = 'User with this email already exists!';
} else {
$stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (?, ?, ?)");
if ($stmt->execute([$email, $hashed_password, $role])) {
$success = 'Registration successful! You can now <a href="login.php">login</a>.';
} else {
$error = 'Something went wrong. Please try again.';
}
}
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
}
}
?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card mt-5">
<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 endif; ?>
<form 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>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="teacher">Teacher</option>
<option value="student">Student</option>
</select>
</div>
<button type="submit" class="btn btn-primary w-100">Register</button>
</form>
<div class="text-center mt-3">
<p>Already have an account? <a href="login.php">Login here</a></p>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer_login.php'; ?>