Your IP : 216.73.216.86


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

home/emeraadmin/public_html/pages/emeraadmin/assigntasks.php000064400000045251151677422340020366 0ustar00<?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';
require_once '../../Service/UserService.php';

$System = new System();

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

// Create UserService instance
$UserService = new UserService();

// Initialize filters array
$filters = [];

// Check for filter inputs and add to the filters array
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    if (!empty($_GET['service_name'])) {
        $filters['service_name'] = filter_input(INPUT_GET, 'service_name', FILTER_SANITIZE_STRING);
    }

    if (!empty($_GET['region'])) {
        $filters['region'] = filter_input(INPUT_GET, 'region', FILTER_SANITIZE_STRING);
    }

    if (!empty($_GET['frequency'])) {
        $filters['frequency'] = filter_input(INPUT_GET, 'frequency', FILTER_SANITIZE_STRING);
    }

    if (isset($_GET['public']) && $_GET['public'] !== '') {
        $filters['public'] = filter_input(INPUT_GET, 'public', FILTER_SANITIZE_NUMBER_INT);
    }
}

// Fetch tasks from the database based on filters
$tasks = $taskService->getAllUnassignedTasks($filters);
?>

<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>Assign Tasks</h5>
                            <span>View all unassigned tasks</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 Tasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Search Form -->
        <div class="row mb-3">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <h3>Search Tasks</h3>
                    </div>
                    <div class="card-body">
                        <form method="GET" action="">
                            <div class="form-row">
                                <div class="form-group col-md-2">
                                    <label for="service_name">Service Name</label>
                                    <input type="text" class="form-control" id="service_name" name="service_name" placeholder="Enter service name" value="<?php echo htmlspecialchars($_GET['service_name'] ?? ''); ?>">
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="region">Region</label>
                                    <input type="text" class="form-control" id="region" name="region" placeholder="Enter region" value="<?php echo htmlspecialchars($_GET['region'] ?? ''); ?>">
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="frequency">Frequency</label>
                                    <select class="form-control" id="frequency" name="frequency">
                                        <option value="">Select</option>
                                        <option value="daily" <?php echo (isset($_GET['frequency']) && $_GET['frequency'] === 'daily') ? 'selected' : ''; ?>>Daily</option>
                                        <option value="3x/week" <?php echo (isset($_GET['frequency']) && $_GET['frequency'] === '3x/week') ? 'selected' : ''; ?>>3x/week</option>
                                        
                                    </select>
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="public">Public</label>
                                    <select class="form-control" id="public" name="public">
                                        <option value="">Select</option>
                                        <option value="1" <?php echo (isset($_GET['public']) && $_GET['public'] === '1') ? 'selected' : ''; ?>>Yes</option>
                                        <option value="0" <?php echo (isset($_GET['public']) && $_GET['public'] === '0') ? 'selected' : ''; ?>>No</option>
                                    </select>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-primary">Apply Filters</button>
                            <a href="assigntasks.php" class="btn btn-secondary">Clear Filters</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- End of Search Form -->

        <!-- Task viewing section -->
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header"><h3>View Tasks</h3></div>
                    <div class="card-body">
                        <table id="advanced_table" class="table">
                            <thead>
                            <tr>
                                <th class="nosort" width="10">
<!--                                    <label class="custom-control custom-checkbox m-0">-->
<!--                                        <input type="checkbox" class="custom-control-input select-all" id="selectall" name="" value="option2">-->
<!--                                        <span class="custom-control-label">&nbsp;</span>-->
<!--                                    </label>-->
                                </th>
                                <th>#</th>
                                <th>Service Name</th>
                                <th>Region</th>
                                <th>Frequency</th>
                                <th>Created By</th>
                                <th>Created At</th>

                                <th>Assigned</th>
                                <th>Rejected By</th>


                                <th>Public Status</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!empty($tasks)): ?>
                                <?php foreach ($tasks as $task): ?>
                                    <tr>
                                        <td>
                                            <label class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input select-task" id="task_<?php echo htmlspecialchars($task->id); ?>" name="selected_tasks[]" value="<?php echo htmlspecialchars($task->id); ?>">
                                                <span class="custom-control-label">&nbsp;</span>
                                            </label>
                                        </td>
                                        <td><?php echo 'TSK-000'.htmlspecialchars($task->id); ?></td>
                                        <td><?php echo htmlspecialchars($task->service_name); ?></td>
                                        <td><?php echo htmlspecialchars($task->region); ?></td>
                                        <td><?php echo htmlspecialchars($task->frequency); ?></td>
                                        <td><?php echo htmlspecialchars($task->added_by_name); ?></td>
                                        <td><?php echo date('F j, Y, g:i a', strtotime($task->created_at)); ?></td>

                                        <td><?php echo ($task->is_assigned ? '<label class="badge badge-success">Assigned</label>' : '<label class="badge badge-danger">Not Assigned</label>'); ?></td>
                                        <td>
                                            <?php foreach ($task->not_accepted_users as $userId) {
                                                // Fetch and display username based on user ID
                                                $userName = $UserService->fetchUserName($userId); // Assuming a function fetchUserName exists
                                                echo htmlspecialchars($userName) . '<br>';
                                            } ?>
                                        </td>
                                        <td><label class="badge badge-<?php echo $task->isPublic ? 'yellow' : 'green'; ?>"><?php echo $task->isPublic ? 'Public' : 'Not Public'; ?></label></td>
                                        <td><a href="viewtask.php?id=<?php echo htmlspecialchars($System->encryptData($task->id)); ?>" class="btn btn-primary">View Details</a></td>
                                    </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="11">No tasks found.</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                        <!-- Assign Task Button -->
                        <button id="assignTaskButton" class="btn btn-success">Assign Task(s)</button>
                        <button id="makePublicButton" class="btn btn-warning">Make Task(s) Public</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal for Assigning Tasks -->
