Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/update_form_template.php

<?php
require_once '../config/config.php';

// Check if user is logged in and is superuser
if (!isLoggedIn() || !hasRole('superuser')) {
    die('Access denied. Superuser required.');
}

$db = new Database();
$conn = $db->getConnection();

echo "<h2>Update Form Template - Remove Age Group Field</h2>";

try {
    // Get current form template
    $query = "SELECT * FROM form_templates WHERE is_active = 1 ORDER BY created_at DESC LIMIT 1";
    $stmt = $conn->prepare($query);
    $stmt->execute();
    $template = $stmt->fetch();
    
    if ($template) {
        $fields = json_decode($template['fields'], true);
        
        echo "<h3>Current Form Fields:</h3>";
        echo "<ul>";
        foreach ($fields as $field) {
            echo "<li>{$field['label']} ({$field['name']}) - {$field['type']}</li>";
        }
        echo "</ul>";
        
        // Remove age_group field
        $updated_fields = array_filter($fields, function($field) {
            return $field['name'] !== 'age_group';
        });
        
        // Re-index array to avoid gaps
        $updated_fields = array_values($updated_fields);
        
        // Update the form template
        $update_query = "UPDATE form_templates SET fields = ? WHERE id = ?";
        $stmt = $conn->prepare($update_query);
        $stmt->execute([json_encode($updated_fields), $template['id']]);
        
        echo "<h3 style='color: green;'>✓ Form template updated successfully!</h3>";
        echo "<h3>Updated Form Fields:</h3>";
        echo "<ul>";
        foreach ($updated_fields as $field) {
            echo "<li>{$field['label']} ({$field['name']}) - {$field['type']}</li>";
        }
        echo "</ul>";
        
        // Log activity
        logActivity($_SESSION['user_id'], 'update_form_template', 'Removed age_group field from form template');
        
    } else {
        echo "<p style='color: red;'>No active form template found.</p>";
    }
    
    echo "<p><a href='dashboard.php'>← Back to Dashboard</a></p>";
    echo "<p><a href='../attendance/form.php?program=1'>→ Test Updated Form</a></p>";
    
} catch (Exception $e) {
    echo "<p style='color: red;'>Error: " . $e->getMessage() . "</p>";
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists