<!-- DataTable JS init -->
<script>
    $(document).ready(function(){
        $('#myTable').DataTable();
    });
</script>
<!-- SweetAlert Trigger -->
<script>
    <?php if (!empty($msg)) { ?>
        Swal.fire({
            position: 'center',
            icon: '<?php echo $alert_type; ?>',
            title: '<?php echo addslashes($msg); ?>',
            showConfirmButton: true,
            confirmButtonText: 'Okay',
        }).then(() => {
            <?php if (!empty($redirect_url)) { ?>
                window.location.href = '<?php echo $redirect_url; ?>';
            <?php } ?>
        });
    <?php } ?>
</script>

<?php
$msg = $_SESSION['msg'] ?? '';
$type = $_SESSION['type'] ?? '';
$redirect_url = $_SESSION['redirect_url'] ?? '';
?>

<!-- SweetAlert Trigger -->
<script>
    <?php if (!empty($msg)) { ?>
        Swal.fire({
            position: 'center',
            icon: '<?php echo $type; ?>',
            title: '<?php echo addslashes($msg); ?>',
            showConfirmButton: true,
            confirmButtonText: 'Okay',
        }).then(() => {
            <?php if (!empty($redirect_url)) { ?>
                window.location.href = '<?php echo $redirect_url; ?>';
            <?php } ?>
        });
    <?php } ?>
</script>
<?php
unset($_SESSION['msg'], $_SESSION['type'], $_SESSION['redirect_url']);
?>
<script>
  $(document).ready(function(){
    $('.datepicker').datepicker({
      format: 'dd/mm/yyyy',
      autoclose: true,
      todayHighlight: true,
      endDate: "0d"
    });
  });
</script>

<!-- JavaScript to preview uploaded image -->
<script>
function previewImage(event) {
    const reader = new FileReader();
    reader.onload = function(){
        const output = document.getElementById('preview');
        output.src = reader.result;
    };
    reader.readAsDataURL(event.target.files[0]);
}
</script>
