<?php require_once('connection.php') ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : Add Holiday</title>
    <?php include("headerlink.php")?>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
        integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <link rel="stylesheet" href="./fullcalendar/lib/main.min.css">
    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script src="./fullcalendar/lib/main.min.js"></script>
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">

        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>

        <?php include("navbar.php")?>

        <?php include("sidebar.php")?>

        <div class="content-wrapper">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 text-uppercase" style="font-weight:bold">Add Events</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Add Events</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card shadow">
                                <div class="card-header" style="background: #343a40;">
                                    <h3 class="card-title  text-white fw-bold text-uppercase">Add Evnets</h3>
                                </div>

                                <div class="container py-5" id="page-container">
                                    <div class="row">
                                        <div class="col-md-9">
                                            <div id="calendar" class="shadow p-5 "></div>
                                        </div>
                                        <div class="col-md-3 ">
                                            <div class="cardt rounded-0 shadow">
                                                <div class="card-header bg-gradient bg-primary text-light">
                                                    <h5 class="card-title text-uppercase fw-bold">Schedule Form</h5>
                                                </div>
                                                <div class="card-body">
                                                    <div class="container-fluid ">
                                                        <form action="save_schedule.php" method="post"
                                                            id="schedule-form">
                                                            <input type="hidden" name="id" value="">
                                                            <div class="form-group mb-2">
                                                                <label for="title" class="control-label">Title</label>
                                                                <select for="title" name="title" class="form-control">
                                                                    <option value="Text">Text</option>
                                                                    <option value="Call">Call</option>
                                                                    <option value="Email">Email</option>
                                                                    <option value="Other">Other</option>
                                                                </select>
                                                            </div>
                                                            <div class="form-group mb-2">
                                                                <label for="description"
                                                                    class="control-label">Description</label>
                                                                <textarea rows="3"
                                                                    class="form-control form-control-sm rounded-0"
                                                                    name="description" id="description"
                                                                    required></textarea>
                                                            </div>
                                                            <div class="form-group mb-2">
                                                                <label for="start_datetime"
                                                                    class="control-label">Start</label>
                                                                <input type="datetime-local"
                                                                    class="form-control form-control-sm rounded-0"
                                                                    name="start_datetime" id="start_datetime" required>
                                                            </div>
                                                            <div class="form-group mb-2">
                                                                <label for="end_datetime"
                                                                    class="control-label">End</label>
                                                                <input type="datetime-local"
                                                                    class="form-control form-control-sm rounded-0"
                                                                    name="end_datetime" id="end_datetime" required>
                                                            </div>
                                                        </form>
                                                    </div>
                                                </div>
                                                <div class="card-footer">
                                                    <div class="text-center">
                                                        <button class="btn btn-primary btn-sm rounded-0" type="submit"
                                                            form="schedule-form"><i class="fa fa-save"></i>
                                                            Save</button>
                                                        <button class="btn btn-default border btn-sm rounded-0"
                                                            type="reset" form="schedule-form"><i
                                                                class="fa fa-reset"></i> Cancel</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="modal fade" tabindex="-1" data-bs-backdrop="static"
                                    id="event-details-modal">
                                    <div class="modal-dialog modal-dialog-centered">
                                        <div class="modal-content rounded-0">
                                            <div class="modal-header rounded-0 bg-dark">
                                                <h5 class="modal-title fw-bold text-uppercase">Schedule Details</h5>
                                                <button type="button" class="btn-close bg-white rounded-circle"
                                                    data-bs-dismiss="modal" aria-label="Close"></button>
                                            </div>
                                            <div class="modal-body rounded-0">
                                                <div class="container-fluid">
                                                    <dl>
                                                        <dt class="text-muted">Title</dt>
                                                        <dd id="title" class="fw-bold fs-4"></dd>
                                                        <dt class="text-muted">Description</dt>
                                                        <dd id="description" class=""></dd>
                                                        <dt class="text-muted">Start</dt>
                                                        <dd id="start" class=""></dd>
                                                        <dt class="text-muted">End</dt>
                                                        <dd id="end" class=""></dd>
                                                    </dl>
                                                </div>
                                            </div>
                                            <div class="modal-footer rounded-0">
                                                <div class="text-end">
                                                    <button type="button" class="btn btn-primary btn-sm rounded-0"
                                                        id="edit" data-id="">Edit</button>
                                                    <button type="button" class="btn btn-danger btn-sm rounded-0"
                                                        id="delete" data-id="">Delete</button>
                                                    <button type="button" class="btn btn-secondary btn-sm rounded-0"
                                                        data-bs-dismiss="modal">Close</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>

                    </div>

                </div>
            </section>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="card shadow">
                                <div class="card-header" style="background: #343a40; ">
                                    <h3 class="card-title text-white text-bold text-uppercase">View All Events</h3>
                                </div>

                                <div class="card-body">
                                    <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                                        <div class="row">
                                            <div class="col-sm-12 col-md-6"></div>
                                            <div class="col-sm-12 col-md-6"></div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <table class="table-responsive">
                                                    <table id="example2"
                                                        class="table table-bordered text-center table-hover dataTable dtr-inline display"
                                                        aria-describedby="example2_info">
                                                        <thead>
                                                            <tr>
                                                                <th>Sr No.</th>
                                                                <th>Title</th>
                                                                <th>Description</th>
                                                                <th>Start Datetime</th>
                                                                <th>End Datetime</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                            include('connection.php');
                                                            $sql = "SELECT * FROM schedule_list ";
                                                            $query = mysqli_query($conn, $sql);
                                                            while ($row = mysqli_fetch_assoc($query)) {
                                                            ?>
                                                            <tr>
                                                                <td><?php echo $row['id']?></td>
                                                                <td><?php echo $row['title']?></td>
                                                                <td><?php echo $row['description']?></td>
                                                                <td><?php echo $row['start_datetime']?></td>
                                                                <td><?php echo $row['end_datetime']?></td>
                                                            </tr>
                                                            <?php }?>
                                                        </tbody>

                                                    </table>
                                                </table>
                                            </div>
                                        </div>

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>
        </div>

        <?php include("footer.php")?>


    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <?php 
    $schedules = $conn->query("SELECT * FROM `schedule_list`");
    $sched_res = [];
    foreach($schedules->fetch_all(MYSQLI_ASSOC) as $row){
        $row['sdate'] = date("F d, Y h:i A",strtotime($row['start_datetime']));
        $row['edate'] = date("F d, Y h:i A",strtotime($row['end_datetime']));
        $sched_res[$row['id']] = $row;
    }
?>
    <?php 
if(isset($conn)) $conn->close();
?>
</body>
<script>
var scheds = $.parseJSON('<?= json_encode($sched_res) ?>')
</script>
<script src="./js/script.js"></script>
<script>
$(document).ready(function() {
    <?php if (isset($_GET['error'])) { ?>
    Swal.fire({
        title: 'Error',
        text: '<?php echo $_GET['error']; ?>',
        icon: 'error',
        confirmButtonText: 'OK',
        confirmButtonClass: 'btn btn-success btn-lg',
    });
    <?php } ?>
    <?php if (isset($_GET['success'])) { ?>
    Swal.fire({
        title: 'Success',
        text: '<?php echo $_GET['success']; ?>',
        icon: 'success',
        confirmButtonText: 'OK',
        confirmButtonClass: 'btn btn-success btn-lg',
    });
    <?php } ?>
});
</script>
<script>
var $j = jQuery.noConflict();
$j(document).ready(function() {
    $j('#example2').DataTable();
});
</script>

<?php include("footerlink.php")?>
</body>

</html>