<div class="modal fade" id="AssignTaskModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalCenterLabel">Assign Tasks to subcontractors</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="tasksForm">
                    <input type="hidden" id="taskIds" name="taskIds">
                    <div class="form-group">
                        <label for="companyId">Select a Subcontractor:</label>
                        <select id="companyId" name="companyId" class="form-control select2">
                            <!-- PHP code to fetch and display companies -->
                            <?php
                            // Fetch company list from the database
                            $companies = $taskService->getAllCompanies();
                            if ($companies) {
                                foreach ($companies as $company) {
                                    echo '<option value="' . $company->id . '">' . $company->first_name . " " . $company->last_name . '</option>';
                                }
                            } else {
                                echo '<option value="">No subcontractors available</option>';
                            }
                            ?>
                        </select>
                    </div>
                </form>
                <div id="message" class="mt-3"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" id="assignTasksButton" class="btn btn-primary">Assign Tasks</button>
            </div>
        </div>
    </div>
</div>

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

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const checkboxes = document.querySelectorAll('.select-task');
        const assignButton = document.getElementById('assignTaskButton');
        const modal = new bootstrap.Modal(document.getElementById('AssignTaskModal'));

        assignButton.addEventListener('click', function () {
            const selectedTasks = Array.from(checkboxes)
                .filter(checkbox => checkbox.checked)
                .map(checkbox => checkbox.value);

            if (selectedTasks.length > 0) {
                document.getElementById('taskIds').value = selectedTasks.join(',');
                modal.show();
            } else {
                Swal.fire({
                    title: 'No Tasks Selected',
                    text: 'Please select at least one task to assign.',
                    icon: 'warning',
                    confirmButtonText: 'Ok'
                });
            }
        });

        document.getElementById('assignTasksButton').addEventListener('click', function () {
            const formData = new FormData(document.getElementById('tasksForm'));
            var selectedCompany = document.getElementById('companyId');
            var selectedCompanyName = selectedCompany.options[selectedCompany.selectedIndex].text; // Get the selected company name
            var numberOfSelectedcheckboxes = Array.from(checkboxes).filter(checkbox => checkbox.checked).length;

            Swal.fire({
                title: 'Are you sure?',
                html: `You are about to assign the selected tasks to ${selectedCompanyName}.<br>You selected ${numberOfSelectedcheckboxes} tasks.`,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Yes, Assign',
                cancelButtonText: 'No, Cancel'
            }).then((result) => {
                if (result.isConfirmed) {
                    fetch('bulk_assign_tasks.php', {
                        method: 'POST',
                        body: formData
                    })
                        .then(response => response.json())
                        .then(data => {
                            if (data.status === 'success') {
                                Swal.fire({
                                    title: 'Tasks Assigned Successfully',
                                    text: 'Task assigned to company successfully.',
                                    icon: 'success',
                                    confirmButtonText: 'Ok'
                                }).then(() => {
                                    window.location.reload();
                                });
                            } else {
                                Swal.fire({
                                    title: 'Error',
                                    text: data.message || 'Failed to assign tasks. Please try again.',
                                    icon: 'error',
                                    confirmButtonText: 'Ok'
                                });
                            }
                        })
                        .catch(error => {
                            console.error('Error assigning tasks:', error);
                            Swal.fire({
                                title: 'Error',
                                text: error.message || 'Failed to assign tasks. Please try again.',
                                icon: 'error',
                                confirmButtonText: 'Ok'
                            });
                        });
                }
            });
        });


        const makePublicButton = document.getElementById('makePublicButton');


        let taskids = [];
        checkboxes.forEach(checkbox => {
            checkbox.addEventListener('change', function () {
                if (checkbox.checked) {
                    taskids.push(checkbox.value);
                } else {
                    taskids = taskids.filter(id => id !== checkbox.value);
                }
            });
        });

        console.log(taskids);

        makePublicButton.addEventListener('click', function () {
            if (taskids.length > 0) {
                const formData = new FormData();
                formData.append('taskIds', taskids.join(','));

                fetch('make_tasks_public.php', {
                    method: 'POST',
                    body: formData
                })
                    .then(response => response.json())
                    .then(data => {
                        if (data.status === 'success') {
                            Swal.fire({
                                title: 'Tasks Made Public Successfully',
                                text: `Task(s) made public successfully.`,
                                icon: 'success',
                                confirmButtonText: 'Ok'
                            }).then(() => {
                                window.location.reload();
                            });
                        } else {
                            Swal.fire({
                                title: 'Error',
                                text: data.message || 'Failed to make tasks public. Please try again.',
                                icon: 'error',
                                confirmButtonText: 'Ok'
                            });
                        }
                    })
                    .catch(error => {
                        console.error('Error making tasks public:', error);
                        Swal.fire({
                            title: 'Error',
                            text: error.message || 'Failed to make tasks public. Please try again.',
                            icon: 'error',
                            confirmButtonText: 'Ok'
                        });
                    });
            } else {
                Swal.fire({
                    title: 'No Tasks Selected',
                    text: 'Please select at least one task to make public.',
                    icon: 'warning',
                    confirmButtonText: 'Ok'
                });
            }
        });

    });

