[
'name' => 'ID Card Template',
'file_path' => '../templates/id_card.png',
'preview_path' => SITE_URL . '/templates/id_card.png',
'type' => 'image/png',
'description' => 'Template for generating member ID cards',
'label' => 'ID Card Template',
'icon' => 'id-card',
'priority' => false
],
'certificate' => [
'name' => 'Certificate Template',
'file_path' => '../templates/certificate-template.png',
'preview_path' => SITE_URL . '/templates/certificate-template.png',
'type' => 'image/png',
'description' => 'Template for generating certificates',
'label' => 'Certificate Template',
'icon' => 'certificate',
'priority' => false
],
'participation_certificate' => [
'name' => 'Participation Certificate Template',
'file_path' => '../templates/participation-certificate-template.png',
'preview_path' => SITE_URL . '/templates/participation-certificate-template.png',
'type' => 'image/png',
'description' => 'Template for generating participation certificates',
'label' => 'Participation Certificate Template',
'icon' => 'certificate',
'priority' => false
],
'logo' => [
'name' => 'Organization Logo',
'file_path' => '../img/logo.png',
'preview_path' => SITE_URL . '/img/logo.png',
'type' => 'image/png',
'description' => 'Logo used in receipts and documents',
'label' => 'Organization Logo',
'icon' => 'image',
'priority' => true
],
'signature' => [
'name' => 'Authorized Signature',
'file_path' => '../img/signature.png',
'preview_path' => SITE_URL . '/img/signature.png',
'type' => 'image/png',
'description' => 'Signature used in receipts and certificates',
'label' => 'Authorized Signature',
'icon' => 'signature',
'priority' => true
],
'signature1' => [
'name' => 'Chief Secretary Signature',
'file_path' => '../img/signature1.png',
'preview_path' => SITE_URL . '/img/signature1.png',
'type' => 'image/png',
'description' => 'Chief Secretary signature used in certificates',
'label' => 'Chief Secretary Signature',
'icon' => 'signature',
'priority' => true
],
'qr_code' => [
'name' => 'QR Code',
'file_path' => '../img/qr_code.png',
'preview_path' => SITE_URL . '/img/qr_code.png',
'type' => 'image/png',
'description' => 'QR code for payments',
'label' => 'QR Code',
'icon' => 'qrcode',
'priority' => false
],
'letterhead' => [
'name' => 'Letterhead',
'file_path' => '../img/letterhead.png',
'preview_path' => SITE_URL . '/img/letterhead.png',
'type' => 'image/png',
'description' => 'Official letterhead for documents',
'label' => 'Letterhead',
'icon' => 'file-alt',
'priority' => false,
'hidden' => true
],
'watermark' => [
'name' => 'Watermark',
'file_path' => '../img/watermark.png',
'preview_path' => SITE_URL . '/img/watermark.png',
'type' => 'image/png',
'description' => 'Document watermark',
'label' => 'Watermark',
'icon' => 'tint',
'priority' => false,
'hidden' => true
],
'seal' => [
'name' => 'Seal/Stamp',
'file_path' => '../img/seal.png',
'preview_path' => SITE_URL . '/img/seal.png',
'type' => 'image/png',
'description' => 'Official seal or stamp',
'label' => 'Seal/Stamp',
'icon' => 'stamp',
'priority' => false
]
];
// Cache file information to avoid repeated file system calls
$fileCache = [];
function getFileInfo($filePath) {
global $fileCache;
if (!isset($fileCache[$filePath])) {
$fileCache[$filePath] = [
'exists' => file_exists($filePath),
'size' => file_exists($filePath) ? filesize($filePath) : 0,
'modified' => file_exists($filePath) ? filemtime($filePath) : 0
];
}
return $fileCache[$filePath];
}
// Handle template upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upload_template') {
$template_type = sanitizeInput($_POST['template_type'] ?? '');
if (!array_key_exists($template_type, $templates)) {
$error = "Invalid template type.";
} elseif (isset($_FILES['template_file']) && $_FILES['template_file']['error'] === UPLOAD_ERR_OK) {
try {
$file = $_FILES['template_file'];
$file_ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$allowed_extensions = ['png', 'jpg', 'jpeg'];
// Validate file extension
if (!in_array($file_ext, $allowed_extensions)) {
throw new Exception("Only PNG, JPG, and JPEG files are allowed.");
}
// Validate file size (max 5MB)
$max_size = 5 * 1024 * 1024; // 5MB
if ($file['size'] > $max_size) {
throw new Exception("File size must not exceed 5MB.");
}
// Validate image dimensions (optional)
$image_info = getimagesize($file['tmp_name']);
if (!$image_info) {
throw new Exception("The uploaded file is not a valid image.");
}
// Create directories if they don't exist
$upload_dir = dirname($templates[$template_type]['file_path']);
if (!is_dir($upload_dir)) {
if (!mkdir($upload_dir, 0755, true)) {
throw new Exception("Unable to create template directory.");
}
}
$file_path = $templates[$template_type]['file_path'];
// Create backup of existing template
if (file_exists($file_path)) {
$backup_path = $file_path . '.backup.' . date('Y-m-d-H-i-s');
copy($file_path, $backup_path);
unlink($file_path);
}
// Move uploaded file
if (!move_uploaded_file($file['tmp_name'], $file_path)) {
throw new Exception("Failed to upload template file.");
}
// Set proper permissions
chmod($file_path, 0644);
// Clear cache for this file
unset($fileCache[$file_path]);
$success = "Template successfully uploaded!";
header("Location: template.php?success=" . urlencode($success));
exit;
} catch (Exception $e) {
$error = "Error uploading template: " . $e->getMessage();
}
} else {
$upload_error_messages = [
UPLOAD_ERR_INI_SIZE => 'The file exceeds the maximum size set in PHP configuration.',
UPLOAD_ERR_FORM_SIZE => 'The file exceeds the maximum size set in the HTML form.',
UPLOAD_ERR_PARTIAL => 'The file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Temporary folder is missing.',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.'
];
$upload_error = $_FILES['template_file']['error'] ?? UPLOAD_ERR_NO_FILE;
$error = $upload_error_messages[$upload_error] ?? "Unknown error occurred during file upload.";
}
}
$pageTitle = "Template Management";
include 'includes/header.php';
?>
Loading...
Templates are loading...
$a['priority'];
});
foreach ($templates as $type => $template):
if (isset($template['hidden']) && $template['hidden']) continue;
$fileInfo = getFileInfo($template['file_path']);
?>
Last Updated:
File Available
No available
Required for receipt and certificate generation
File Status Summary
-
Logo File:
(/img/logo.png)
-
Signature File:
(/img/signature.png)
-
Chief Secretary Signature:
(/img/signature1.png)
-
ID Card Template:
-
Certificate Template:
-
Participation Certificate Template:
Warning: Logo and both signature files are required for receipt and certificate generation. Please upload them.
Congratulations! All required files are available. Receipt and certificate generation will work correctly.