Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/4d695/
Upload File :
Current File : /home/emeraadmin/public_html/4d695/viewsubtask.php.tar

home/emeraadmin/public_html/pages/emeraadmin/viewsubtask.php000064400000046712151677421410020403 0ustar00<?php include('head.php'); ?>
<?php
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';
require_once '../../Service/UserService.php';
require_once '../../Classes/System.php';

$System = new System();
$subtaskService = new SubtaskService();
$userService = new UserService();

if (!isset($_GET['id'])) {
    echo '<p>No subtask ID provided.</p>';
    exit;
}

$subtaskId = $System->decryptData($_GET['id']);
// show error if the provided id is not valid with Swal alert
if (!$subtaskId) {
    echo '<script>
            Swal.fire({
                title: "Invalid Subtask ID",
                text: "The URL parameter is invalid. Please go back and try again.",
                icon: "error",
                confirmButtonText: "Ok"
            }).then(() => window.location.href = "viewschedules.php");
        </script>';
    exit;
}


$subtask = $subtaskService->getSubtaskById($subtaskId);
$users = $userService->getAllUsers();


if ($subtask->completed) {
    $submittedLocation = $subtaskService->getSubtaskLocation($subtaskId);
    if ($submittedLocation) {
        $latitude = $submittedLocation->latitude;
        $longitude = $submittedLocation->longitude;
    } else {
        // Handle the case where location is not found
        $latitude = null;
        $longitude = null;
        // Optionally, display an error message or take other actions
        echo "Location not found for the specified subtask.";
    }
}

?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap" async
        defer></script>
<div class="main-content">
    <div class="container-fluid">
        <div class="page-header 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>View Subtask</h5>
                        <span>View details of a subtask</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="../../index.html"><i class="ik ik-home"></i></a></li>
                        <li class="breadcrumb-item"><a href="#">Subtasks</a></li>
                        <li class="breadcrumb-item active" aria-current="page">View Subtask</li>
                    </ol>
                </nav>
            </div>
        </div>

        <div class="card">
            <div class="card-header d-flex justify-content-between">
                <a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
                <div>
                    <?php if (!$subtask->assigned): ?>
                        <button type="button" class="btn btn-primary" id="assignTaskButton">Assign Task to a cleaner
                        </button>
                    <?php endif; ?>
                    <?php if ($subtask->assigned && !$subtask->completed): ?>
                        <button type="button" class="btn btn-primary" id="assignTaskButton">Resend Task to a cleaner
                        </button>
                    <?php endif; ?>

                    <?php if ($subtask->completed): ?>
                        <!--                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#viewTaskCompletionFormModal">View Task Completion Form</button>-->
                    <?php endif; ?>
                </div>
            </div>
            <div class="card-body">
                <div class="row align-items-center mb-30">
                    <div class="col-md-12">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-map-pin icon-large"></i></td>
                                            <td>
                                                <h3 class="mb-0 fw-700 text-black"><?php echo $subtask->service_name; ?></h3>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-calendar icon-large"></i></td>
                                            <td>
                                                <h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_date ? date('F j, Y', strtotime($subtask->subtask_date)) : 'Not set'; ?></h5>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-clock icon-large"></i></td>
                                            <!--                                            Show time in am or pm -->
                                            <td>
                                                <h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_time ? date('g:i A', strtotime($subtask->subtask_time)) : 'Not set'; ?></h5>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td>
                                                <h5 class="mb-0 fw-500 text-black"><?php echo date('F j, Y', strtotime($subtask->updated_at)); ?></h5>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-check-circle icon-large"></i></td>
                                            <td>
                                                <?php
                                                if ($subtask->ignored) {
                                                    echo '<span class="badge badge-yellow">Ignored</span>';
                                                } else {
                                                    if ($subtask->completed) {
                                                        echo '<span class="badge badge-success">Completed</span> ';
                                                    } else {
                                                        echo '<span class="badge badge-danger">Not Completed</span>';
                                                    }
                                                }
                                                ?>
                                            </td>
                                        </tr>
                                        <?php //if ($subtask->completed && $subtask->submitted_by_admin): ?>
                                        <!--                                            <tr>-->
                                        <!--                                                <td><i class="ik ik-calendar icon-large"></i></td>-->
                                        <!--                                                <td><h5 class="mb-0 fw-500 text-black">-->
                                        <?php //echo date('F j, Y, g:i A', strtotime($subtask->completed_at)); ?><!--</h5></td>-->
                                        <!--                                            </tr>-->
                                        <!--                                        --><?php //endif; ?>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td>
                                                <?php if ($subtask->assigned): ?>
                                                    <span class="badge badge-success">Assigned</span>
                                                <?php else: ?>
                                                    <span class="badge badge-danger">Not assigned</span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <?php if ($subtask->assigned): ?>
                                            <tr>
                                                <td><i class="ik ik-mail icon-large"></i></td>
                                                <td>
                                                    <h5 class="mb-0 fw-500 text-black"><?php echo $subtask->assigned_to_Mobile ?: 'Not set'; ?></h5>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><i class="ik ik-check icon-large"></i></td>
                                                <td>
                                                    <h5 class="mb-0 fw-500 text-black"><?php echo $subtask->assigned_Message_Rsponse ? 'Email sent successfully' : 'Unable to send email'; ?></h5>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td><i class="ik ik-file-text icon-large"></i></td>
                                                <td>
                                                    <h5 class="mb-0 fw-500 <?php echo $subtask->form_submission_id ? 'text-primary' : 'text-black'; ?>">
                                                        <?php if ($subtask->form_submission_id): ?>
                                                            <a href="../completedsubtaskform.php?id=<?php echo $subtask->form_submission_id; ?>"
                                                               target="_blank">View Submitted Form</a>
                                                        <?php else: ?>
                                                            <span class="badge badge-warning">Form not submitted</span>
                                                        <?php endif; ?>
                                                    </h5>
                                                </td>
                                            </tr>

                                            <?php if ($subtask->completed && property_exists($subtask, 'submitted_by_admin') && $subtask->submitted_by_admin): ?>
                                                <tr>
                                                    <td><i class="ik ik-user icon-large"></i></td>
                                                    <td><h5 class="mb-0 fw-500 text-black"><span
                                                                    class="badge badge-warning">Marked as completed by admin</span>
                                                        </h5></td>
                                                </tr>
                                            <?php endif; ?>
                                            <?php if ($subtask->form_submission_id): ?>
                                                <tr>
                                                    <td><i class="fas fa-calendar-check icon-large"></i></td>
                                                    <?php
                                                    // Assuming $subtask->completed_at contains the datetime string
                                                    $completedAt = $subtask->completed_at;

                                                    // Create a new DateTime object with the original datetime
                                                    $date = new DateTime($completedAt, new DateTimeZone('UTC'));

                                                    // Set the timezone to Sydney
                                                    $date->setTimezone(new DateTimeZone('Australia/Sydney'));

                                                    // Format the date and time
                                                    $formattedDate = $date->format('F j, Y, g:i a');
                                                    ?>
                                                    <td>
                                                        <h5 class="mb-0 fw-500 text-black"><?php echo $formattedDate; ?></h5>
                                                    </td>
                                                </tr>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <style>
                            table {
                                width: 100%;
                                border-collapse: collapse;
                            }

                            td {
                                padding: 10px 15px;
                                vertical-align: middle;
                            }

                            .icon-large {
                                font-size: 24px;
                                color: #333;
                            }

                            .mb-0 {
                                margin-bottom: 0;
                            }

                            .fw-700 {
                                font-weight: 700;
                            }

                            .fw-500 {
                                font-weight: 500;
                            }

                            .text-black {
                                color: #000;
                            }

                            .badge-success {
                                background-color: #28a745;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }

                            .badge-danger {
                                background-color: #dc3545;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }
                        </style>
                    </div>
                </div>
            </div>
        </div>

        <?php if ($subtask->completed && $latitude !== null && $longitude !== null): ?>
            <div class="card">
                <div class="card-header d-flex justify-content-between">
                    <h3>Submitted Location</h3>
                </div>
                <div class="card-body">
                    <div id="map"></div>
                </div>
            </div>
            <script>
                function initMap() {
                    // Replace these PHP variables with actual PHP values
                    var latitude = <?php echo $latitude; ?>; // PHP variable for latitude
                    var longitude = <?php echo $longitude; ?>; // PHP variable for longitude

                    // Create a map centered at a specific location
                    var map = new google.maps.Map(document.getElementById('map'), {
                        center: {lat: latitude, lng: longitude},
                        zoom: 12 // Adjust zoom level as needed
                    });

                    // Add a marker at the specified location
                    var marker = new google.maps.Marker({
                        position: {lat: latitude, lng: longitude},
                        map: map,
                        title: 'Hello World!' // Marker tooltip (optional)
                    });
                }
            </script>
            <script async defer
                    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap">
            </script>
        <?php endif; ?>

        <script>
            document.getElementById('assignTaskButton').addEventListener('click', function () {
                Swal.fire({
                    title: 'Enter cleaner Email',
                    input: 'email',
                    inputLabel: 'Cleaner Email',
                    inputPlaceholder: 'Enter cleaner email',
                    showCancelButton: true,
                    confirmButtonText: 'Assign Task',
                    showLoaderOnConfirm: true,
                    preConfirm: (email) => {
                        const subtaskIds = <?php echo json_encode([$subtaskId]); ?>;
                        return fetch('../send_email_to_workers.php', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify({
                                action: 'bulk', // or 'single' depending on your logic
                                worker_email: email,
                                subtask_ids: subtaskIds
                            })
                        })
                            .then(response => {
                                if (!response.ok) {
                                    throw new Error('Network response was not ok');
                                }
                                return response.json();
                            })
                            .then(data => {
                                console.log('Response from PHP:', data);
                                // Handle response data accordingly
                                if (data.status === 'success') {
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Task has been assigned successfully',
                                        icon: 'success'
                                    }).then(() => location.reload());
                                } else {
                                    throw new Error(data.message || 'Unknown error');
                                }
                            })
                            .catch(error => {
                                console.error('Fetch error:', error);
                                Swal.showValidationMessage(
                                    `Request failed: ${error.message}`
                                );
                            });
                    },
                    allowOutsideClick: () => !Swal.isLoading()
                });
            });

        </script>


    </div>
</div>
<?php include('footer.php'); ?>
home/emeraadmin/public_html/pages/taskprovider/viewsubtask.php000064400000033201151677422660021013 0ustar00<?php include('head.php'); ?>
<?php
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';
require_once '../../Service/UserService.php';
require_once '../../Classes/System.php';

$System = new System();
$subtaskService = new SubtaskService();
$userService = new UserService();

if (!isset($_GET['id'])) {
    echo '<p>No subtask ID provided.</p>';
    exit;
}

$subtaskId = $System->decryptData($_GET['id']);
// show error if the provided id is not valid with Swal alert
if (!$subtaskId) {
    echo '<script>
            Swal.fire({
                title: "Invalid Subtask ID",
                text: "The URL parameter is invalid. Please go back and try again.",
                icon: "error",
                confirmButtonText: "Ok"
            }).then(() => window.location.href = "viewschedules.php");
        </script>';
    exit;
}


$subtask = $subtaskService->getSubtaskById($subtaskId);
$users = $userService->getAllUsers();


if($subtask->completed){
    $submittedLocation = $subtaskService->getSubtaskLocation($subtaskId);
    if ($submittedLocation) {
        $latitude = $submittedLocation->latitude;
        $longitude = $submittedLocation->longitude;
    } else {
        // Handle the case where location is not found
        $latitude = null;
        $longitude = null;
        // Optionally, display an error message or take other actions
        echo "Location not found for the specified subtask.";
    }
}

?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap" async defer></script>
<div class="main-content">
    <div class="container-fluid">
        <div class="page-header 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>View Subtask</h5>
                        <span>View details of a subtask</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="#">Subtasks</a></li>
                        <li class="breadcrumb-item active" aria-current="page">View Subtask</li>
                    </ol>
                </nav>
            </div>
        </div>

        <div class="card">
            <div class="card-header d-flex justify-content-between">
                <a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
                <div>

                </div>
            </div>
            <div class="card-body">
                <div class="row align-items-center mb-30">
                    <div class="col-md-12">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-layers icon-large"></i></td>
                                            <td><h3 class="mb-0 fw-700 text-black"><?php echo $subtask->service_name; ?></h3></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-calendar icon-large"></i></td>
                                            <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_date ? date('F j, Y', strtotime($subtask->subtask_date)) : 'Not set'; ?></h5></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-clock icon-large"></i></td>
<!--                                            Show time in am or pm -->
                                            <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_time ? date('g:i A', strtotime($subtask->subtask_time)) : 'Not set'; ?></h5></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td><h5 class="mb-0 fw-500 text-black"><?php echo date('F j, Y', strtotime($subtask->updated_at)); ?></h5></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-check-circle icon-large"></i></td>
                                            <td>
                                                <?php
                                                if ($subtask->ignored) {
                                                    echo '<span class="badge badge-yellow">Ignored</span>';
                                                } else {
                                                    if ($subtask->completed) {
                                                        echo '<span class="badge badge-success">Completed</span> ';
                                                    } else {
                                                        echo '<span class="badge badge-danger">Not Completed</span>';
                                                    }
                                                }
                                                ?>
                                            </td>
                                        </tr>