</script>
home/emeraadmin/public_html/pages/subcontractor/assigntasks.php000064400000014410151701467310021137 0ustar00<?php
include('head.php');
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';
require_once '../../Service/ServiceService.php';

$serviceService = new ServiceService();

$System = new System();

$services = $serviceService->getAllServicesForDropdown();


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



$tasks = $taskService->getTasksWithUnassignedSubtasks($companyId);

?>

<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>View Assignable Tasks</h5>
                            <span>View details of tasks assigned to your company</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 Accepted Tasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Task viewing section -->
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header"><h3>View Tasks</h3></div>
                    <div class="card-body">
                        <div class="form-group row">
                            <div class="col-sm-3">
                                <label for="filter_service" class="col-form-label">Filter Service Name:</label>
                                <input type="text" class="form-control" id="filter_service">
                            </div>
                            <div class="col-sm-3">
                                <label for="filter_region" class="col-form-label">Filter Region:</label>
                                <select class="form-control" id="filter_region">
                                    <option value="">All Regions</option>
                                    <?php
                                    // Collect unique regions
                                    $uniqueRegions = [];
                                    foreach ($services as $service) {
                                        if (!in_array($service->region, $uniqueRegions)) {
                                            $uniqueRegions[] = $service->region;
                                            ?>
                                            <option value="<?= htmlspecialchars($service->region) ?>"><?= htmlspecialchars($service->region) ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>

                        </div>
                        <table id="super_advanced_table" class="table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Service Name</th>
                                <th>Region</th>
                                <th>Frequency</th>
                                <th>Created At</th>
                                <th>Completed</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($tasks as $task): ?>
                                <tr>
                                    <td><?php echo 'TSK-000'.$task->id; ?></td>
                                    <td><?php echo $task->service_name; ?></td>
                                    <td><?php echo $task->region; ?></td>
                                    <td><?php echo $task->frequency; ?></td>
                                    <td><?php echo date('F j, Y, g:i a', strtotime($task->created_at)); ?></td>
                                    <td>
                                        <label class="badge badge-<?php echo $task->finished ? 'success' : 'yellow'; ?>"><?php echo $task->finished ? 'Completed' : 'Not Completed'; ?></label>
                                    </td>
                                    <td>
                                        <a href="viewtask.php?id=<?php echo $System->encryptData($task->id); ?>" class="btn btn-primary">View Details</a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                    <script>
                        $(document).ready(function () {
                            // Initialize DataTable
                            var table = $('#super_advanced_table').DataTable({
                                // Configure initial settings if needed
                            });

                            // Add custom filters
                            $('#filter_service').on('keyup', function () {
                                table.column(1).search(this.value).draw();
                            });

                            $('#filter_region').on('change', function () {
                                table.column(2).search($(this).val()).draw();
                            });


                        });
                    </script>
                </div>
            </div>
        </div>

    </div>
</div>

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