<?php
// Include header
include 'includes/header.php';
// Check if the user is an admin
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'director')) {
echo '<div class="alert alert-danger">Access denied. You must be an admin to access this page.</div>';
include 'includes/footer.php';
exit;
}
// Define paths
$target_dir = __DIR__ . '/../assets/img/courses/';
$default_image = $target_dir . 'default.jpg';
// Create directory if it doesn't exist
if (!file_exists($target_dir)) {
if (!mkdir($target_dir, 0777, true)) {
echo '<div class="alert alert-danger">Failed to create directory for course images.</div>';
include 'includes/footer.php';
exit;
}
}
// Create a default course image
$width = 1200;
$height = 600;
$image = imagecreatetruecolor($width, $height);
// Define colors
$bg_color = imagecolorallocate($image, 79, 70, 229); // Primary color #4F46E5
$text_color = imagecolorallocate($image, 255, 255, 255); // White text
$accent_color = imagecolorallocate($image, 99, 102, 241); // Lighter accent color
// Fill background with gradient-like effect
imagefill($image, 0, 0, $bg_color);
// Add some design elements (circles)
for ($i = 0; $i < 8; $i++) {
$circle_x = mt_rand(0, $width);
$circle_y = mt_rand(0, $height);
$circle_size = mt_rand(50, 200);
imagefilledellipse($image, $circle_x, $circle_y, $circle_size, $circle_size, $accent_color);
}
// Add text
$text = "Course Image";
$font_size = 5;
$font_path = __DIR__ . '/fonts/arial.ttf';
// Use TrueType font if available
if (file_exists($font_path)) {
// Calculate position for centered text
$bbox = imagettfbbox(40, 0, $font_path, $text);
$text_width = $bbox[2] - $bbox[0];
$text_x = ($width - $text_width) / 2;
$text_y = ($height / 2) + 20;
imagettftext($image, 40, 0, $text_x, $text_y, $text_color, $font_path, $text);
} else {
// Fallback to built-in font
$text_width = imagefontwidth($font_size) * strlen($text);
$text_x = ($width - $text_width) / 2;
$text_y = ($height / 2);
imagestring($image, $font_size, $text_x, $text_y, $text, $text_color);
}
// Save image
imagejpeg($image, $default_image, 90);
imagedestroy($image);
// Output success message
?>
<div class="container mt-5">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>Default Course Image Created</h4>
</div>
<div class="card-body">
<div class="alert alert-success">
<p>The default course image has been created successfully!</p>
</div>
<div class="text-center my-4">
<img src="../assets/img/courses/default.jpg" alt="Default Course Image" class="img-fluid rounded shadow-sm" style="max-width: 500px;">
</div>
<div class="mt-4">
<p>This image will be used as a fallback when no specific course image is available.</p>
<p>Path: <code>assets/img/courses/default.jpg</code></p>
</div>
<div class="text-center mt-4">
<a href="index.php" class="btn btn-primary">Return to Dashboard</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include 'includes/footer.php';
?>