2026-01-01 19:00:42 -05:00
|
|
|
<?php
|
|
|
|
|
session_start();
|
2026-01-01 19:18:57 -05:00
|
|
|
require_once dirname(__DIR__) . '/config/config.php';
|
2026-01-01 19:00:42 -05:00
|
|
|
require_once dirname(__DIR__) . '/models/TemplateModel.php';
|
|
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
|
|
// Check authentication
|
|
|
|
|
if (!isset($_SESSION['user']) || !isset($_SESSION['user']['user_id'])) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Not authenticated']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get template ID from query parameter
|
|
|
|
|
$templateId = $_GET['template_id'] ?? null;
|
|
|
|
|
|
|
|
|
|
if (!$templateId) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Template ID required']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create database connection
|
|
|
|
|
$conn = new mysqli(
|
|
|
|
|
$GLOBALS['config']['DB_HOST'],
|
|
|
|
|
$GLOBALS['config']['DB_USER'],
|
|
|
|
|
$GLOBALS['config']['DB_PASS'],
|
|
|
|
|
$GLOBALS['config']['DB_NAME']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($conn->connect_error) {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Database connection failed']);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get template
|
|
|
|
|
$templateModel = new TemplateModel($conn);
|
|
|
|
|
$template = $templateModel->getTemplateById($templateId);
|
|
|
|
|
|
|
|
|
|
$conn->close();
|
|
|
|
|
|
|
|
|
|
if ($template) {
|
|
|
|
|
echo json_encode(['success' => true, 'template' => $template]);
|
|
|
|
|
} else {
|
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Template not found']);
|
|
|
|
|
}
|