Initial version

This commit is contained in:
Flatlogic Bot 2025-09-04 20:39:54 +00:00
commit ddf6a87ef7
8 changed files with 186 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules/
*/node_modules/
*/build/

18
.htaccess Normal file
View File

@ -0,0 +1,18 @@
DirectoryIndex index.php index.html
Options -Indexes
Options -MultiViews
RewriteEngine On
# 0) Serve existing files/directories as-is
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# 1) Internal map: /page or /page/ -> /page.php (if such PHP file exists)
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# 2) Optional: strip trailing slash for non-directories (keeps .php links working)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]

0
.perm_test_apache Normal file
View File

0
.perm_test_exec Normal file
View File

17
db/config.php Normal file
View File

@ -0,0 +1,17 @@
<?php
// Generated by setup_mariadb_project.sh — edit as needed.
define('DB_HOST', '127.0.0.1');
define('DB_NAME', 'app_33890');
define('DB_USER', 'app_33890');
define('DB_PASS', '400e495e-0bbc-447f-b58a-12e9808e995a');
function db() {
static $pdo;
if (!$pdo) {
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
}
return $pdo;
}

49
db/migrate.php Normal file
View File

@ -0,0 +1,49 @@
<?php
require_once __DIR__ . '/config.php';
function run_migrations() {
$pdo = db();
// 1. Create migrations table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS `migrations` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`migration_file` VARCHAR(255) NOT NULL UNIQUE,
`applied_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
// 2. Get all migration files
$migration_files = glob(__DIR__ . '/migrations/*.sql');
// 3. Get already applied migrations
$stmt = $pdo->query("SELECT `migration_file` FROM `migrations`");
$applied_migrations = $stmt->fetchAll(PDO::FETCH_COLUMN);
echo "Starting migrations...\n";
// 4. Apply pending migrations
foreach ($migration_files as $file) {
$filename = basename($file);
if (!in_array($filename, $applied_migrations)) {
echo "Applying migration: {$filename}...\n";
// Execute the SQL file
$sql = file_get_contents($file);
$pdo->exec($sql);
// Record the migration
$stmt = $pdo->prepare("INSERT INTO `migrations` (`migration_file`) VALUES (?)");
$stmt->execute([$filename]);
echo " ...applied successfully.\n";
} else {
echo "Migration already applied: {$filename}\n";
}
}
echo "Migrations finished.\n";
}
// Run migrations if the script is executed directly
if (php_sapi_name() === 'cli' && basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
run_migrations();
}

View File

@ -0,0 +1,65 @@
-- 001_initial_schema.sql
-- Table for user roles
CREATE TABLE IF NOT EXISTS `roles` (
`role_id` INT AUTO_INCREMENT PRIMARY KEY,
`role_name` VARCHAR(50) NOT NULL UNIQUE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Insert default roles
INSERT IGNORE INTO `roles` (`role_name`) VALUES ('student'), ('instructor'), ('admin');
-- Table for users
CREATE TABLE IF NOT EXISTS `users` (
`user_id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL UNIQUE,
`password_hash` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`role_id` INT,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`role_id`) REFERENCES `roles`(`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Table for courses
CREATE TABLE IF NOT EXISTS `courses` (
`course_id` INT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`description` TEXT,
`instructor_id` INT,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`instructor_id`) REFERENCES `users`(`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Table for enrollments
CREATE TABLE IF NOT EXISTS `enrollments` (
`enrollment_id` INT AUTO_INCREMENT PRIMARY KEY,
`student_id` INT,
`course_id` INT,
`enrollment_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`student_id`) REFERENCES `users`(`user_id`) ON DELETE CASCADE,
FOREIGN KEY (`course_id`) REFERENCES `courses`(`course_id`) ON DELETE CASCADE,
UNIQUE KEY `student_course_unique` (`student_id`, `course_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Table for discussion posts
CREATE TABLE IF NOT EXISTS `discussion_posts` (
`post_id` INT AUTO_INCREMENT PRIMARY KEY,
`course_id` INT NOT NULL,
`user_id` INT NOT NULL,
`parent_post_id` INT NULL,
`post_content` TEXT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`course_id`) REFERENCES `courses`(`course_id`) ON DELETE CASCADE,
FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`) ON DELETE CASCADE,
FOREIGN KEY (`parent_post_id`) REFERENCES `discussion_posts`(`post_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Table for grades
CREATE TABLE IF NOT EXISTS `grades` (
`grade_id` INT AUTO_INCREMENT PRIMARY KEY,
`enrollment_id` INT NOT NULL,
`grade` DECIMAL(5, 2) NOT NULL,
`comments` TEXT,
`assessment_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`enrollment_id`) REFERENCES `enrollments`(`enrollment_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

34
index.php Normal file
View File

@ -0,0 +1,34 @@
<?php
require_once 'includes/header.php';
// Redirect to login page if user is not logged in
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
?>
<h1>Welcome to your Learning Dashboard</h1>
<p>This is your central hub for managing your educational experience.</p>
<?php
// Example of showing different content based on role
$role = '';
try {
$stmt = db()->prepare("SELECT r.role_name FROM users u JOIN roles r ON u.role_id = r.role_id WHERE u.user_id = ?");
$stmt->execute([$_SESSION['user_id']]);
$role = $stmt->fetchColumn();
} catch (PDOException $e) {
echo "<p style='color:red'>Could not determine user role.</p>";
}
if ($role === 'admin') {
echo '<p>As an administrator, you can manage all aspects of the platform from the <a href="admin.php">Admin Dashboard</a>.</p>';
} elseif ($role === 'instructor') {
echo '<p>As an instructor, you can manage your <a href="courses.php">courses</a> and students.</p>';
} else {
echo '<p>As a student, you can view your enrolled <a href="courses.php">courses</a> and track your progress.</p>';
}
?>
<?php require_once 'includes/footer.php'; ?>