Your IP : 216.73.216.86


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

<?php
include('head.php');
// Include database connection and TaskService class
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';
$System = new System();

// Create TaskService instance
$taskService = new TaskService();

// Check if task ID is provided in URL
if (isset($_GET['id'])) {
// Fetch task details based on ID
    $taskId = $System->decryptData($_GET['id']);
    // show error if the provided id is not valid with Swal alert
    if (!$taskId) {
        echo '<script>Swal.fire({
            title: "Invalid task ID!",
            text: "Please check the URL and try again.",
            icon: "error",
            confirmButtonText: "OK"
        }).then(function() {
            window.location = "viewAcceptedTasks.php";
        });</script>';
    }

    $task = $taskService->getTaskById($taskId);

    if (!$task) {
        exit();
    }

} else {
    echo '<p>No task ID provided.</p>';
}
$subtasks = $taskService->getSubtasksByTaskId($taskId);
?>

<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-box bg-blue"></i>
                        <div class="d-inline">
                            <h5>View Task</h5>
                            <span>View details of a task</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="#">Tasks</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">View Task</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
        <!-- New row for buttons and actions -->
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <div class="card-header-left">
                            <a href="javascript:history.back()" class="btn btn-outline-primary">Back</a>
                        </div>

                        <div class="card-header-right">


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

        <!-- Modal to assign task to a company -->



        <div class="row">
            <div class="col-xl-6 col-md-6">
                <div class="card ">
                    <div class="card-body">
                        <div class="row align-items-center mb-30">
                            <div class="col-md-6">

                                <table>
                                    <tbody>
                                    <tr>
                                        <td><i class="ik ik-layers icon-large"></i></td>
                                        <td><h3 class="mb-0 fw-700 text-black"><?php echo $task->service_name; ?> </h3>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><i class="ik ik-map-pin icon-large"></i></td>
                                        <td><h5 class="mb-0 fw-500 text-black"><?php echo $task->region; ?> </h5></td>
                                    </tr>
                                    <tr>
                                        <td><i class="ik ik-calendar icon-large"></i></td>
                                        <td><h5 class="mb-0 fw-500 text-black"><?php echo $task->schedule_name; ?> </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 $task->frequency; ?> </h5>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><i class="ik ik-check-circle icon-large"></i></td>
                                        <td>
                                            <h2><?php echo($task->finished ? '<span class="badge badge-success">Task completed</span>' : '<span class="badge badge-danger">Not Completed</span>'); ?></h2>
                                        </td>
                                    </tr>
                                    <!--                                    is public or not-->




                                    <?php if($task->is_assigned == 1 && $task->assigned_to == $companyId) : ?>


                                        <tr>
                                            <td><i class="ik ik-user icon-large"></i></td>
                                            <td><h6><span class="badge badge-yellow">
                                                        This task is assigned to your company.</span>
                                                </h6></td>
                                        </tr>


                                    <?php endif; ?>
                                    </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 class="col-md-6">
                                <?php
                                // Assuming $task->dates is a JSON string
                                $datesJson = $task->dates;

                                // Decode the JSON string to an array
                                $datesArray = json_decode($datesJson, true);

                                // Extract the dates and format them for JavaScript
                                $formattedDates = array_map(function ($dateEntry) {
                                    return '"' . $dateEntry['date'] . '"';
                                }, $datesArray);
                                $jsDates = implode(",", $formattedDates); // Convert the array to a comma-separated string
                                ?>
                                <div id="datepicker"></div>
                                <script>
                                    const today = new Date();
                                    flatpickr("#datepicker", {
                                        enable: [<?php echo $jsDates; ?>], // Array of selectable dates
                                        dateFormat: "Y-m-d", // Date format
                                        inline: true, // Show calendar inline
                                        defaultDate: today, // Highlighted date
                                        disableMobile: "false"
                                    });
                                </script>
                            </div>

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

            <!-- Form to assign task to a company -->

            <div class="col-md-6">
                <div class="card">
                    <div class="card-header"><h3>Subtasks</h3></div>
                    <div class="card-body">
                        <!-- PHP code to fetch and display subtasks -->
                        <?php
                        // Fetch and display subtasks associated with the task

                        // Display subtasks
                        if ($subtasks) {
                            ?>
                            <table class="table" id="advanced_table">
                                <thead>
                                <tr>
                                    <th>Id</th>
                                    <th>Date</th>
                                    <th>Updated At</th>
                                    <th>Assigned</th>
                                    <th>Completed</th>
                                    <th>Actions</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                foreach ($subtasks as $subtask) {
                                    ?>
                                    <tr>
                                        <td> ST-000<?php echo $subtask->id; ?></td>
                                        <td><?php echo $subtask->subtask_date; ?></td>

                                        <td><?php echo date('F j, Y, g:i a', strtotime($subtask->updated_at)); ?></td>
                                        <td><?php echo($subtask->assigned ? '<span class="badge badge-success">Assigned</span>' : '<span class="badge badge-danger">Not Assigned</span>'); ?></td>
                                        <td>
                                            <?php
                                            if ($subtask->ignored) {
                                                echo '<span class="badge badge-warning">Ignored</span>';
                                            } else {
                                                echo $subtask->completed
                                                    ? '<span class="badge badge-success">Completed</span>'
                                                    : '<span class="badge badge-danger">Not Completed</span>';
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <a href="viewsubtask.php?id=<?php echo $System->encryptData($subtask->id); ?>" class="btn btn-primary">View</a>


                                        </td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                            </table>
                            <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>



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