Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/pages/emeraadmin/
Upload File :
Current File : /home/emeraadmin/public_html/pages/emeraadmin/exportScheduleData.php

<?php
include('head.php');
require_once '../../Service/ScheduleService.php';

$scheduleService = new ScheduleService();

// Fetch all schedules for the dropdown
$schedules = $scheduleService->getAllSchedules();
?>

<div class="main-content">
    <div class="container-fluid">
        <div class="page-header">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                        <i class="ik ik-layers bg-blue"></i>
                        <div class="d-inline">
                            <h5>Select Schedule to Export Summary</h5>
                            <span>Select a schedule to export its summary up to today.</span>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="#"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item">
                                <a href="#">Tasks</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">Export Summary</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Selection Form -->
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label for="schedule_id">Select Schedule:</label>
                    <select name="schedule_id" id="schedule_id" class="form-control">
                        <option value="">-- Select Schedule --</option>
                        <?php foreach ($schedules as $schedule) { ?>
                            <option value="<?php echo $schedule->id; ?>"><?php echo htmlspecialchars($schedule->schedule_name); ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>

        <!-- Export Box -->
        <div class="row" id="export_box" style="display: none;">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Export Summary</h5>
                        <p class="card-text">Click the button below to export the selected schedule summary.</p>
                        <button id="export_summary" class="btn btn-success">Export Summary</button>
                    </div>
                </div>
                <div id="export_message" class="mt-2 text-danger" style="display: none;">Please select a schedule to export.</div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const scheduleSelect = document.getElementById('schedule_id');
        const exportBox = document.getElementById('export_box');
        const exportButton = document.getElementById('export_summary');
        const exportMessage = document.getElementById('export_message');

        scheduleSelect.addEventListener('change', function() {
            if (scheduleSelect.value) {
                exportBox.style.display = 'block';
                exportMessage.style.display = 'none';
            } else {
                exportBox.style.display = 'none';
                exportMessage.style.display = 'block';
            }
        });

        exportButton.addEventListener('click', function() {
            if (!scheduleSelect.value) {
                exportMessage.style.display = 'block';
            } else {
                const scheduleId = scheduleSelect.value;
                window.location.href = `export_schedule.php?schedule_id=${scheduleId}`;
            }
        });

        // Initialize the state based on the current selection
        if (scheduleSelect.value) {
            exportBox.style.display = 'block';
        } else {
            exportBox.style.display = 'none';
        }
    });
</script>

<?php include('footer.php'); ?>