<!--                                        --><?php //if ($subtask->completed): ?>
<!--                                            <tr>-->
<!--                                                <td><i class="ik ik-calendar icon-large"></i></td>-->
<!--                                                <td><h5 class="mb-0 fw-500 text-black">--><?php //echo $subtask->completed_at; ?><!--</h5></td>-->
<!--                                            </tr>-->
<!--                                        --><?php //endif; ?>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td>
                                                <?php if ($subtask->assigned): ?>
                                                    <span class="badge badge-success">Assigned</span>
                                                <?php else: ?>
                                                    <span class="badge badge-danger">Not assigned</span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <?php if ($subtask->assigned): ?>
                                            <tr>
                                                <td><i class="ik ik-file-text icon-large"></i></td>
                                                <td><h5 class="mb-0 fw-500 text-black">
                                                        <?php echo $subtask->form_submission_id ? '<a href="../completedsubtaskform.php?id=' . $subtask->form_submission_id . '" target="_blank" >View Submitted Form</a>' : 'Not Submitted'; ?>
                                                    </h5></td>
                                            </tr>
                                            <?php if ($subtask->completed && property_exists($subtask, 'submitted_by_admin') && $subtask->submitted_by_admin): ?>
                                                <tr>
                                                    <td><i class="ik ik-user icon-large"></i></td>
                                                    <td><h5 class="mb-0 fw-500 text-black"><span class="badge badge-warning">Marked as completed by admin</span></h5></td>
                                                </tr>
                                            <?php endif; ?>
                                            <?php if ($subtask->form_submission_id): ?>
                                                <tr>
                                                    <td><i class="fas fa-calendar-check icon-large"></i></td>
                                                    <?php
                                                    // Assuming $subtask->completed_at contains the datetime string
                                                    $completedAt = $subtask->completed_at;

                                                    // Create a new DateTime object with the original datetime
                                                    $date = new DateTime($completedAt, new DateTimeZone('UTC'));

                                                    // Set the timezone to Sydney
                                                    $date->setTimezone(new DateTimeZone('Australia/Sydney'));

                                                    // Format the date and time
                                                    $formattedDate = $date->format('F j, Y, g:i a');
                                                    ?>
                                                    <td>
                                                        <h5 class="mb-0 fw-500 text-black"><?php echo $formattedDate; ?></h5>
                                                    </td>
                                                </tr>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <style>
                            table {
                                width: 100%;
                                border-collapse: collapse;
                            }
                            td {
                                padding: 10px 15px;
                                vertical-align: middle;
                            }
                            .icon-large {
                                font-size: 24px;
                                color: #333;
                            }
                            .mb-0 {
                                margin-bottom: 0;
                            }
                            .fw-700 {
                                font-weight: 700;
                            }
                            .fw-500 {
                                font-weight: 500;
                            }
                            .text-black {
                                color: #000;
                            }
                            .badge-success {
                                background-color: #28a745;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }
                            .badge-danger {
                                background-color: #dc3545;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }
                        </style>
                    </div>
                </div>
            </div>
        </div>
        <?php if ($subtask->completed && $latitude !== null && $longitude !== null): ?>
            <div class="card">
                <div class="card-header d-flex justify-content-between">
                    <h3>Submitted Location</h3>
                </div>
                <div class="card-body">
                    <div id="map"></div>
                </div>
            </div>
            <script>
                function initMap() {
                    // Replace these PHP variables with actual PHP values
                    var latitude = <?php echo $latitude; ?>; // PHP variable for latitude
                    var longitude = <?php echo $longitude; ?>; // PHP variable for longitude

                    // Create a map centered at a specific location
                    var map = new google.maps.Map(document.getElementById('map'), {
                        center: {lat: latitude, lng: longitude},
                        zoom: 12 // Adjust zoom level as needed
                    });

                    // Add a marker at the specified location
                    var marker = new google.maps.Marker({
                        position: {lat: latitude, lng: longitude},
                        map: map,
                        title: 'Hello World!' // Marker tooltip (optional)
                    });
                }
            </script>
            <script async defer
                    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap">
            </script>
        <?php endif; ?>

    </div>
</div>
<?php include('footer.php'); ?>
home/emeraadmin/public_html/pages/subcontractor/viewsubtask.php000064400000043426151701471030021157 0ustar00<?php include('head.php'); ?>
<?php
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';
require_once '../../Service/UserService.php';
require_once '../../Classes/System.php';

$System = new System();
$subtaskService = new SubtaskService();
$userService = new UserService();

if (!isset($_GET['id'])) {
    echo '<p>No subtask ID provided.</p>';
    exit;
}

$subtaskId = $System->decryptData($_GET['id']);
// show error if the provided id is not valid with Swal alert
if (!$subtaskId) {
    echo '<script>
        Swal.fire({
            title: "Invalid Subtask ID",
            text: "Please check the URL and try again.",
            icon: "error",
            confirmButtonText: "Ok"
        }).then(() => window.location.href = "viewAcceptedTasks.php");
    </script>';
    exit;
}
$subtask = $subtaskService->getSubtaskById($subtaskId);
$users = $userService->getAllUsers();

if ($subtask->completed) {
    $submittedLocation = $subtaskService->getSubtaskLocation($subtaskId);
    if ($submittedLocation) {
        $latitude = $submittedLocation->latitude;
        $longitude = $submittedLocation->longitude;
    } else {
        // Handle the case where location is not found
        $latitude = null;
        $longitude = null;
        // Optionally, display an error message or take other actions
        echo "Location not found for the specified subtask.";
    }
}
?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap" async
        defer></script>
<div class="main-content">
    <div class="container-fluid">
        <div class="page-header 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>View Subtask</h5>
                        <span>View details of a subtask</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="../../index.html"><i class="ik ik-home"></i></a></li>
                        <li class="breadcrumb-item"><a href="#">Subtasks</a></li>
                        <li class="breadcrumb-item active" aria-current="page">View Subtask</li>
                    </ol>
                </nav>
            </div>
        </div>

        <div class="card">
            <div class="card-header d-flex justify-content-between">
                <a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
                <div>
                    <?php if (!$subtask->assigned): ?>
                        <button type="button" class="btn btn-primary" id="assignTaskButton">Assign Task to a cleaner</button>
                    <?php endif; ?>
                    <?php if ($subtask->assigned && !$subtask->completed): ?>
                        <button type="button" class="btn btn-primary" id="assignTaskButton">Resend Task to a cleaner</button>
                    <?php endif; ?>

                    <?php if ($subtask->completed): ?>
                        <!--                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#viewTaskCompletionFormModal">View Task Completion Form</button>-->
                    <?php endif; ?>
                </div>
            </div>
            <div class="card-body">
                <div class="row align-items-center mb-30">
                    <div class="col-md-12">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-layers icon-large"></i></td>
                                            <td><h3 class="mb-0 fw-700 text-black"><?php echo $subtask->service_name; ?></h3></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-calendar icon-large"></i></td>
                                            <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_date ? date('F j, Y', strtotime($subtask->subtask_date)) : 'Not set'; ?></h5></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-clock icon-large"></i></td>
                                            <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->subtask_time ? date('g:i A', strtotime($subtask->subtask_time)) : 'Not set'; ?></h5></td>
                                        </tr>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td>
                                                <h5 class="mb-0 fw-500 text-black"><?php echo date('F j, Y', strtotime($subtask->updated_at)); ?></h5>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </td>
                                <td>
                                    <table>
                                        <tbody>
                                        <tr>
                                            <td><i class="ik ik-check-circle icon-large"></i></td>
                                            <td>
                                                <?php
                                                if ($subtask->ignored) {
                                                    echo '<span class="badge badge-yellow">Ignored</span>';
                                                } else {
                                                    if ($subtask->completed) {
                                                        echo '<span class="badge badge-success">Completed</span> ';
                                                    } else {
                                                        echo '<span class="badge badge-danger">Not Completed</span>';
                                                    }
                                                }
                                                ?>
                                            </td>
                                        </tr>
<!--                                        --><?php //if ($subtask->completed): ?>
<!--                                            <tr>-->
<!--                                                <td><i class="ik ik-calendar icon-large"></i></td>-->
<!--                                                <td><h5 class="mb-0 fw-500 text-black">--><?php //echo $subtask->completed_at; ?><!--</h5></td>-->
<!--                                            </tr>-->
<!--                                        --><?php //endif; ?>
                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td>
                                                <?php if ($subtask->assigned): ?>
                                                    <span class="badge badge-success">Assigned</span>
                                                <?php else: ?>
                                                    <span class="badge badge-danger">Not assigned</span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <?php if ($subtask->assigned): ?>
                                            <tr>
                                                <td><i class="ik ik-mail icon-large"></i></td>
                                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->assigned_to_Mobile ?: 'Not set'; ?></h5></td>
                                            </tr>
                                            <tr>
                                                <td><i class="ik ik-check icon-large"></i></td>
                                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $subtask->assigned_Message_Rsponse ? 'Email sent successfully' : 'Unable to send email'; ?></h5></td>
                                            </tr>
                                            <tr>
                                                <td><i class="ik ik-file-text icon-large"></i></td>
                                                <td><h5 class="mb-0 fw-500 text-black">
                                                        <?php echo $subtask->form_submission_id ? '<a href="../completedsubtaskform.php?id=' . $subtask->form_submission_id . '" target="_blank">View Submitted Form</a>' : 'Form not submitted'; ?>
                                                    </h5></td>
                                            </tr>
                                            <?php if ($subtask->completed && property_exists($subtask, 'submitted_by_admin') && $subtask->submitted_by_admin): ?>
                                                <tr>
                                                    <td><i class="ik ik-user icon-large"></i></td>
                                                    <td><h5 class="mb-0 fw-500 text-black"><span class="badge badge-warning">Marked as completed by admin</span></h5></td>
                                                </tr>
                                            <?php endif; ?>
                                            <?php if ($subtask->form_submission_id): ?>
                                                <tr>
                                                    <td><i class="fas fa-calendar-check icon-large"></i></td>
                                                    <?php
                                                    // Assuming $subtask->completed_at contains the datetime string
                                                    $completedAt = $subtask->completed_at;

                                                    // Create a new DateTime object with the original datetime
                                                    $date = new DateTime($completedAt, new DateTimeZone('UTC'));

                                                    // Set the timezone to Sydney
                                                    $date->setTimezone(new DateTimeZone('Australia/Sydney'));

                                                    // Format the date and time
                                                    $formattedDate = $date->format('F j, Y, g:i a');
                                                    ?>
                                                    <td>
                                                        <h5 class="mb-0 fw-500 text-black"><?php echo $formattedDate; ?></h5>
                                                    </td>
                                                </tr>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <style>
                            table {
                                width: 100%;
                                border-collapse: collapse;
                            }
                            td {
                                padding: 10px 15px;
                                vertical-align: middle;
                            }
                            .icon-large {
                                font-size: 24px;
                                color: #333;
                            }
                            .mb-0 {
                                margin-bottom: 0;
                            }
                            .fw-700 {
                                font-weight: 700;
                            }
                            .fw-500 {
                                font-weight: 500;
                            }
                            .text-black {
                                color: #000;
                            }
                            .badge-success {
                                background-color: #28a745;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }
                            .badge-danger {
                                background-color: #dc3545;
                                color: #fff;
                                padding: 5px 10px;
                                border-radius: 5px;
                            }
                        </style>
                    </div>
                </div>
            </div>
        </div>
        <?php if ($subtask->completed && $latitude !== null && $longitude !== null): ?>
            <div class="card">
                <div class="card-header d-flex justify-content-between">
                    <h3>Submitted Location</h3>
                </div>
                <div class="card-body">
                    <div id="map"></div>
                </div>
            </div>
            <script>
                function initMap() {
                    // Replace these PHP variables with actual PHP values
                    var latitude = <?php echo $latitude; ?>; // PHP variable for latitude
                    var longitude = <?php echo $longitude; ?>; // PHP variable for longitude

                    // Create a map centered at a specific location
                    var map = new google.maps.Map(document.getElementById('map'), {
                        center: {lat: latitude, lng: longitude},
                        zoom: 12 // Adjust zoom level as needed
                    });

                    // Add a marker at the specified location
                    var marker = new google.maps.Marker({
                        position: {lat: latitude, lng: longitude},
                        map: map,
                        title: 'Hello World!' // Marker tooltip (optional)
                    });
                }
            </script>
            <script async defer
                    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9O5PAsTaFPCHlIlM4XSK7ei-gaLMYpzk&callback=initMap">
            </script>
        <?php endif; ?>

        <script>
            document.getElementById('assignTaskButton').addEventListener('click', function () {
                Swal.fire({
                    title: 'Enter Cleaner Email',
                    input: 'email',
                    inputLabel: 'Cleaner Email',
                    inputPlaceholder: 'Enter cleaner email',
                    showCancelButton: true,
                    confirmButtonText: 'Assign Task',
                    showLoaderOnConfirm: true,
                    preConfirm: (email) => {
                        const subtaskIds = <?php echo json_encode([$subtaskId]); ?>;
                        return fetch('../send_email_to_workers.php', {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify({
                                action: 'bulk', // or 'single' depending on your logic
                                worker_email: email,
                                subtask_ids: subtaskIds
                            })
                        })
                            .then(response => {
                                if (!response.ok) {
                                    throw new Error('Network response was not ok');
                                }
                                return response.json();
                            })
                            .then(data => {
                                console.log('Response from PHP:', data);
                                // Handle response data accordingly
                                if (data.status === 'success') {
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Task has been assigned successfully',
                                        icon: 'success'
                                    }).then(() => location.reload());
                                } else {
                                    throw new Error(data.message || 'Unknown error');
                                }
                            })
                            .catch(error => {
                                console.error('Fetch error:', error);
                                Swal.showValidationMessage(
                                    `Request failed: ${error.message}`
                                );
                            });
                    },
                    allowOutsideClick: () => !Swal.isLoading()
                });
            });

        </script>
    </div>
</div>
<?php include('footer.php'); ?>