Sindbad~EG File Manager
<?php
require_once '../config/config.php';
// Check if user is logged in
if (!isLoggedIn()) {
redirect('login.php');
}
$db = new Database();
$conn = $db->getConnection();
$template_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$template_id) {
echo '<div class="p-4 text-red-600">Invalid template ID</div>';
exit;
}
// Get form template
$query = "SELECT * FROM form_templates WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->execute([$template_id]);
$template = $stmt->fetch();
if (!$template) {
echo '<div class="p-4 text-red-600">Template not found</div>';
exit;
}
$fields = json_decode($template['fields'], true) ?: [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Preview: <?php echo htmlspecialchars($template['name']); ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3B82F6',
secondary: '#F59E0B',
accent: '#6B7280'
}
}
}
}
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
.gradient-bg {
background: linear-gradient(135deg, #3B82F6 0%, #F59E0B 50%, #6B7280 100%);
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Header -->
<header class="gradient-bg text-white py-6">
<div class="container mx-auto px-4">
<div class="flex items-center justify-between">
<div>
<h1 class="text-2xl font-bold">Form Preview</h1>
<p class="text-white/80"><?php echo htmlspecialchars($template['name']); ?></p>
</div>
<button onclick="window.close()" class="bg-white/20 hover:bg-white/30 px-4 py-2 rounded-lg transition duration-300">
<i class="fas fa-times mr-2"></i>Close
</button>
</div>
</div>
</header>
<!-- Form Preview -->
<main class="container mx-auto px-4 py-8">
<div class="max-w-2xl mx-auto">
<div class="bg-white rounded-lg shadow-lg p-8">
<div class="mb-6">
<h2 class="text-2xl font-bold text-gray-900 mb-2"><?php echo htmlspecialchars($template['name']); ?></h2>
<?php if ($template['description']): ?>
<p class="text-gray-600"><?php echo htmlspecialchars($template['description']); ?></p>
<?php endif; ?>
</div>
<form class="space-y-6">
<?php foreach ($fields as $field): ?>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">
<?php echo htmlspecialchars($field['label']); ?>
<?php if ($field['required']): ?>
<span class="text-red-500">*</span>
<?php endif; ?>
</label>
<?php if ($field['type'] === 'textarea'): ?>
<textarea
name="<?php echo htmlspecialchars($field['name']); ?>"
rows="4"
<?php echo $field['required'] ? 'required' : ''; ?>
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Enter <?php echo htmlspecialchars($field['label']); ?>"></textarea>
<?php elseif ($field['type'] === 'select'): ?>
<select
name="<?php echo htmlspecialchars($field['name']); ?>"
<?php echo $field['required'] ? 'required' : ''; ?>
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent">
<option value="">Select <?php echo htmlspecialchars($field['label']); ?></option>
<?php if (isset($field['options']) && is_array($field['options'])): ?>
<?php foreach ($field['options'] as $option): ?>
<option value="<?php echo htmlspecialchars($option); ?>">
<?php echo htmlspecialchars($option); ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php elseif ($field['type'] === 'radio'): ?>
<div class="space-y-2">
<?php if (isset($field['options']) && is_array($field['options'])): ?>
<?php foreach ($field['options'] as $index => $option): ?>
<label class="flex items-center">
<input
type="radio"
name="<?php echo htmlspecialchars($field['name']); ?>"
value="<?php echo htmlspecialchars($option); ?>"
<?php echo $field['required'] ? 'required' : ''; ?>
class="h-4 w-4 text-primary focus:ring-primary border-gray-300">
<span class="ml-2 text-sm text-gray-700"><?php echo htmlspecialchars($option); ?></span>
</label>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php else: ?>
<input
type="<?php echo htmlspecialchars($field['type']); ?>"
name="<?php echo htmlspecialchars($field['name']); ?>"
<?php echo $field['required'] ? 'required' : ''; ?>
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent"
placeholder="Enter <?php echo htmlspecialchars($field['label']); ?>">
<?php endif; ?>
</div>
<?php endforeach; ?>
<div class="pt-6 border-t">
<button type="button" class="w-full bg-primary text-white py-3 px-6 rounded-lg hover:bg-blue-700 transition duration-300 font-semibold" disabled>
<i class="fas fa-paper-plane mr-2"></i>Submit (Preview Only)
</button>
<p class="text-sm text-gray-500 text-center mt-2">
This is a preview. The form is not functional.
</p>
</div>
</form>
</div>
<!-- Template Info -->
<div class="mt-6 bg-blue-50 border border-blue-200 rounded-lg p-4">
<h3 class="font-semibold text-blue-900 mb-2">
<i class="fas fa-info-circle mr-2"></i>Template Information
</h3>
<div class="text-sm text-blue-800 space-y-1">
<p><strong>Name:</strong> <?php echo htmlspecialchars($template['name']); ?></p>
<p><strong>Status:</strong> <?php echo $template['is_active'] ? 'Active' : 'Inactive'; ?></p>
<p><strong>Fields:</strong> <?php echo count($fields); ?> total fields</p>
<p><strong>Created:</strong> <?php echo date('F j, Y g:i A', strtotime($template['created_at'])); ?></p>
</div>
</div>
</div>
</main>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists