commit ddf6a87ef757bb4ff24afe34c4b643936fb84004 Author: Flatlogic Bot Date: Thu Sep 4 20:39:54 2025 +0000 Initial version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e427ff3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +*/node_modules/ +*/build/ diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e2bbc23 --- /dev/null +++ b/.htaccess @@ -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] diff --git a/.perm_test_apache b/.perm_test_apache new file mode 100644 index 0000000..e69de29 diff --git a/.perm_test_exec b/.perm_test_exec new file mode 100644 index 0000000..e69de29 diff --git a/db/config.php b/db/config.php new file mode 100644 index 0000000..0542cfa --- /dev/null +++ b/db/config.php @@ -0,0 +1,17 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); + } + return $pdo; +} diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..fb3b622 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,49 @@ +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(); +} diff --git a/db/migrations/001_initial_schema.sql b/db/migrations/001_initial_schema.sql new file mode 100644 index 0000000..7ef8381 --- /dev/null +++ b/db/migrations/001_initial_schema.sql @@ -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; diff --git a/index.php b/index.php new file mode 100644 index 0000000..9e12601 --- /dev/null +++ b/index.php @@ -0,0 +1,34 @@ + + +

Welcome to your Learning Dashboard

+

This is your central hub for managing your educational experience.

+ +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 "

Could not determine user role.

"; +} + +if ($role === 'admin') { + echo '

As an administrator, you can manage all aspects of the platform from the Admin Dashboard.

'; +} elseif ($role === 'instructor') { + echo '

As an instructor, you can manage your courses and students.

'; +} else { + echo '

As a student, you can view your enrolled courses and track your progress.

'; +} +?> + +