Your IP : 216.73.216.86


Current Path : /home/emeraadmin/www/4d695/
Upload File :
Current File : /home/emeraadmin/www/4d695/taskprovider.zip

PK��\�k�%%export_schedule.phpnu�[���<?php
//enable error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

// Include Composer's autoload file to load PHPSpreadsheet
require '../../vendor/autoload.php';


require_once __DIR__ . '/../../Classes/Database.php';


use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

// Function to export schedule tasks to Excel and return file contents
function exportScheduleToExcel($scheduleId) {
    // Establish database connection (replace with your connection logic)
    $db = new Database();
    $pdo = $db->getConn();


    // SQL query to fetch tasks with subtask dates and times formatted
    $sql = "
    SELECT
        srv.name AS service_name,
        srv.region,
        t.frequency,
        GROUP_CONCAT(DISTINCT st.subtask_date ORDER BY st.subtask_date SEPARATOR ', ') AS subtask_dates
    FROM
        tasks t
    JOIN
        subtasks st ON t.id = st.task_id
    JOIN
        services srv ON t.service_id = srv.id
    WHERE
        t.schedule_id = :schedule_id
    GROUP BY
        srv.name, srv.region, t.frequency, t.id
    ORDER BY
        srv.name, srv.region, t.frequency
";


    $stmt = $pdo->prepare($sql);
    $stmt->bindValue(':schedule_id', $scheduleId, PDO::PARAM_INT);
    $stmt->execute();
    $tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // Create a new Spreadsheet object
    $spreadsheet = new Spreadsheet();
    $sheet = $spreadsheet->getActiveSheet();

    // Set headers or titles in the Excel sheet
    $sheet->setCellValue('A1', 'Service Name');
    $sheet->setCellValue('B1', 'Region');
    $sheet->setCellValue('C1', 'Frequency');

    // Get all distinct subtask dates
    $distinctDates = [];
    foreach ($tasks as $task) {
        $dates = explode(', ', $task['subtask_dates']);
        $distinctDates = array_merge($distinctDates, $dates);
    }
    $distinctDates = array_unique($distinctDates);
    sort($distinctDates);

    // Set dates as headers in the Excel sheet
    $col = 'D';
    foreach ($distinctDates as $date) {
        $sheet->setCellValue($col . '1', $date);
        $sheet->getColumnDimension($col)->setWidth(12); // Adjust width as needed
        $col++;
    }

    // Populate tasks data into Excel
    $row = 2;
    foreach ($tasks as $task) {
        $sheet->setCellValue('A' . $row, $task['service_name']);
        $sheet->setCellValue('B' . $row, $task['region']);
        $sheet->setCellValue('C' . $row, $task['frequency']);

        // Split subtask dates for the current task
        $dates = explode(', ', $task['subtask_dates']);
        $col = 'D';
        foreach ($distinctDates as $date) {
            // Check if the date exists for the current task or color black
            $value = in_array($date, $dates) ? 'X' : '';

            // Set value in corresponding cell
            $cellCoordinate = $col . $row;
            $sheet->setCellValue($cellCoordinate, $value);

            // Apply black color to non-X values
            if ($value !== 'X') {
                $spreadsheet->getActiveSheet()->getStyle($cellCoordinate)
                    ->getFont()->getColor()->setARGB(Color::COLOR_BLACK);
            }

            $col++;
        }

        $row++;
    }

    // Set column widths (optional)
    $sheet->getColumnDimension('A')->setWidth(25); // Adjust width as needed
    $sheet->getColumnDimension('B')->setWidth(20);
    $sheet->getColumnDimension('C')->setWidth(15);

    // Set headers for Excel file download
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="schedule_export_' . date('Y-m-d') . '.xlsx"');
    header('Cache-Control: max-age=0');

    // Save Excel file to PHP output (browser will download it)
    $writer = new Xlsx($spreadsheet);
    $writer->save('php://output');
}

// Check if schedule_id is provided via GET request
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['schedule_id'])) {
    $scheduleId = $_GET['schedule_id'];

    try {
        // Export schedule to Excel and initiate download
        exportScheduleToExcel($scheduleId);
        exit; // Stop further execution after file download
    } catch (Exception $e) {
        // Handle exceptions (e.g., database errors, file saving errors)
        echo 'Error: ' . $e->getMessage();
    }
} else {
    // Handle case where schedule_id parameter is missing
    echo 'Error: Schedule ID parameter missing.';
}
?>
PK��\3ͥ�~~	error_lognu�[���[15-Sep-2024 08:02:20 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[15-Sep-2024 08:03:31 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:27:38 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:29:38 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:37:52 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:38:15 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:40:10 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:41:29 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:41:44 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:42:01 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 12:43:03 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 13:46:44 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Sep-2024 13:50:11 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[17-Sep-2024 03:19:41 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[17-Sep-2024 03:20:51 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[17-Sep-2024 04:28:43 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[17-Sep-2024 04:29:16 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 02:02:34 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 02:15:38 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 02:17:17 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 02:21:44 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 02:48:43 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 06:09:31 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[23-Sep-2024 06:38:24 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 03:19:51 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 05:54:10 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 05:54:38 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 05:55:51 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 05:57:08 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 05:59:22 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 06:00:15 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[24-Sep-2024 12:39:26 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[25-Sep-2024 00:12:27 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[25-Sep-2024 00:17:50 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[25-Sep-2024 02:18:02 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[25-Sep-2024 04:46:41 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[28-Sep-2024 07:38:15 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[28-Sep-2024 12:26:05 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[28-Sep-2024 12:32:31 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:07:15 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:44:51 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:45:13 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:45:26 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:46:27 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:46:32 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[30-Sep-2024 00:54:11 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 00:13:23 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 00:13:56 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 00:21:36 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 00:24:49 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 01:29:08 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[01-Oct-2024 04:22:24 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[02-Oct-2024 01:00:36 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[02-Oct-2024 01:38:55 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[02-Oct-2024 22:33:18 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[02-Oct-2024 22:33:24 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[03-Oct-2024 22:14:36 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[03-Oct-2024 22:31:55 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[04-Oct-2024 04:42:30 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[06-Oct-2024 21:37:47 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[07-Oct-2024 21:12:59 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[08-Oct-2024 00:01:55 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[09-Oct-2024 01:10:53 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[09-Oct-2024 04:27:31 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Oct-2024 05:31:07 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[16-Oct-2024 05:32:35 UTC] PHP Warning:  Undefined array key "pending" in /home/ftmgc76wdee4/public_html/pages/taskprovider/dashboard.php on line 36
[08-Nov-2024 04:01:46 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:13:23 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:13:40 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:19:21 UTC] PHP Deprecated:  base64_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/Classes/System.php on line 29
[26-Nov-2024 00:20:19 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:20:52 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:24:17 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:44:22 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 00:44:25 UTC] PHP Deprecated:  base64_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/Classes/System.php on line 29
[26-Nov-2024 00:44:29 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 128
[26-Nov-2024 00:44:29 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 134
[26-Nov-2024 03:39:02 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[26-Nov-2024 03:39:15 UTC] PHP Deprecated:  base64_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/Classes/System.php on line 29
[26-Nov-2024 03:39:19 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 128
[26-Nov-2024 03:39:19 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 134
[02-Dec-2024 04:28:02 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[02-Dec-2024 04:28:18 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[02-Dec-2024 04:29:05 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[03-Dec-2024 08:29:48 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[03-Dec-2024 08:30:35 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 62
[03-Dec-2024 08:30:35 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 68
[03-Dec-2024 08:32:24 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[03-Dec-2024 08:32:56 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[09-Dec-2024 21:55:09 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[09-Dec-2024 23:46:04 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[09-Dec-2024 23:46:10 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 62
[09-Dec-2024 23:46:10 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 68
[09-Dec-2024 23:46:16 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 62
[09-Dec-2024 23:46:16 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php on line 68
[09-Dec-2024 23:46:21 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 128
[09-Dec-2024 23:46:21 UTC] PHP Deprecated:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_viewsubtasksdaywise.php on line 134
[11-Dec-2024 22:29:20 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[11-Dec-2024 22:30:01 UTC] PHP Deprecated:  base64_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/Classes/System.php on line 29
[11-Dec-2024 22:30:16 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[12-Dec-2024 21:56:35 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[10-Jan-2025 04:57:09 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[12-Jan-2025 20:12:51 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[12-Jan-2025 20:25:13 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[13-Jan-2025 03:40:00 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[13-Jan-2025 03:40:26 UTC] PHP Deprecated:  base64_decode(): Passing null to parameter #1 ($string) of type string is deprecated in /home/emeraadmin/public_html/Classes/System.php on line 29
[13-Jan-2025 03:40:31 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[13-Jan-2025 03:41:26 UTC] PHP Deprecated:  Constant FILTER_SANITIZE_STRING is deprecated in /home/emeraadmin/public_html/pages/taskprovider/report_alltasks.php on line 19
[13-Jan-2025 22:01:48 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[14-Jan-2025 23:37:46 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[15-Jan-2025 21:01:06 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[15-Jan-2025 21:41:51 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[15-Jan-2025 21:50:19 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[15-Jan-2025 21:50:44 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[16-Jan-2025 00:12:15 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[16-Jan-2025 02:05:22 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[16-Jan-2025 23:38:54 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[17-Jan-2025 02:20:40 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[17-Jan-2025 04:56:07 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[20-Jan-2025 04:13:16 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[22-Jan-2025 21:27:29 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[22-Jan-2025 22:11:21 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[24-Jan-2025 03:45:58 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[24-Jan-2025 03:46:01 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[30-Jan-2025 00:29:52 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[30-Jan-2025 00:30:00 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[30-Jan-2025 02:40:28 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[30-Jan-2025 03:38:56 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[30-Jan-2025 04:45:52 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[05-Feb-2025 03:15:03 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[05-Feb-2025 04:25:05 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[11-Feb-2025 21:36:50 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[11-Feb-2025 22:32:50 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[11-Feb-2025 23:57:34 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[12-Mar-2025 21:46:39 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[08-Apr-2025 01:34:27 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[10-Apr-2025 03:33:08 UTC] PHP Warning:  Undefined array key "pending" in /home/emeraadmin/public_html/pages/taskprovider/dashboard.php on line 36
[15-Apr-2026 10:57:12 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/TaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_task.php(7): TaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:00:40 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ServiceService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/add_tasks.php(15): ServiceService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:36:50 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/SubtaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_subtask.php(6): SubtaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:38:02 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ScheduleService.php(13): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_schedule.php(7): ScheduleService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:39:34 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/TaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_task.php(7): TaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:41:48 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/SubtaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_subtask.php(6): SubtaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:44:49 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ServiceService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/add_tasks.php(15): ServiceService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 11:47:26 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/TaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_task.php(7): TaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 13:20:42 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ScheduleService.php(13): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_schedule.php(7): ScheduleService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 13:48:21 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/SubtaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_subtask.php(6): SubtaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 15:23:12 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ServiceService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/add_tasks.php(15): ServiceService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 15:23:30 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/ScheduleService.php(13): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_schedule.php(7): ScheduleService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 15:23:34 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/SubtaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_subtask.php(6): SubtaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
[15-Apr-2026 15:23:37 UTC] PHP Fatal error:  Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/home/emeraadmin/public_html/Classes/../.env]. in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /home/emeraadmin/public_html/Classes/Database.php(23): Dotenv\Dotenv->load()
#2 /home/emeraadmin/public_html/Service/TaskService.php(12): Database->__construct()
#3 /home/emeraadmin/public_html/pages/taskprovider/delete_task.php(7): TaskService->__construct()
#4 {main}
  thrown in /home/emeraadmin/public_html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
PK��\�ڭ���add_subtask.phpnu�[���<?php


// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    require_once '../../Classes/Subtask.php';
    require_once '../../Service/SubtaskService.php';
    require_once '../../Service/TaskService.php';
    // Retrieve and sanitize input data
    $task_id = $_POST['task_id'];
    $service_id = $_POST['service_name'];


    $subtask_date = $_POST['subtask_date'];
    $subtask_time = isset($_POST['subtask_time']) ? $_POST['subtask_time'] : null;


    $now = new DateTime();
    $created_at = $now->format('Y-m-d H:i:s');
    $updated_at = $now->format('Y-m-d H:i:s');


    // Create a new Subtask object
    $subtask = new Subtask('', $task_id, $service_id, $subtask_date, $subtask_time,$created_at,$updated_at,0,"",0,"","","");

    // Instantiate SubtaskService
    $subtaskService = new SubtaskService(); // Replace with your SubtaskService class instantiation

    // Attempt to add the subtask
    if ($subtaskService->addSubtask($subtask)) {
        echo "Subtask added successfully!";
    } else {
        echo "Failed to add subtask.";
    }
} else {
    echo "Invalid request method.";
}
?>
PK��\.�*]VVuploadSchedule.phpnu�[���<?php include('head.php'); ?>

<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-upload bg-blue"></i>
                        <div class="d-inline">
                            <h5>Upload Schedules</h5>
                            <span>Upload schedules via CSV or Excel files</span>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4"></div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h3>Upload Schedules</h3>
            </div>
            <div class="card-body">
                <div id="drop-area" class="drop-area">
                    <form id="uploadForm" class="my-form" enctype="multipart/form-data">
                        <p>Drag and drop your file here, or click to select it.</p>
                        <input type="file" name="csv_file" id="csv_file" accept=".csv, .xls, .xlsx">

                        <!-- Hidden current user id -->
                        <input type="hidden" name="current_user_id" value="<?php echo $companyId; ?>">
                    </form>
                </div>
                <button id="uploadBtn" class="btn btn-primary">Upload</button>
                <div id="overlay" class="overlay">
                    <div class="loader"></div>
                    <p>Uploading...</p>
                </div>
                <div id="responseMessage"></div>
            </div>
        </div>
    </div>
</div>

<style>
    .drop-area {
        border: 2px dashed #ccc;
        padding: 20px;
        text-align: center;
        transition: border .3s ease-in-out;
    }

    .drop-area.highlight {
        border-color: #007bff;
    }

    .button {
        display: inline-block;
        padding: 8px 20px;
        background-color: #007bff;
        color: #fff;
        cursor: pointer;
        border-radius: 4px;
        margin-top: 10px;
    }

    .button:hover {
        background-color: #0056b3;
    }

    .overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        justify-content: center;
        align-items: center;
        z-index: 999;
    }

    .overlay .loader {
        border: 6px solid #f3f3f3;
        border-radius: 50%;
        border-top: 6px solid #3498db;
        width: 50px;
        height: 50px;
        animation: spin 1s linear infinite;
    }

    @keyframes spin {
        0% {
            transform: rotate(0deg);
        }

        100% {
            transform: rotate(360deg);
        }
    }
</style>

<!-- SweetAlert CDN -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        let dropArea = document.getElementById('drop-area');
        let overlay = document.getElementById('overlay');
        let responseMessage = document.getElementById('responseMessage');

        // Prevent default drag behaviors
        ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
            dropArea.addEventListener(eventName, preventDefaults, false);
        });

        function preventDefaults(e) {
            e.preventDefault();
            e.stopPropagation();
        }

        // Highlight drop area when item is dragged over it
        ['dragenter', 'dragover'].forEach(eventName => {
            dropArea.addEventListener(eventName, highlight, false);
        });

        ['dragleave', 'drop'].forEach(eventName => {
            dropArea.addEventListener(eventName, unhighlight, false);
        });

        function highlight(e) {
            dropArea.classList.add('highlight');
        }

        function unhighlight(e) {
            dropArea.classList.remove('highlight');
        }

        // Handle dropped files
        dropArea.addEventListener('drop', handleDrop, false);

        function handleDrop(e) {
            let dt = e.dataTransfer;
            let files = dt.files;
            handleFiles(files);
        }

        function handleFiles(files) {
            const formData = new FormData();
            formData.append('csv_file', files[0]);
            formData.append('current_user_id', <?php echo $companyId; ?>);

            // Show overlay while uploading
            overlay.style.display = 'flex';

            Swal.fire({
                title: 'Uploading...',
                text: 'Please wait while the file is being uploaded.',
                allowOutsideClick: false,
                onBeforeOpen: () => {
                    Swal.showLoading();
                }
            });

            fetch('../process_upload.php', {
                method: 'POST',
                body: formData
            }).then(response => response.json())
                .then(data => {
                    console.log(data);
                    // Hide overlay on response
                    overlay.style.display = 'none';
                    Swal.close(); // Close Swal loading indicator

                    if (data.success) {
                        Swal.fire({
                            icon: 'success',
                            title: data.message,
                            text: 'File uploaded successfully'
                        });
                    } else {
                        Swal.fire({
                            icon: 'error',
                            title: 'Upload Failed',
                            text: 'File upload failed: ' + data.error
                        });
                    }
                    // Display response message
                    responseMessage.innerHTML = data.success ? '<div class="alert alert-success">Schedule uploaded successfully.</div>' : '<div class="alert alert-danger">File upload failed: ' + data.error + '</div>';
                }).catch(error => {
                console.error('Error:', error);
                // Hide overlay on error
                overlay.style.display = 'none';
                Swal.close(); // Close Swal loading indicator

                Swal.fire({
                    icon: 'error',
                    title: 'Upload Failed',
                    text: 'An error occurred while uploading the file.'
                });
                // Display error message
                responseMessage.innerHTML = '<div class="alert alert-danger">An error occurred while uploading the file.</div>';
            });
        }

        // Optional: Handle form submission (if needed)
        document.getElementById('uploadBtn').addEventListener('click', function(e) {
            e.preventDefault();
            handleFiles(document.getElementById('csv_file').files);
        });
    });
</script>

<?php include('footer.php'); ?>
PK��\��VV
navbar.phpnu�[���<div class="modal fade apps-modal" id="appsModal" tabindex="-1" role="dialog" aria-labelledby="appsModalLabel" aria-hidden="true" data-backdrop="false">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="ik ik-x-circle"></i></button>
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="quick-search">
                <div class="container">
                    <div class="row">
                        <div class="col-md-4 ml-auto mr-auto">
                            <div class="input-wrap">
                                <input type="text" id="quick-search" class="form-control" placeholder="Search..." />
                                <i class="ik ik-search"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-body d-flex align-items-center">
                <div class="container">
                    <div class="apps-wrap">
                        <div class="app-item">
                            <a href="#"><i class="ik ik-bar-chart-2"></i><span>Dashboard</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-mail"></i><span>Message</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-users"></i><span>Accounts</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-shopping-cart"></i><span>Sales</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-briefcase"></i><span>Purchase</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-server"></i><span>Menus</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-clipboard"></i><span>Pages</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-message-square"></i><span>Chats</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-map-pin"></i><span>Contacts</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-box"></i><span>Blocks</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-calendar"></i><span>Events</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-bell"></i><span>Notifications</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-pie-chart"></i><span>Reports</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-layers"></i><span>Tasks</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-edit"></i><span>Blogs</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-settings"></i><span>Settings</span></a>
                        </div>
                        <div class="app-item">
                            <a href="#"><i class="ik ik-more-horizontal"></i><span>More</span></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>PK��\��D���delete_schedule.phpnu�[���<?php
require_once '../../Classes/Database.php';
require_once '../../Service/ScheduleService.php';
require_once '../../Classes/System.php';

$System = new System();
$scheduleService = new ScheduleService();

if (isset($_POST['scheduleId']) && !empty($_POST['scheduleId'])) {
    $scheduleId = $System->decryptData($_POST['scheduleId']);

    if (!$scheduleId) {
        echo "Invalid Schedule ID";
        exit;
    }

    $deleteResult = $scheduleService->deleteScheduleWithTasks($scheduleId);

    if ($deleteResult) {
        echo "success";
    } else {
        echo $deleteResult;
    }
} else {
    echo "Schedule ID is missing";
}
?>
PK��\� ?��viewtask.phpnu�[���<?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: "The URL parameter is invalid. Please go back and try again.",
                icon: "error",
                confirmButtonText: "Ok"
            }).then(() => {
                window.location.href = "tasks.php";
            });
        </script>';
    }


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

    // show error if the task is not found with Swal alert
    if (!$task) {
        exit();
    }


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

$subtaskDates= '';

for ($i = 0; $i < count($subtasks); $i++) {
    $subtaskDates .= '"' . $subtasks[$i]->subtask_date . '"';
    if ($i < count($subtasks) - 1) {
        $subtaskDates .= ',';
    }
}
?>

<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="modal fade" id="AssignTaskModal" role="dialog" aria-labelledby="exampleModalCenterLabel"
             aria-hidden="true">
            <div class="modal-dialog modal-lg mt-0 mb-0" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterLabel">Assign Task to Company</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">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group row">

                                        <div class="col-sm-9">
                                            <input type="hidden" id="schedule-id" name="schedule-id" class="form-control"
                                                   value="<?php echo $taskId; ?>" readonly>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="companyId" class="col-sm-3 col-form-label">Company:</label>
                                        <div class="col-sm-9">
                                            <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 companies available</option>';
                                                }
                                                ?>
                                            </select>
                                        </div>

                                    </div>

                                </div>
                            </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" form="tasksForm" id="assignTask" class="btn btn-primary">Assign Task
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="AddSubtaskModal" tabindex="-1" role="dialog" aria-labelledby="AddSubtaskModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="AddSubtaskModalLabel">Add Subtask</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <form id="addSubtaskForm">
                        <div class="modal-body">
                            <input type="hidden" name="task_id" value="<?php echo $taskId; ?>">
                            <input type="hidden" class="form-control" id="service_name" name="service_name" value="<?php echo $task->service_id; ?>">
                            <div class="form-group">
                                <label for="subtask_date">Subtask Date</label>
                                <input type="date" class="form-control" id="subtask_date" name="subtask_date" required>
                            </div>
                            <div class="form-group">

                                    <label for="subtask_time">Subtask Time</label>
                                    <input type="time" class="form-control" id="subtask_time" name="subtask_time" required>

<!--                                <label for="subtask_time">Subtask Time</label>-->
<!--                                <input type="time" class="form-control" id="subtask_time" name="subtask_time">-->
                            </div>
                            <!-- Add more fields as needed -->
                            <script>
                                //Disable all dates before today
                                var today = new Date();
                                var dd = today.getDate();
                                var mm = today.getMonth() + 1; //January is 0!
                                var yyyy = today.getFullYear();
                                if (dd < 10) {
                                    dd = '0' + dd
                                }
                                if (mm < 10) {
                                    mm = '0' + mm
                                }
                                today = yyyy + '-' + mm + '-' + dd;
                                document.getElementById("subtask_date").setAttribute("min", today);



                            </script>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Save changes</button>
                        </div>
                    </form>
                    <script>
                        var addSubtaskForm = document.getElementById('addSubtaskForm');
                        if (addSubtaskForm) {
                            addSubtaskForm.addEventListener('submit', function (e) {
                                e.preventDefault();
                                var formData = new FormData(addSubtaskForm);
                                var xhr = new XMLHttpRequest();
                                xhr.open('POST', 'add_subtask.php', true);
                                xhr.onreadystatechange = function () {
                                    if (xhr.readyState == 4 && xhr.status == 200) {
                                        console.log(xhr.responseText); // Log the response
                                        if (xhr.responseText === 'Subtask added successfully!') {
                                            Swal.fire({
                                                title: 'Subtask added successfully.',
                                                icon: 'success',
                                                confirmButtonText: 'Ok'
                                            });
                                            // Optionally reload the page after a short delay
                                            setTimeout(() => {
                                                window.location.reload();
                                            }, 2000);
                                        } else if (xhr.responseText === 'error') {
                                            Swal.fire({
                                                title: 'An error occurred',
                                                text: 'Please try again.',
                                                icon: 'error',
                                                confirmButtonText: 'Ok'
                                            });
                                        } else if (xhr.responseText === 'invalid_data') {
                                            Swal.fire({
                                                title: 'Invalid data',
                                                text: 'Please check the data and try again.',
                                                icon: 'error',
                                                confirmButtonText: 'Ok'
                                            });
                                        } else if (xhr.responseText === 'invalid_request') {
                                            Swal.fire({
                                                title: 'Invalid request',
                                                text: 'Please check the request and try again.',
                                                icon: 'error',
                                                confirmButtonText: 'Ok'
                                            });
                                        }
                                    }
                                };
                                xhr.send(formData);
                            });
                        } else {
                            console.error('Add subtask form not found.');
                        }
                    </script>

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



        <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>

<!--                                    is public or not-->


                                    </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>

                                    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 class="card-header-right">
                            <?php if($task->is_assigned == 0 ){
                                echo '<button type="button" class="btn btn-success" data-toggle="modal" data-target="#AddSubtaskModal">Add Subtask </button>';
                            }
                            ?>

                        </div>
                    </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>Time</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 $subtask->subtask_time? $date = date("g:i A", strtotime($subtask->subtask_time)) : ''; ?></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>
                                            <!-- if subtask is not assigned to any company then delete button will be shown -->
                                            <?php
                                            if ($subtask->assigned == 0 && $task->is_assigned == 0) {
                                                echo '<button type="button" class="btn btn-danger delete-subtask" data-subtask-id="'.$subtask->id.'">Delete</button>';
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                ?>
                                </tbody>
                            </table>
                            <?php
                        } else {
                            echo '<p>No subtasks found for this task.</p>';
                        }
                        ?>
                    </div>

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

    </div>
</div>

<script>
    var assignTaskButton = document.getElementById('assignTask');
    if (assignTaskButton) {
        assignTaskButton.addEventListener('click', function () {
            console.log('Assign task button found.');

            var companyId = document.getElementById('companyId').value;
            if (companyId) {
                Swal.fire({
                    title: 'Are you sure?',
                    text: "Do you want to assign this task to the selected company?",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonText: 'Yes, assign it!',
                    cancelButtonText: 'No, cancel'
                }).then((result) => {
                    if (result.isConfirmed) {
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', 'assigntask.php', true);
                        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        xhr.onreadystatechange = function () {
                            if (xhr.readyState == 4 && xhr.status == 200) {
                                console.log(xhr.responseText); // Log the response
                                if (xhr.responseText === 'success') {
                                    Swal.fire({
                                        title: 'Task assigned successfully.',
                                        icon: 'success',
                                        confirmButtonText: 'Ok'
                                    });
                                    // Optionally reload the page after a short delay
                                    setTimeout(() => {
                                        window.location.reload();
                                    }, 2000);
                                } else if (xhr.responseText === 'error') {
                                    Swal.fire({
                                        title: 'An error occurred',
                                        text: 'Please try again.',
                                        icon: 'error',
                                        confirmButtonText: 'Ok'
                                    });
                                } else if (xhr.responseText === 'task_not_found') {
                                    Swal.fire({
                                        title: 'Task not found',
                                        text: 'Please check the task ID.',
                                        icon: 'error',
                                        confirmButtonText: 'Ok'
                                    });
                                } else if (xhr.responseText === 'invalid_data') {
                                    Swal.fire({
                                        title: 'Invalid data',
                                        text: 'Please check the data and try again.',
                                        icon: 'error',
                                        confirmButtonText: 'Ok'
                                    });
                                } else if (xhr.responseText === 'invalid_request') {
                                    Swal.fire({
                                        title: 'Invalid request',
                                        text: 'Please check the request and try again.',
                                        icon: 'error',
                                        confirmButtonText: 'Ok'
                                    });
                                }
                            }
                        };
                        var taskId = '<?php echo htmlspecialchars($taskId); ?>';
                        xhr.send('taskId=' + taskId + '&companyId=' + companyId);
                    }
                });
            }
        });
    } else {
        console.error('Assign task button not found.');
    }

    // make public button
    var makePublicButton = document.getElementById('makePublic');
    if (makePublicButton) {
        makePublicButton.addEventListener('click', function () {
            console.log('Make public button found.');

            Swal.fire({
                title: 'Are you sure?',
                text: "Do you want to make this task public?",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Yes, make it public!',
                cancelButtonText: 'No, cancel'
            }).then((result) => {
                if (result.isConfirmed) {
                    var xhr = new XMLHttpRequest();
                    xhr.open('POST', 'makepublic.php', true);
                    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xhr.onreadystatechange = function () {
                        if (xhr.readyState == 4 && xhr.status == 200) {
                            console.log(xhr.responseText); // Log the response
                            if (xhr.responseText === 'success') {
                                Swal.fire({
                                    title: 'Task made public successfully.',
                                    icon: 'success',
                                    confirmButtonText: 'Ok'
                                });
                                // Optionally reload the page after a short delay
                                setTimeout(() => {
                                    window.location.reload();
                                }, 2000);
                            } else if (xhr.responseText === 'error') {
                                Swal.fire({
                                    title: 'An error occurred',
                                    text: 'Please try again.',
                                    icon: 'error',
                                    confirmButtonText: 'Ok'
                                });
                            } else if (xhr.responseText === 'task_not_found') {
                                Swal.fire({
                                    title: 'Task not found',
                                    text: 'Please check the task ID.',
                                    icon: 'error',
                                    confirmButtonText: 'Ok'
                                });
                            } else if (xhr.responseText === 'invalid_data') {
                                Swal.fire({
                                    title: 'Invalid data',
                                    text: 'Please check the data and try again.',
                                    icon: 'error',
                                    confirmButtonText: 'Ok'
                                });
                            } else if (xhr.responseText === 'invalid_request') {
                                Swal.fire({
                                    title: 'Invalid request',
                                    text: 'Please check the request and try again.',
                                    icon: 'error',
                                    confirmButtonText: 'Ok'
                                });
                            }
                        }
                    };
                    var taskId = '<?php echo htmlspecialchars($taskId); ?>';
                    xhr.send('taskId=' + taskId);
                }
            });
        });
    } else {
        console.error('Make public button not found.');
    }



    document.addEventListener('DOMContentLoaded', function() {
        // Find all delete buttons and attach click event
        var deleteButtons = document.querySelectorAll('.delete-subtask');
        deleteButtons.forEach(function(button) {
            button.addEventListener('click', function() {
                var subtaskId = button.getAttribute('data-subtask-id');

                // Show confirmation dialog using SweetAlert
                Swal.fire({
                    title: 'Are you sure?',
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!'
                }).then((result) => {
                    if (result.isConfirmed) {
                        // If confirmed, make AJAX request to delete_subtask.php
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', 'delete_subtask.php', true);
                        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        xhr.onreadystatechange = function() {
                            if (xhr.readyState == 4 && xhr.status == 200) {
                                console.log(xhr.responseText); // Log the response for debugging
                                if (xhr.responseText === 'success') {
                                    Swal.fire({
                                        title: 'Deleted!',
                                        text: 'Your subtask has been deleted.',
                                        icon: 'success'
                                    }).then(() => {
                                        window.location.reload(); // Reload the page after deletion
                                    });
                                } else {
                                    Swal.fire({
                                        title: 'Error!',
                                        text: 'Failed to delete subtask.',
                                        icon: 'error'
                                    });
                                }
                            }
                        };
                        xhr.send('subtaskId=' + subtaskId); // Send subtask ID to delete_subtask.php
                    }
                });
            });
        });
    });
</script>


<?php include('footer.php'); ?>
PK��\�_���scripts.phpnu�[���

<script src="../../node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../../node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
<script src="../../node_modules/screenfull/dist/screenfull.js"></script>
<script src="../../node_modules/flatpickr/dist/flatpickr.js"></script>
<script src="../../node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
<script src="../../dist/js/theme.min.js"></script>


<script src="../../node_modules/popper.js/dist/umd/popper.min.js"></script>

<script src="../../node_modules/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../../node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../../node_modules/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
<script src="../../node_modules/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

<script src="../../node_modules/d3/dist/d3.min.js"></script>
<script src="../../node_modules/c3/c3.min.js"></script>
<script src="../../js/tables.js"></script>
<!--<script src="../../js/widgets.js"></script>-->
<script src="../../js/charts.js"></script>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js"></script>



<script src="../../node_modules/flatpickr/dist/flatpickr.min.js"></script>



<script src="../../node_modules/select2/dist/js/select2.min.js"></script>
<script src="../../node_modules/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
<script src="../../node_modules/jquery.repeater/jquery.repeater.min.js"></script>
<!--<script src="../../node_modules/mohithg-switchery/dist/switchery.min.js"></script>-->
<!--<script src="../../js/form-advanced.js"></script>-->
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
    (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
        function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
        e=o.createElement(i);r=o.getElementsByTagName(i)[0];
        e.src='https://www.google-analytics.com/analytics.js';
        r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
    ga('create','UA-XXXXX-X','auto');ga('send','pageview');
</script>
<script>
    var scriptUrls = {};
    var scripts = document.getElementsByTagName('script');
    for (var i = 0; i < scripts.length; i++) {
        var src = scripts[i].src;
        if (src && !scriptUrls[src]) {
            scriptUrls[src] = true;
        } else {
            scripts[i].parentNode.removeChild(scripts[i]);
        }
    }
</script>

<script>
    $(document).ready(function() {
        $('.select2').select2();
    });

</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<script src="../../node_modules/select2/dist/js/select2.min.js"></script>
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>



</body>
</html>
PK��\
U�6�6addtasks.phpnu�[���<?php include('head.php'); ?>

<?php
require_once '../../Service/ServiceService.php';

// Create ServiceService instance
$serviceService = new ServiceService();
$services = $serviceService->getAllServicesForDropdown();

?>

<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-edit bg-blue"></i>
                        <div class="d-inline">
                            <h5>Add Tasks</h5>
                            <span>Add tasks to the schedule</span>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4"></div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <div class="card-header-left">
                    <h3>Add Tasks</h3>
                </div>
                <div class="card-header-right">


                </div>
            </div>
            <div class="card-body">
                <p>Click the add button to repeat the form</p>
                <div class="form-group">
                    <label for="schedule-name" class="sr-only">Schedule Name</label>
                    <input type="text" class="form-control" id="schedule-name" placeholder="Schedule Name">
                    <input type="hidden" id="current-user" value="<?php echo $_SESSION['user_id']; ?>">
                </div>
                <form class="form-inline repeater">
                    <div data-repeater-list="group-a">
                        <div data-repeater-item="" class="d-flex mb-2">
                            <table class="left-column">
                                <tr>
                                    <td>
                                        <div class="form-group mb-2">
                                            <label for="service-name" class="service-name-label">Service Name</label>
                                            <select name="service-name" class="form-control select2 service-name-select">
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="form-group mb-2">
                                            <label for="frequency" class="frequency-label">Frequency</label>
                                            <select class="form-control frequencySelect" name="frequency">
                                                <option value="daily">Daily</option>
                                                <option value="3x/week">3x/week</option>

                                            </select>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                            <div class="form-group mb-2 mr-sm-2 mb-sm-0">
                                <input type="text" class="form-control date-picker" placeholder="Select Date" hidden>
                            </div>
                            <div class="date-time-container mb-2 mr-sm-2 mb-sm-0 flex-grow-1">
                                <!-- Date and time fields will be appended here -->
                            </div>
                            <button data-repeater-delete type="button" class="btn btn-danger btn-icon ml-2">
                                <i class="ik ik-trash-2"></i>
                            </button>
                        </div>
                    </div>
                    <button data-repeater-create type="button" class="btn btn-success btn-icon ml-2 mb-2">
                        <i class="ik ik-plus"></i>
                    </button>
                </form>
                <button id="addTaskBtn" class="btn btn-primary">Add Tasks</button>
            </div>
        </div>
    </div>
</div>

<style>
    .card-body {
        width: 100%;
    }
    .repeater {
    }
    .repeater > div {
        background-color: #f9f9f9;
    }
    label {
        font-weight: bold;
    }
    .form-control {
        width: 100%;
    }
</style>
<script>
    $(document).ready(function () {
        function initializeFlatpickr() {
            $('.date-picker').each(function () {
                flatpickr(this, {
                    dateFormat: "Y-m-d",
                    mode: "multiple",
                    inline: true,
                    onChange: function (selectedDates, dateStr, instance) {
                        const container = $(instance.element).closest('.d-flex').find('.date-time-container');
                        const existingDateTimePairs = [];

                        container.find('.form-group').each(function () {
                            const date = $(this).find('input[type="text"]').first().val();
                            const time = $(this).find('.time-picker').val();
                            existingDateTimePairs.push({date, time});
                        });

                        selectedDates.sort((a, b) => new Date(a) - new Date(b));

                        container.empty();

                        selectedDates.forEach((date) => {
                            const formattedDate = formatDate(date);
                            let timeValue = '';

                            existingDateTimePairs.forEach(pair => {
                                if (pair.date === formattedDate) {
                                    timeValue = pair.time;
                                }
                            });


                                container.append(`
                                    <div class="form-group mb-2 mr-sm-2 mb-sm-0">
                                        <input type="text" class="form-control" value="${formattedDate}" readonly>
                                        <input type="text" class="form-control time-picker" placeholder="Start Time" value="${timeValue}">

                                    </div>
                                `);



                        });

                        initializeTimePicker(container);
                    }
                });
            });
        }

        function initializeTimePicker(container) {
            container.find('.time-picker').each(function () {
                flatpickr(this, {
                    enableTime: true,
                    noCalendar: true,
                    dateFormat: "H:i",
                });
            });
        }

        function formatDate(date) {
            const year = date.getFullYear();
            const month = (date.getMonth() + 1).toString().padStart(2, '0');
            const day = date.getDate().toString().padStart(2, '0');
            return `${year}-${month}-${day}`;
        }



        $('.repeater').repeater({
            show: function () {
                $(this).slideDown();
                initializeFlatpickr();

                populateServiceNames($(this).find('.service-name-select'));
                initializeSelect2($(this).find('.service-name-select')); // Initialize Select2 for new element
            },
            hide: function (deleteElement) {
                const container = $(deleteElement).closest('.d-flex').find('.date-time-container');
                container.find('.form-group').remove();
                $(deleteElement).remove();
            },
            ready: function (setIndexes) {
                initializeFlatpickr();

                populateServiceNames($('.service-name-select'));
                initializeSelect2($('.service-name-select')); // Initialize Select2 for existing elements
            }
        });

        initializeFlatpickr();


        function populateServiceNames(selectElement) {
            var services = <?php echo json_encode($services); ?>;
            services.forEach(service => {
                var option = document.createElement("option");
                option.value = service.id;
                option.textContent = service.name;
                selectElement.append(option);
            });
        }

        function initializeSelect2(selectElement) {
            selectElement.select2({
                placeholder: 'Select a service',
                allowClear: true
            });
        }

        $('#addTaskBtn').click(function (event) {
            event.preventDefault();

            var scheduleName = $('#schedule-name').val().trim();
            var currentUserId = $('#current-user').val().trim();
            var tasks = [];

            $('div[data-repeater-item]').each(function () {
                var dates = [];
                var service = $(this).find('.service-name-select').val().trim();
                var frequency = $(this).find('.frequencySelect').val().trim();

                $(this).find('.date-time-container .form-group').each(function () {
                    var date = $(this).find('input[type="text"]').first().val().trim();

                    //if a daily task send time otherwise time is empty
                    var time = frequency === 'daily' ? $(this).find('.time-picker').val().trim() : '';

                    dates.push({date: date, time: time});
                });

                tasks.push({
                    service: service,
                    frequency: frequency,
                    dates: dates
                });
            });

            var postData = {
                scheduleName: scheduleName,
                currentUserId: currentUserId,
                tasks: tasks
            };

            if (scheduleName === '') {
                Swal.fire({
                    title: 'Error',
                    text: 'Please enter a schedule name',
                    icon: 'error',
                    confirmButtonText: 'Close'
                });
                return;
            }

            if (tasks.length === 0) {
                Swal.fire({
                    title: 'Error',
                    text: 'Please add at least one task',
                    icon: 'error',
                    confirmButtonText: 'Close'
                });
                return;
            }

            if (tasks.some(task => task.dates.length === 0)) {
                Swal.fire({
                    title: 'Error',
                    text: 'Please select at least one date and time for each task',
                    icon: 'error',
                    confirmButtonText: 'Close'
                });
                return;
            }

            Swal.fire({
                title: 'Form Data',

                text: 'Are you sure you want to submit the form data?',
                confirmButtonText: 'Confirm',
                cancelButtonText: 'Cancel',
                showCancelButton: true,
                showLoaderOnConfirm: true,
                preConfirm: () => {
                    return new Promise(function (resolve, reject) {
                        $.ajax({
                            type: 'POST',
                            url: 'add_tasks.php',
                            data: JSON.stringify(postData),
                            contentType: 'application/json',
                            success: function (response) {
                                resolve(response);
                            },
                            error: function (xhr, status, error) {
                                reject(error);
                            }
                        });
                    });
                },
                allowOutsideClick: () => !Swal.isLoading()
            }).then((result) => {
                if (result.isConfirmed) {
                    var response = JSON.parse(result.value);

                    if (response.success) {
                        Swal.fire({
                            title: 'Success',
                            text: response.message,
                            icon: 'success',
                            confirmButtonText: 'Close'
                        }).then(() => {
                            window.location.href = 'viewscheduletasks.php?id=' + btoa(response.schedule_id);
                        });
                    } else {
                        Swal.fire({
                            title: 'Error',
                            text: response.message,
                            icon: 'error',
                            confirmButtonText: 'Close'
                        });
                    }
                } else if (result.dismiss === Swal.DismissReason.cancel) {
                    Swal.fire({
                        title: 'Cancelled',
                        text: 'You cancelled the operation',
                        icon: 'info',
                        confirmButtonText: 'Close'
                    });
                }
            }).catch((error) => {
                console.error('Error:', error);
                Swal.fire({
                    title: 'Error',
                    text: 'An error occurred while processing your request. Please try again later.',
                    icon: 'error',
                    confirmButtonText: 'Close'
                });
            });
        });

        // Initialize service names in the first select and apply Select2

        initializeSelect2($('.service-name-select').first());
    });
</script>

<?php include('footer.php'); ?>
PK��\�0��sidebar.phpnu�[���<div class="app-sidebar colored">
    <div class="sidebar-header">
        <a class="header-brand" href="#">
            <div class="logo-img">
<!--                <img src="../../src/img/Emera-Primary-Logo.png" class="header-brand-img" alt="Emera Primary Logo" height="50px">-->
            </div>
            <img src="../../src/img/Emera-Primary-Logo-White.png" class="header-brand-img" alt="Emera Primary Logo" height="50px">
        </a>
        <button type="button" class="nav-toggle"><i data-toggle="expanded" class="ik ik-toggle-right toggle-icon"></i></button>
        <button id="sidebarClose" class="nav-close"><i class="ik ik-x"></i></button>
    </div>

    <div class="sidebar-content">
        <div class="nav-container">
            <nav id="main-menu-navigation" class="navigation-main">
                <div class="nav-item">
                    <a href="dashboard.php"><i class="ik ik-bar-chart-2"></i><span>Dashboard</span></a>
                </div>
                <div class="nav-lavel">Tasks</div>
                <div class="nav-item">
                    <a href="addtasks.php"><i class="ik ik-box"></i><span>Add Schedules</span></a>
                    <a href="uploadSchedule.php"><i class="ik ik-upload"></i><span>Upload Schedules</span></a>
                </div>
                <div class="nav-lavel">Schedules</div>
                <div class="nav-item">
                    <a href="viewschedules.php"><i class="ik ik-calendar"></i><span>View Schedules</span></a>
                </div>
                <div class="nav-lavel">Services</div>
                <div class="nav-item">
                    <a href="viewservices.php"><i class="ik ik-map-pin"></i><span>Service Locations</span></a>
                </div>
                <div class="nav-lavel">Reports</div>
                <div class="nav-item">
                    <a href="reports.php"><i class="ik ik-pie-chart"></i><span>Reports</span></a>
                </div>
                <div class="nav-lavel">Logout</div>
                <div class="nav-item">
                    <a href="../logout.php" id="logout-link"><i class="ik ik-power"></i><span>Logout</span></a>
                </div>

                <script>
                    document.getElementById('logout-link').addEventListener('click', function(event) {
                        event.preventDefault(); // Prevent the default action

                        Swal.fire({
                            title: 'Are you sure?',
                            text: "You won't be able to revert this!",
                            icon: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: 'Yes, log out!'
                        }).then((result) => {
                            if (result.isConfirmed) {
                                window.location.href ='../logout.php';
                            }
                        });
                    });
                </script>
            </nav>
        </div>
    </div>
</div>PK��\��b�)�)viewservices.phpnu�[���<?php
include('head.php');
require_once '../../Service/ServiceService.php';
require_once '../../Classes/System.php';

$System = new System();
$serviceService = new ServiceService();
$services = $serviceService->getAllServices();
?>

<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 Services</h5>
                            <span>View all services</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="#">Services</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">View Services</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
                            <i class="ik ik-plus"></i> Create Service
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterLabel">Add a new service</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="serviceForm" class="forms-sample">
                            <div class="form-group row">
                                <label for="name" class="col-sm-3 col-form-label">Name:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="name" name="name" class="form-control" required placeholder="Enter service name">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="region" class="col-sm-3 col-form-label">Region:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="region" name="region" class="form-control" required placeholder="Enter region">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="address_line1" class="col-sm-3 col-form-label">Address Line 1:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="address_line1" name="address_line1" class="form-control"  placeholder="Enter address line 1">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="address_line2" class="col-sm-3 col-form-label">Address Line 2:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="address_line2" name="address_line2" class="form-control" placeholder="Enter address line 2">
                                </div>
                            </div>
                            <div class="form-group row">

                                <div class="col-sm-9">
                                    <input type="hidden" id="suburb" name="suburb" class="form-control"  placeholder="Enter suburb">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="city" class="col-sm-3 col-form-label">City:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="city" name="city" class="form-control"  placeholder="Enter city">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="state" class="col-sm-3 col-form-label">State:</label>
                                <div class="col-sm-9">
                                    <input type="text" id="state" name="state" class="form-control"  placeholder="Enter state">
                                </div>
                            </div>
                            <div class="form-group row">

                                <div class="col-sm-9">
                                    <input type="hidden" id="postal_code" name="postal_code" class="form-control"  placeholder="Enter postal code">
                                </div>
                            </div>
                            <div class="form-group row">

                                <div class="col-sm-9">
                                    <input type="hidden" id="country" name="country" class="form-control"  placeholder="Enter country">
                                </div>
                            </div>
                            <div class="form-group row">

                                <div class="col-sm-9">
                                    <input type="hidden" id="latitude" name="latitude" class="form-control" placeholder="Enter latitude">
                                </div>
                            </div>
                            <div class="form-group row">

                                <div class="col-sm-9">
                                    <input type="hidden" id="longitude" name="longitude" class="form-control" placeholder="Enter longitude">
                                </div>
                            </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="submit" form="serviceForm" class="btn btn-primary">Add Service</button>
                    </div>
                </div>
            </div>
        </div>







        <script>
            document.getElementById('serviceForm').addEventListener('submit', function(event) {
                event.preventDefault();

                const formData = new FormData(this);
                fetch('submit_service.php', {
                    method: 'POST',
                    body: formData
                })
                    .then(response => response.text())
                    .then(data => {
                        const messageDiv = document.getElementById('message');
                        messageDiv.textContent = data;
                        messageDiv.classList.add('alert', 'alert-success');

                        Swal.fire({
                            title: 'Success!',
                            text: data,
                            icon: 'success',
                            confirmButtonText: 'Ok'
                        }).then(() => {
                            location.reload();
                        });

                        document.getElementById('serviceForm').reset();
                    })
                    .catch(error => {
                        const messageDiv = document.getElementById('message');
                        messageDiv.textContent = 'Error: ' + error;
                        messageDiv.classList.add('alert', 'alert-danger');

                        Swal.fire({
                            title: 'Error!',
                            text: error,
                            icon: 'error',
                            confirmButtonText: 'Ok'
                        });
                    });
            });


        </script>
        <!-- continued from previous code snippet -->


        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <table id="advanced_table" class="table">
                            <thead>
                            <tr>
                                <th>Name</th>
                                <th>Region</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($services as $service): ?>
                                <tr>
                                    <td><?php echo $service->name; ?></td>
                                    <td><?php echo $service->region; ?></td>

                                    <td>

                                        <a href="viewservice.php?id=<?php echo $System->encryptData($service->id); ?>" class="btn btn-success">
                                            <i class="ik ik-eye text-white"></i> View
                                        </a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div>

    </div>
</div>





<?php include('footer.php'); ?>
PK��\�7̳��submit_schedule.phpnu�[���<?php


require_once '../../Classes/Schedules.php';
require_once '../../Service/ScheduleService.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $schedule_name = $_POST['schedule-name'];
    $currentUser = $_POST['created_by'];


    $completed = false; // Default value
    $created_at = date('Y-m-d H:i:s');
    $updated_at = date('Y-m-d H:i:s');

    $schedule = new Schedules(null, $schedule_name, $currentUser, $completed, $created_at, $updated_at);

    $scheduleService = new ScheduleService();
    if ($scheduleService->addSchedule($schedule)) {
        echo "Schedule added successfully!";
    } else {
        echo "Failed to add schedule.";
    }
} else {
    echo "Invalid request method.";
}
?>
PK��\f�e���
header.phpnu�[���<header class="header-top" header-theme="dark">
    <div class="container-fluid">
        <div class="d-flex justify-content-between">
            <div class="top-menu d-flex align-items-center">
                <button type="button" class="btn-icon mobile-nav-toggle d-lg-none"><span></span></button>
                <div class="header-search">
                    
                </div>
                <button type="button" id="navbar-fullscreen" class="nav-link"><i class="ik ik-maximize"></i></button>
            </div>
            <div class="top-menu d-flex align-items-center">
<!--                <div class="dropdown">-->
<!--<!--                    <a class="nav-link dropdown-toggle" href="#" id="notiDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="ik ik-bell"></i><span class="badge bg-danger">3</span></a>-->-->
<!--                    <div class="dropdown-menu dropdown-menu-right notification-dropdown" aria-labelledby="notiDropdown">-->
<!--                        <h4 class="header">Notifications</h4>-->
<!--                        <div class="notifications-wrap">-->
<!--                            <a href="#" class="media">-->
<!--                                            <span class="d-flex">-->
<!--                                                <i class="ik ik-check"></i>-->
<!--                                            </span>-->
<!--                                <span class="media-body">-->
<!--                                                <span class="heading-font-family media-heading">Invitation accepted</span>-->
<!--                                                <span class="media-content">Your have been Invited ...</span>-->
<!--                                            </span>-->
<!--                            </a>-->
<!--                            <a href="#" class="media">-->
<!--                                            <span class="d-flex">-->
<!--                                                <img src="../../img/users/1.jpg" class="rounded-circle" alt="">-->
<!--                                            </span>-->
<!--                                <span class="media-body">-->
<!--                                                <span class="heading-font-family media-heading">Steve Smith</span>-->
<!--                                                <span class="media-content">I slowly updated projects</span>-->
<!--                                            </span>-->
<!--                            </a>-->
<!--                            <a href="#" class="media">-->
<!--                                            <span class="d-flex">-->
<!--                                                <i class="ik ik-calendar"></i>-->
<!--                                            </span>-->
<!--                                <span class="media-body">-->
<!--                                                <span class="heading-font-family media-heading">To Do</span>-->
<!--                                                <span class="media-content">Meeting with Nathan on Friday 8 AM ...</span>-->
<!--                                            </span>-->
<!--                            </a>-->
<!--                        </div>-->
<!--                        <div class="footer"><a href="javascript:void(0);">See all activity</a></div>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <button type="button" class="nav-link ml-10 right-sidebar-toggle"><i class="ik ik-message-square"></i><span class="badge bg-success">3</span></button>-->
<!--                <div class="dropdown">-->
<!--                    <a class="nav-link dropdown-toggle" href="#" id="menuDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="ik ik-plus"></i></a>-->
<!--                    <div class="dropdown-menu dropdown-menu-right menu-grid" aria-labelledby="menuDropdown">-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Dashboard"><i class="ik ik-bar-chart-2"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Message"><i class="ik ik-mail"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Accounts"><i class="ik ik-users"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Sales"><i class="ik ik-shopping-cart"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Purchase"><i class="ik ik-briefcase"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Pages"><i class="ik ik-clipboard"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Chats"><i class="ik ik-message-square"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Contacts"><i class="ik ik-map-pin"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Blocks"><i class="ik ik-inbox"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Events"><i class="ik ik-calendar"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="Notifications"><i class="ik ik-bell"></i></a>-->
<!--                        <a class="dropdown-item" href="#" data-toggle="tooltip" data-placement="top" title="More"><i class="ik ik-more-horizontal"></i></a>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <button type="button" class="nav-link ml-10" id="apps_modal_btn" data-toggle="modal" data-target="#appsModal"><i class="ik ik-grid"></i></button>-->
<!--                <div class="dropdown">-->
<!--                    <a class="dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img class="avatar" src="../../img/user.jpg" alt=""></a>-->
<!--                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">-->
<!--                        <a class="dropdown-item" href="#"><i class="ik ik-user dropdown-icon"></i> Profile</a>-->
<!--                        <a class="dropdown-item" href="#"><i class="ik ik-settings dropdown-icon"></i> Settings</a>-->
<!--                        <a class="dropdown-item" href="#"><span class="float-right"><span class="badge badge-primary">6</span></span><i class="ik ik-mail dropdown-icon"></i> Inbox</a>-->
<!--                        <a class="dropdown-item" href="#"><i class="ik ik-navigation dropdown-icon"></i> Message</a>-->
<!--                        <a class="dropdown-item" href="#"><i class="ik ik-power dropdown-icon"></i> Logout</a>-->
<!--                    </div>-->
<!--                </div>-->

            </div>
        </div>
    </div>
</header>PK��\��?��submit_task.phpnu�[���<?php

//$currentUser = $_SESSION['user_id'];

require_once '../../Classes/Task.php';
require_once '../../Service/TaskService.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $schedule_id = $_POST['schedule-id'];
    $service_id = $_POST['service-id'];
    $frequency = $_POST['frequency'];
    $dates = $_POST['dates'];
    $currentUser = $_POST['current-user'];
    $added_by = $currentUser;
    $updated_by = $currentUser;
    $created_at = date('Y-m-d H:i:s');
    $updated_at = date('Y-m-d H:i:s');
    
    

    $taskService = new TaskService();   
    
    
    $task = new Task('', $schedule_id, $service_id, $frequency,$dates,  $currentUser,  $currentUser, $created_at,$updated_at, false, null, false, false, false, null, null, false);
    if ($taskService->addTask($task)) {
        echo "Task added successfully!";
    } else {
        echo "Failed to add task.";
    }
} else {
    echo "Invalid request method.";
}

?>
PK��\�)�wwsubmit_service.phpnu�[���<?php


require_once '../../Classes/Service.php';
require_once '../../Service/ServiceService.php';

function validate_decimal($value) {
    if (is_numeric($value)) {
        return (float) $value;
    }
    return NULL; // Default to NULL if not a valid number
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = $_POST['name'];
    $region = $_POST['region'];
    $address_line1 = $_POST['address_line1'];
    $address_line2 = $_POST['address_line2'];
    $suburb = $_POST['suburb'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $postal_code = $_POST['postal_code'];
    $country = $_POST['country'];
    //decimal value of latitude and longitude
    $latitude = isset($_POST['latitude']) ? validate_decimal($_POST['latitude']) : NULL;
    $longitude = isset($_POST['longitude']) ? validate_decimal($_POST['longitude']) : NULL;
    $created_at = date('Y-m-d H:i:s');
    $updated_at = date('Y-m-d H:i:s');

    $serviceService = new ServiceService();
    
    $service = new Service("", $name, $region, $address_line1, $address_line2, $suburb, $city, $state, $postal_code, "Australia", "", "", "", "", $created_at, $updated_at);

    if ($serviceService->addService($service)) {
        echo "Service added successfully!";
    } else {
        echo "Failed to add service.";
    }
} else {
    echo "Invalid request method.";
}
?>
PK��\,!"�MMreports.phpnu�[���<?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';

// Initialize necessary services and classes
$System = new System();
$subtaskService = new SubtaskService();
$userService = new UserService();
?>

<style>
    .card {
        height: 300px; /* Increase the height of the cards */
        border-radius: 15px; /* Add rounded corners */
        margin-bottom: 20px; /* Add space between the cards */
    }

    .card-body {
        height: 200px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
</style>

<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 Reports</h5>
                        <span>Navigate to different reports</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="#">Reports</a></li>
                        <li class="breadcrumb-item active" aria-current="page">View Reports</li>
                    </ol>
                </nav>
            </div>
        </div>

        <div class="row mt-20">
            <!-- First card -->
            <div class="col-md-6">
                <a href="report_tasksstatusbyschedule.php" class="card text-center h-100">
                    <div class="card-body">
                        <i class="ik ik-calendar" style="font-size: 2em;"></i>
                        <h5 class="card-title">Schedule status</h5>
                        <p class="card-text">View the status of schedules</p>
                    </div>
                </a>
            </div>

            <!-- Second card -->
            <div class="col-md-6">
                <a href="report_alltasks.php" class="card text-center h-100">
                    <div class="card-body">
                        <i class="ik ik-box" style="font-size: 2em;"></i>
                        <h5 class="card-title text-center">All Tasks</h5>
                        <p class="card-text">View all tasks</p>
                    </div>
                </a>
            </div>
        </div>
        <div class="row mt-20">
            <!-- Third card -->
            <div class="col-md-6">
                <a href="report_viewsubtasksdaywise.php" class="card text-center h-100">
                    <div class="card-body">
                        <i class="ik ik-x-circle" style="font-size: 2em;"></i>
                        <h5 class="card-title text-center">Subtasks Day Wise</h5>
                        <p class="card-text">View subtasks day wise</p>
                    </div>
                </a>
            </div>
            <div class="col-md-6">
                <a href="report_subtaskswithnotes.php" class="card text-center h-100">
                    <div class="card-body">
                        <i class="ik ik-file-text" style="font-size: 2em;"></i>
                        <h5 class="card-title
                        text-center">Subtasks with Notes</h5>
                        <p class="card-text">View subtasks with notes</p>
                    </div>
                </a>
            </div>

            <!-- Fourth card -->
<!--            <div class="col-md-6">-->
<!--                <a href="reports_acceptedtasksbyusers.php" class="card text-center h-100">-->
<!--                    <div class="card-body">-->
<!--                        <i class="ik ik-trending-up" style="font-size: 2em;"></i>-->
<!--                        <h5 class="card-title">Accepted Tasks by Users</h5>-->
<!--                        <p class="card-text">View accepted tasks categorized by assigned users</p>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </div>-->
        </div>
        <div class="row mt-20 h-100">
            <!-- Fifth card -->
<!--            <div class="col-md-6">-->
<!--                <a href="report_TaskSummaryForUsers.php" class="card text-center h-100">-->
<!--                    <div class="card-body">-->
<!--                        <i class="ik ik-list" style="font-size: 2em;"></i>-->
<!--                        <h5 class="card-title text-center">Task Summary for Each Subcontractor</h5>-->
<!--                        <p class="card-text">View summary of tasks for each subcontractor</p>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </div>-->

            <!-- Sixth card -->
<!--            <div class="col-md-6">-->
<!--                <a href="#" class="card text-center h-100">-->
<!--                    <div class="card-body">-->
<!--                        <i class="ik ik-trending-down" style="font-size: 2em;"></i>-->
<!--                        <h5 class="card-title">Report 6</h5>-->
<!--                        <p class="card-text">Description of report 6</p>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </div>-->
        </div>
    </div>
</div>
<?php include('footer.php'); ?>
PK��\�o��
5
5viewschedules.phpnu�[���<?php
include('head.php');
// Include database connection and ScheduleService class

require_once '../../Service/ScheduleService.php';
require_once '../../Classes/System.php';

$System = new System();
// Create ScheduleService instance
$scheduleService = new ScheduleService();

// Initialize filters array
$filters = [];

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

// Fetch schedules from the database based on filters
$schedules = $scheduleService->getAllSchedules($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>View Schedules</h5>
                            <span>View all schedules</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="#">Schedules</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">View Schedules</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>



        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <div class="card-header-left">
                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter"><i class="ik ik-plus"></i> Create Schedule</button>
                        </div>
                        <div class="card-header-right">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Filter Form -->
        <div class="row mb-3">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <h3>Filter Schedules</h3>
                    </div>
                    <div class="card-body">
                        <form method="GET" action="">
                            <div class="form-row">
                                


                                <div class="form-group col-md-2">
                                    <label for="date_from">Date From</label>
                                    <input type="date" class="form-control" id="date_from" name="date_from" value="<?php echo htmlspecialchars($_GET['date_from'] ?? ''); ?>">
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="date_to">Date To</label>
                                    <input type="date" class="form-control" id="date_to" name="date_to" value="<?php echo htmlspecialchars($_GET['date_to'] ?? ''); ?>">
                                </div>
                            </div>
                            <button type="submit" class="btn btn-primary">Apply Filters</button>
                            <a href="viewschedules.php" class="btn btn-secondary">Clear Filters</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- End of Filter Form -->

        <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterLabel">Add a new schedule</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <form id="scheduleForm" class="forms-sample">
                                <div class="col-md-12">
                                    <div class="form-group row">
                                        <div class="col-sm-3">
                                            <label for="schedule-name" class="col-sm-3 col-form-label">Schedule Name:</label>
                                        </div>
                                        <div class="col-sm-9">
                                            <input type="text" id="schedule-name" name="schedule-name" class="form-control" required placeholder="Enter schedule name">
                                        </div>
                                        <input type="hidden"  name="created_by" value="<?php echo $companyId; ?>">
                                    </div>
                                    
                                </div>
                            </form>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                            </div>
                        </div>
                        <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="submit" form="scheduleForm" class="btn btn-primary">Add Schedule</button>
                    </div>
                </div>
            </div>
        </div>
        <script>
            document.getElementById('scheduleForm').addEventListener('submit', function (event) {
                event.preventDefault();

                const formData = new FormData(this);
                fetch('submit_schedule.php', {
                    method: 'POST',
                    body: formData
                })
                    .then(response => response.text())
                    .then(data => {
                        const messageDiv = document.getElementById('message');
                        messageDiv.textContent = data;
                        messageDiv.classList.add('alert', 'alert-success');

                        Swal.fire({
                            title: 'Success!',
                            text: data,
                            icon: 'success',
                            confirmButtonText: 'Ok'
                        }).then(() => {
                            location.reload();
                        });
                        // Reset form
                        document.getElementById('scheduleForm').reset();
                    })
                    .catch(error => {
                        const messageDiv = document.getElementById('message');
                        messageDiv.textContent = 'Error: ' + error;
                        messageDiv.classList.add('alert', 'alert-danger');

                        Swal.fire({
                            title: 'Error!',
                            text: error,
                            icon: 'error',
                            confirmButtonText: 'Ok'
                        });
                    });
            });
        </script>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <table id="advanced_table" class="table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Schedule Name</th>
                                

                                <th>Created By</th>
                                <th>Created At</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($schedules as $schedule): ?>
                                <tr>
                                    <td><?php echo 'SCH-000' . $schedule->id; ?></td>
                                    <td><?php echo $schedule->schedule_name; ?></td>
                                    

                                    <td><?php echo $schedule->created_by; ?></td>
                                    <td><?php echo date('F j, Y, g:i a', strtotime($schedule->created_at)); ?></td>
                                    <td>
                                        <a href="viewscheduletasks.php?id=<?php echo $System->encryptData($schedule->id) ?>" class="btn btn-primary">View Tasks</a>
                                        &nbsp;
                                        <!--                                        --><?php //if (!$scheduleService->hasAssignedTasks($schedule->id)): ?>
                                        <!--                                            <button class="btn btn-danger delete-schedule" data-schedule-id="--><?php //echo $System->encryptData($schedule->id); ?><!--">Delete</button>-->
                                        <!--                                        --><?php //endif; ?>
                                        <?php if (!$scheduleService->hasSubmittedSubTasks($schedule->id)): ?>
                                            <button type="button" class="btn btn-icon btn-danger delete-schedule" data-schedule-id="<?php echo $System->encryptData($schedule->id); ?>"><i class="ik ik-trash-2"></i></button>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Find all delete buttons and attach click event
        var deleteButtons = document.querySelectorAll('.delete-schedule');
        deleteButtons.forEach(function(button) {
            button.addEventListener('click', function() {
                var scheduleId = button.getAttribute('data-schedule-id');

                // Show confirmation dialog using SweetAlert
                Swal.fire({
                    title: 'Are you sure?',
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!'
                }).then((result) => {
                    if (result.isConfirmed) {
                        // If confirmed, make AJAX request to delete_schedule.php
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', 'delete_schedule.php', true);
                        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        xhr.onreadystatechange = function() {
                            if (xhr.readyState == 4 && xhr.status == 200) {
                                console.log(xhr.responseText); // Log the response for debugging
                                if (xhr.responseText === 'success') {
                                    Swal.fire({
                                        title: 'Deleted!',
                                        text: 'The schedule has been deleted.',
                                        icon: 'success'
                                    }).then(() => {
                                        window.location.reload(); // Reload the page after deletion
                                    });
                                } else {
                                    Swal.fire({
                                        title: 'Error!',
                                        text: 'An error occurred while deleting the schedule. Please try again.',
                                        icon: 'error'
                                    });
                                }
                            }
                        };
                        xhr.send('scheduleId=' + scheduleId); // Send schedule ID to delete_schedule.php
                    }
                });
            });
        });
    });
</script>
<?php include('footer.php'); ?>
PK��\o!C�delete_subtask.phpnu�[���<?php
// Include necessary files and instantiate objects
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';

$subTaskService = new SubtaskService();

// Check if subtask ID is provided via POST
if (isset($_POST['subtaskId'])) {
    $subtaskId = $_POST['subtaskId'];

    // Perform deletion of subtask
    if ($subTaskService->deleteSubtaskById($subtaskId)) {
        echo 'success';
    } else {
        echo 'error';
    }
} else {
    echo 'invalid_request';
}
?>
PK��\a��Fzzviewscheduletasks.phpnu�[���<?php include('head.php'); ?>
<?php
// Get schedule ID from URL parameter
$schedule_id = $_GET['id'];
// Include database connection and TaskService class
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';

require_once '../../Classes/System.php';

require_once '../../Service/ServiceService.php';


// Create ServiceService instance
$serviceService = new ServiceService();
$services = $serviceService->getAllServicesForDropdown();

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


$schedule_id = $System->decryptData($_GET['id']);
// show error if the provided id is not valid with Swal alert
if (!$schedule_id) {
    echo "<script>
        Swal.fire({
            title: 'Invalid Schedule 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;
}


// Fetch tasks from the database that belong to the given schedule
$tasks = $taskService->getTasksByScheduleId($schedule_id);
?>
<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 Tasks</h5>
                            <span>View tasks for the selected schedule</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="#">Schedules</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">View Tasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
        <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">

                            <!--                            <a href="createtasks.php?schedule_id=-->
                            <?php //echo $schedule_id; ?><!--" class="btn btn-outline-primary">Add Task</a>-->

                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                    data-target="#createTaskModal"><i class="ik ik-plus"></i>Create Task
                            </button>
                        </div>

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


        <div class="modal fade" id="createTaskModal" role="dialog" aria-labelledby="exampleModalCenterLabel"
             aria-hidden="true">
            <div class="modal-dialog modal-xl mt-0 mb-0" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalCenterLabel">Add a Task</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">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group row">
                                        <div class="col-sm-9">
                                            <input type="text" id="schedule-id" name="schedule-id" class="form-control"
                                                   value="<?php echo $schedule_id; ?>" <?php echo isset($schedule_id) ? 'readonly' : ''; ?>
                                                   hidden>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="service-id" class="col-sm-3 col-form-label">Service:</label>
                                        <div class="col-sm-9">
                                            <select id="service-id" name="service-id" class="form-control select2"></select>
                                        </div>
                                    </div>

                                    <input type="hidden" name="current-user" value="<?php echo $_SESSION['user_id']; ?>">

                                    <script>
                                        document.addEventListener('DOMContentLoaded', function () {
                                            var services = <?php echo json_encode($services); ?>;
                                            var serviceSelect = document.getElementById("service-id");

                                            services.forEach(service => {
                                                var option = document.createElement("option");
                                                option.value = service.id; // Use service ID as value
                                                option.textContent = service.name; // Show service name
                                                serviceSelect.appendChild(option);
                                            });
                                        });
                                    </script>

                                    <div class="form-group row">
                                        <label for="frequency" class="col-sm-3 col-form-label">Frequency:</label>
                                        <div class="col-sm-9">
                                            <select id="frequency" name="frequency" class="form-control select2 frequencySelect">
                                                <option value="daily">Daily</option>
                                                <option value="3x/week">3x/week</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <input type="text" id="dates" name="dates" hidden>
                                <div class="col-md-6">
                                    <div class="d-flex flex-column">
                                        <h1>Select Dates</h1>
                                        <div class="date-picker"></div>
                                        <div class="date-time-container"></div>
                                    </div>
                                </div>
                            </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="submit" form="tasksForm" class="btn btn-primary">Add Task</button>
                    </div>
                </div>
            </div>
        </div>

        <script src="../../node_modules/flatpickr/dist/flatpickr.js"></script>
        <script>
            document.addEventListener('DOMContentLoaded', function () {
                initializeFlatpickr();

            });

            function initializeFlatpickr() {
                $('.date-picker').each(function () {
                    flatpickr(this, {
                        dateFormat: "Y-m-d",
                        mode: "multiple",
                        inline: true,
                        onChange: function (selectedDates, dateStr, instance) {
                            const container = $(instance.element).closest('.d-flex').find('.date-time-container');
                            const existingDateTimePairs = [];

                            container.find('.form-group').each(function () {
                                const date = $(this).find('input[type="text"]').first().val();
                                const time = $(this).find('.time-picker').val();
                                existingDateTimePairs.push({ date, time });
                            });

                            selectedDates.sort((a, b) => new Date(a) - new Date(b));
                            container.empty();

                            selectedDates.forEach((date) => {
                                const formattedDate = formatDate(date);
                                let timeValue = '';

                                existingDateTimePairs.forEach(pair => {
                                    if (pair.date === formattedDate) {
                                        timeValue = pair.time;
                                    }
                                });

                                container.append(`
                            <div class="form-group mb-2 mr-sm-2 mb-sm-0">
                                <input type="text" class="form-control" value="${formattedDate}" readonly>
                                <input type="text" class="form-control time-picker" placeholder="Select Time" value="${timeValue}">
                            </div>
                        `);
                            });

                            initializeTimePicker(container);
                        }
                    });
                });
            }

            function initializeTimePicker(container) {
                container.find('.time-picker').each(function () {
                    flatpickr(this, {
                        enableTime: true,
                        noCalendar: true,
                        dateFormat: "H:i",
                    });
                });
            }

            function formatDate(date) {
                const year = date.getFullYear();
                const month = (date.getMonth() + 1).toString().padStart(2, '0');
                const day = date.getDate().toString().padStart(2, '0');
                return `${year}-${month}-${day}`;
            }



            document.getElementById('tasksForm').addEventListener('submit', function (event) {
                event.preventDefault();

                // Collect date-time pairs
                const dateTimePairs = [];
                document.querySelectorAll('.date-time-container .form-group').forEach(group => {
                    const date = group.querySelector('input[type="text"]').value;
                    const time = group.querySelector('.time-picker').value;
                    dateTimePairs.push({ date, time });
                });

                // Set the dates field value
                document.getElementById('dates').value = JSON.stringify(dateTimePairs);

                // Validate dates
                if (dateTimePairs.length === 0) {
                    Swal.fire({
                        title: 'Error',
                        text: 'Please select dates',
                        icon: 'error',
                        confirmButtonText: 'OK'
                    });
                    return;
                }

                // Collect form data
                const formData = new FormData(this);

                // Send form data via fetch
                fetch('submit_task.php', {
                    method: 'POST',
                    body: formData
                })
                    .then(response => response.text())
                    .then(data => {
                        // Reset form fields
                        document.getElementById('service-id').value = '';
                        document.getElementById('frequency').value = '';
                        document.querySelector('.date-time-container').innerHTML = '';

                        // Show success message
                        Swal.fire({
                            title: 'Task Created',
                            text: data,
                            icon: 'success',
                            confirmButtonText: 'OK'
                        }).then(() => {
                            location.reload();
                        });
                    })
                    .catch(error => {
                        // Show error message
                        Swal.fire({
                            title: 'Error',
                            text: error,
                            icon: 'error',
                            confirmButtonText: 'OK'
                        });
                    });
            });

            function populateRegion() {
                var selectedService = document.getElementById('service-name').value;
                var selectedServiceData = <?php echo json_encode($services); ?>;
                var regionSelect = document.getElementById('region');

                regionSelect.innerHTML = '';

                selectedServiceData.forEach(service => {
                    if (service.name === selectedService) {
                        var regionOption = document.createElement('option');
                        regionOption.value = service.region;
                        regionOption.textContent = service.region;
                        regionSelect.appendChild(regionOption);
                    }
                });
            }

            populateRegion();
        </script>


        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <div class="card-header-left">
                            <h3>View Tasks</h3>
                        </div>
                        <div class="card-header-right">
                            <!--                            <button id="download_excel" class="btn btn-success">Export to Excel</button>-->

                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group row">
                                    <div class="col-sm-3">
                                        <label for="filter_service" class="col-form-label">Filter Service Name:</label>
                                    </div>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="filter_service">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-sm-2">
                                        <div class="row">
                                            <div class="col-sm-3">
                                                <label for="filter_region" class="col-form-label">Filter Region:</label>
                                            </div>
                                            <div class="col-sm-9">
                                            <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>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="row">
                                            <div class="col-sm-2">
                                                <label for="filter_finished" class="col-form-label">Filter
                                                    Finished:</label>
                                            </div>
                                            <div class="col-sm-9">
                                                <select class="form-control" id="filter_finished">
                                                    <option value="">All</option>
                                                    <option value="Not Finished">Not Finished.</option>
                                                    <option value="Finished.">Finished.</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3">
                                        <div class="row">
                                            <div class="col-sm-2">
                                                <label for="filter_assigned" class="col-form-label">Filter
                                                    Assigned:</label>
                                            </div>
                                            <div class="col-sm-9">
                                                <select class="form-control" id="filter_assigned">
                                                    <option value="">All</option>
                                                    <option value="Not Assigned">Not Assigned.</option>
                                                    <option value="Assigned.">Assigned.</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <div class="row">
                                            <div class="col-sm-2">
                                                <label for="filter_public" class="col-form-label">Filter Public:</label>
                                            </div>
                                            <div class="col-sm-8">
                                                <select class="form-control" id="filter_public">
                                                    <option value="">All</option>
                                                    <option value="Not Public">Not Public</option>
                                                    <option value="Public.">Public.</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">

                                        <button type="button" id="reset_filters" class="btn btn-icon btn-outline-danger"><i class="ik ik-refresh-cw"></i></button>

                                    </div>
                                </div>
                                <!-- Add other filters as per your requirements -->
                            </div>
                        </div>
                        <table id="superadvanced_table" class="table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Service Name</th>
                                <th>Region</th>
                                <th>Frequency</th>
                                <th>Created By</th>
                                <th>Created At</th>
                                <th>Finished</th>
                                <th>Assigned</th>

                                <th>Public Status</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 $task->created_by_name; ?></td>
                                    <td><?php echo date('F j, Y, g:i a', strtotime($task->created_at)); ?></td>
                                    <td><?php echo($task->finished ? '<label class="badge badge-success">Finished.</label>' : '<label class="badge badge-warning">Not Finished</label>'); ?></td>
                                    <td><?php echo($task->is_assigned ? '<label class="badge badge-success">Assigned.</label>' : '<label class="badge badge-warning">Not Assigned</label>'); ?></td>

                                    <td><?php echo($task->isPublic ? '<label class="badge badge-warning">Public.</label>' : '<label class="badge badge-success">Not Public</label>'); ?></td>
                                    <td>
                                        <a href="viewtask.php?id=<?php echo $System->encryptData($task->id); ?>"
                                           class="btn btn-primary">View Details</a>
                                        <?php if ($task->is_assigned == 0): ?>
                                            <button class="btn btn-danger delete-task"
                                                    data-task-id="<?php echo $System->encryptData($task->id); ?>">Remove
                                            </button>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                    <script>
                        $(document).ready(function () {
                            // Initialize DataTable
                            var table = $('#superadvanced_table').DataTable({
                                // Configure initial settings if needed
                            });

                            // Function to save filters to localStorage
                            function saveFilters() {
                                var filters = {
                                    service: $('#filter_service').val(),
                                    region: $('#filter_region').val(),
                                    finished: $('#filter_finished').val(),
                                    assigned: $('#filter_assigned').val(),
                                    public: $('#filter_public').val()
                                };
                                localStorage.setItem('superadvancedTableFilters', JSON.stringify(filters));
                            }

                            // Function to apply saved filters
                            function applyFilters() {
                                var filters = JSON.parse(localStorage.getItem('superadvancedTableFilters'));
                                if (filters) {
                                    $('#filter_service').val(filters.service).trigger('keyup');
                                    $('#filter_region').val(filters.region).trigger('change');
                                    $('#filter_finished').val(filters.finished).trigger('change');
                                    $('#filter_assigned').val(filters.assigned).trigger('change');
                                    $('#filter_public').val(filters.public).trigger('change');
                                }
                            }

                            // Function to reset filters
                            function resetFilters() {
                                $('#filter_service').val('').trigger('keyup');
                                $('#filter_region').val('').trigger('change');
                                $('#filter_finished').val('').trigger('change');
                                $('#filter_assigned').val('').trigger('change');
                                $('#filter_public').val('').trigger('change');
                                localStorage.removeItem('superadvancedTableFilters');
                                table.search('').columns().search('').draw();
                            }

                            // Check previous page and apply filters if necessary
                            function checkPreviousPage() {
                                var previousUrl = sessionStorage.getItem('previousUrl');
                                if (!previousUrl || !previousUrl.includes('viewtask.php')) {
                                    resetFilters();
                                } else {
                                    applyFilters();
                                }
                            }

                            checkPreviousPage();

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

                            $('#filter_finished').on('change', function () {
                                table.column(6).search($(this).val()).draw();
                                saveFilters();
                            });

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

                            $('#filter_assigned').on('change', function () {
                                table.column(7).search($(this).val()).draw();
                                saveFilters();
                            });

                            $('#filter_public').on('change', function () {
                                table.column(8).search($(this).val()).draw();
                                saveFilters();
                            });

                            // Add reset filters button functionality
                            $('#reset_filters').on('click', function () {
                                resetFilters();
                            });

                            // Apply saved filters on initial load
                            applyFilters();
                        });
                    </script>

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


    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        var deleteButtons = document.querySelectorAll('.delete-task');
        deleteButtons.forEach(function (button) {
            button.addEventListener('click', function () {
                var taskId = button.getAttribute('data-task-id');

                Swal.fire({
                    title: 'Are you sure?',
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!'
                }).then((result) => {
                    if (result.isConfirmed) {
                        var xhr = new XMLHttpRequest();
                        xhr.open('POST', 'delete_task.php', true);
                        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                        xhr.onreadystatechange = function () {
                            if (xhr.readyState == 4 && xhr.status == 200) {
                                if (xhr.responseText === 'success') {
                                    Swal.fire({
                                        title: 'Deleted!',
                                        text: 'Your task has been deleted.',
                                        icon: 'success'
                                    }).then(() => {
                                        window.location.reload();
                                    });
                                } else {
                                    Swal.fire({
                                        title: 'Error!',
                                        text: xhr.responseText,
                                        icon: 'error'
                                    });
                                }
                            }
                        };
                        xhr.send('taskId=' + taskId);
                    }
                });
            });
        });
    });
</script>


<?php include('footer.php'); ?>
PK��\�qC�]=]=
dashboard.phpnu�[���<?php
//enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
include('head.php');

require_once '../../Service/ReportsAndDashboardService.php';
$reportsAndDashboardService = new ReportsAndDashboardService();

//
//
//$pendingTasks = $reportsAndDashboardService->getPendingTasks($companyId);
//$completedTasks =$reportsAndDashboardService->getCompletedTasks($companyId);
//
//$ongoingSubtasks = $reportsAndDashboardService->getOngoingSubtasks($companyId);
//$unassignedSubtasks = $reportsAndDashboardService->getUnassignedSubtasks($companyId);
//
$subtasks = $reportsAndDashboardService->getSubtasks();

$taskProviderId = $_SESSION['user_id'];
//Tasks added by me
$tasksAddedByMe = $reportsAndDashboardService->getTasksAddedByMe($taskProviderId);
//Service Locations
$services = $reportsAndDashboardService->getServicesCount();


// Fetch completed and incomplete subtask summary data
$subtasksSummary = $reportsAndDashboardService->getSubtasksSummaryAdmin();
$completedSubTasks = $subtasksSummary['completed'];
$incompleteSubTasks = $subtasksSummary['incomplete'];
$ongoingSubTasks = $completedSubTasks + $incompleteSubTasks; // Calculating ongoing subtasks

// Fetch total finished and not finished task summary data
$taskSummary = $reportsAndDashboardService->getTasksSummaryAdmin();
$completedTasks = $taskSummary['completed'];
$pendingTasks = $taskSummary['pending'];
$ongoingTasks = $taskSummary['total'];


$todaySubtasksSummary = $reportsAndDashboardService->getSubtasksSummaryForTodayAdmin(date('Y-m-d'));
$todayTotalSubTasks = $todaySubtasksSummary['total'];
$todayCompletedSubTasks = $todaySubtasksSummary['completed'];
$todayIncompleteSubTasks = $todaySubtasksSummary['incomplete'];
?>


<div class="main-content">
    <div class="container-fluid">
        <div class="row grid-layout">
            <!-- Ongoing, Completed, Incomplete Subtasks and Chart -->
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        <h3>Overall Subtasks Summary</h3>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="widget bg-primary">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Ongoing Subtasks</h6>
                                                <h2><?php echo $ongoingSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-box"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="widget bg-success">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Completed Subtasks</h6>
                                                <h2><?php echo $completedSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-shopping-cart"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="widget bg-warning">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Incomplete Subtasks</h6>
                                                <h2><?php echo $incompleteSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-inbox"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="card-body text-center">
                                    <canvas id="subtasksPieChart" style="height: 370px; width: 100%;"></canvas>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Today's Subtasks Summary -->
                <div class="card">
                    <div class="card-header">
                        <h3>Today's Subtasks Summary: <?php echo date('l, F j, Y'); ?></h3>
                    </div>
                    <div class="card-block">
                        <div class="row">
                            <div class="col-md-6">
                                <!-- Total Subtasks -->
                                <div class="widget bg-info">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Total Subtasks to be Completed</h6>
                                                <h2><?php echo $todayTotalSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-calendar"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Today's Completed Subtasks -->
                                <div class="widget bg-success">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Completed Subtasks</h6>
                                                <h2><?php echo $todayCompletedSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-check-circle"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- Today's Incomplete Subtasks -->
                                <div class="widget bg-warning">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Incomplete Subtasks</h6>
                                                <h2><?php echo $todayIncompleteSubTasks; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-alert-circle"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Doughnut Chart for Today's Subtasks -->
                            <div class="col-md-6">
                                <div class="card-block text-center">
                                    <canvas id="todaySubtasksDoughnutChart" style="height: 370px; width: 100%;"></canvas>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Right Column Widgets -->
            <div class="col-md-4">
                <!-- Sub Contractors -->
                <div class="widget bg-primary">
                    <div class="widget-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div class="state">
                                <h6> Tasks Added By Me</h6>
                                <h2><?php echo  $tasksAddedByMe; ?></h2>
                            </div>
                            <div class="icon">
                                <i class="ik ik-box"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Services -->
                <div class="widget bg-success">
                    <div class="widget-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div class="state">
                                <h6>Services</h6>
                                <h2><?php echo $services->count; ?></h2>
                            </div>
                            <div class="icon">
                                <i class="ik ik-map-pin"></i>
                            </div>
                        </div>
                    </div>
                </div>


                <!-- Completed Subtasks Chart -->
                <div class="card sale-card">
                    <div class="card-header">
                        <h3>Completed Subtasks</h3>
                    </div>
                    <div class="card-block">
                        <div id="subtask-chart" class="chart-shadow" style="height:300px"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script>
    var chartData = [
        <?php foreach ($subtasks as $subtask): ?>
        {
            "date": "<?php echo $subtask->completed_at; ?>",
            "completed_subtasks": <?php echo $subtask->completed_subtasks; ?>
        },
        <?php endforeach; ?>
    ];

    var chart = AmCharts.makeChart("subtask-chart", {
        "type": "serial",
        "theme": "light",
        "dataDateFormat": "YYYY-MM-DD",
        "precision": 2,
        "valueAxes": [{
            "id": "v1",
            "position": "left",
            "autoGridCount": false,
            "labelFunction": function (value) {
                return value + " tasks";
            }
        }],
        "graphs": [{
            "id": "g1",
            "valueAxis": "v1",
            "bullet": "round",
            "bulletBorderAlpha": 1,
            "bulletColor": "#FFFFFF",
            "bulletSize": 8,
            "hideBulletsCount": 50,
            "lineThickness": 3,
            "lineColor": "#2ed8b6",
            "title": "Completed Subtasks",
            "useLineColorForBulletBorder": true,
            "valueField": "completed_subtasks",
            "balloonText": "[[title]]<br /><b style='font-size: 130%'>[[value]]</b>"
        }],
        "chartCursor": {
            "pan": true,
            "valueLineEnabled": true,
            "valueLineBalloonEnabled": true,
            "cursorAlpha": 0,
            "valueLineAlpha": 0.2
        },
        "categoryField": "date",
        "categoryAxis": {
            "parseDates": true,
            "dashLength": 1,
            "minorGridEnabled": true
        },
        "legend": {
            "useGraphSettings": true,
            "position": "top"
        },
        "balloon": {
            "borderThickness": 1,
            "shadowAlpha": 0
        },
        "dataProvider": chartData
    });
</script>

<script>
    // Data for the doughnut chart
    var completedSubTasks = <?php echo $completedSubTasks; ?>;
    var incompleteSubTasks = <?php echo $incompleteSubTasks; ?>;

    // Create Doughnut Chart
    var ctx = document.getElementById('subtasksPieChart').getContext('2d');
    var subtasksDoughnutChart = new Chart(ctx, {
        type: 'doughnut',  // Change type to 'doughnut'
        data: {
            labels: ['Completed Subtasks', 'Incomplete Subtasks'],
            datasets: [{
                label: 'Subtasks Status',
                data: [completedSubTasks, incompleteSubTasks],  // Data values for doughnut chart
                backgroundColor: [
                    '#28a745',  // Green color for 'Completed Subtasks'
                    '#fd7e14'   // Red color for 'Incomplete Subtasks'
                ],
                borderColor: [
                    '#ffffff',  // White border
                    '#ffffff'   // White border
                ],
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,  // Make chart responsive
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: true,  // Show legend
                    position: 'bottom'  // Position of the legend
                },
            }
        }
    });
</script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    // Data for the doughnut chart for today's subtasks
    var todayCompletedSubTasks = <?php echo $todayCompletedSubTasks; ?>;
    var todayIncompleteSubTasks = <?php echo $todayIncompleteSubTasks; ?>;

    // Create Doughnut Chart for Today's Subtasks
    var ctx = document.getElementById('todaySubtasksDoughnutChart').getContext('2d');
    var todaySubtasksDoughnutChart = new Chart(ctx, {
        type: 'doughnut',
        data: {
            labels: ['Completed Subtasks', 'Incomplete Subtasks'],
            datasets: [{
                label: 'Today\'s Subtasks Status',
                data: [todayCompletedSubTasks, todayIncompleteSubTasks],  // Data values for doughnut chart
                backgroundColor: [
                    '#28a745',  // Green for completed
                    '#ffc107'   // Yellow for incomplete
                ],
                borderColor: [
                    '#ffffff',  // White border
                    '#ffffff'   // White border
                ],
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,  // Make chart responsive
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: true,  // Show legend
                    position: 'bottom'  // Position of the legend
                },
            }
        }
    });
</script>

<?php include('footer.php'); ?>
PK��\!�$7$7 report_tasksstatusbyschedule.phpnu�[���<?php
include('head.php');
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Service/UserService.php';
require_once '../../Service/ServiceService.php';
require_once '../../Classes/System.php';

// Create instances of the required services
$taskService = new TaskService();
$UserService = new UserService();
$System = new System();

// Create ServiceService instance
$serviceService = new ServiceService();
$services = $serviceService->getAllServicesForDropdown();

// Fetch all schedules for the dropdown
$schedules = $taskService->getAllSchedules();

//get schedule id form the url
$schedule_id = isset($_GET['schedule_id']) ? $_GET['schedule_id'] : null;

// Handle form submission and fetch tasks based on the selected schedule
$selectedScheduleId = $System->decryptData($schedule_id);
$tasksBySchedule = [];
if ($selectedScheduleId) {
    $tasksBySchedule = $taskService->getTasksBySchedule($selectedScheduleId);
}

?>

<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 Tasks by Schedule</h5>
                            <span>Select a schedule to view 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="#"><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 by Schedule</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Search Form -->
        <div class="row">
            <div class="col-md-12">
                <form method="GET" action="">
                    <div class="form-group">
                        <label for="schedule_id">Select Schedule:</label>
                        <select name="schedule_id" id="schedule_id" class="form-control">
                            <option value="">-- Select Schedule --</option>
                            <?php foreach ($schedules as $schedule) { ?>
                                <option value="<?= htmlspecialchars($System->encryptData($schedule->id)); ?>" <?= ($selectedScheduleId == $schedule->id) ? 'selected' : '' ?>>
                                    <?= htmlspecialchars($schedule->schedule_name); ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary">Search</button>
                </form>
            </div>
        </div>

        <!-- Display Tasks Table -->
        <div class="row mt-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="dt-responsive">
                            <div class="row mb-3">
                                <div class="col-md-2">
                                    <label for="filter_Service_Name" class="form-label">Filter by Service Name:</label>
                                    <input type="text" class="form-control" id="filter_Service_Name">
                                </div>
                                <div class="col-md-2">
                                    <label for="filter_region" class="form-label">Filter by 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 class="col-md-2">
                                    <label for="filter_status" class="form-label">Filter by Status:</label>
                                    <select name="filter_status" id="filter_status" class="form-control">
                                        <option value="">-- Select Status --</option>
                                        <option value="Assigned.">Assigned</option>
                                        <option value="Not Assigned">Not Assigned</option>
                                    </select>
                                </div>
                                <div class="col-md-2">
                                    <label for="filter_finished" class="form-label">Filter by Finished:</label>
                                    <select name="filter_finished" id="filter_finished" class="form-control">
                                        <option value="">-- Select Finished --</option>
                                        <option value="Finished.">Finished</option>
                                        <option value="Not Finished">Not Finished</option>
                                    </select>
                                </div>
                                <div class="col-md-3">
                                    <label for="reset_filters" class="form-label">&nbsp;</label>
                                    <button type="button" id="reset_filters" class="btn btn-icon btn-outline-danger"><i class="ik ik-refresh-cw"></i></button>
                                </div>
                            </div>
                            <table class="table" id="tasks_by_schedule_table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Service Name</th>
                                    <th>Region</th>
                                    <th>Status</th>
                                    <th>Finished</th>
                                    <th>Actions</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($tasksBySchedule as $task) { ?>
                                    <tr>
                                        <td><?php echo 'TSK-000'.htmlspecialchars($task->id); ?></td>
                                        <td><?= htmlspecialchars($task->service_name); ?></td>
                                        <td><?= htmlspecialchars($task->region); ?></td>
                                        <td>
                                            <?= $task->is_assigned && $task->accepted
                                                ? '<label class="badge badge-success">Assigned.</label>'
                                                : '<label class="badge badge-warning">Not Assigned</label>'; ?>
                                        </td>

                                        <td><?php echo($task->finished ? '<label class="badge badge-success">Finished.</label>' : '<label class="badge badge-warning">Not Finished</label>'); ?></td>
                                        <td>
                                            <a href="viewtask.php?id=<?= $System->encryptData($task->id); ?>" class="btn btn-primary">View</a>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                            <script>
                                $(document).ready(function () {
                                    // Initialize DataTable
                                    var table = $('#tasks_by_schedule_table').DataTable({
                                        // Configure initial settings if needed
                                    });

                                    // Function to save filters to localStorage
                                    function saveFilters() {
                                        var filters = {
                                            serviceName: $('#filter_Service_Name').val(),
                                            region: $('#filter_region').val(),
                                            status: $('#filter_status').val(),
                                            finished: $('#filter_finished').val()
                                        };
                                        localStorage.setItem('tasksByScheduleTableFilters', JSON.stringify(filters));
                                    }

                                    // Function to apply saved filters
                                    function applyFilters() {
                                        var filters = JSON.parse(localStorage.getItem('tasksByScheduleTableFilters'));
                                        if (filters) {
                                            $('#filter_Service_Name').val(filters.serviceName).trigger('keyup');
                                            $('#filter_region').val(filters.region).trigger('change');
                                            $('#filter_status').val(filters.status).trigger('change');
                                            $('#filter_finished').val(filters.finished).trigger('change');
                                        }
                                    }

                                    // Function to reset filters
                                    function resetFilters() {
                                        $('#filter_Service_Name').val('').trigger('keyup');
                                        $('#filter_region').val('').trigger('change');
                                        $('#filter_status').val('').trigger('change');
                                        $('#filter_finished').val('').trigger('change');
                                        localStorage.removeItem('tasksByScheduleTableFilters');
                                        table.search('').columns().search('').draw();
                                    }

                                    // Check previous page and apply filters if necessary
                                    function checkPreviousPage() {
                                        var previousUrl = sessionStorage.getItem('previousUrl');
                                        if (!previousUrl || !previousUrl.includes('viewtask.php')) {
                                            resetFilters();
                                        } else {
                                            applyFilters();
                                        }
                                    }

                                    checkPreviousPage();

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

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

                                    $('#filter_status').on('change', function () {
                                        table.column(3).search(this.value).draw();
                                        saveFilters();
                                    });

                                    $('#filter_finished').on('change', function () {
                                        table.column(4).search(this.value).draw();
                                        saveFilters();
                                    });

                                    // Add reset filters button functionality
                                    $('#reset_filters').on('click', function () {
                                        resetFilters();
                                    });

                                    // Apply saved filters on initial load
                                    applyFilters();
                                });
                            </script>

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

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

<script>
    $(document).ready(function() {
        $('#tasks_by_schedule_table').DataTable();
    });
</script>
PK��\��!n�;�;report_viewsubtasksdaywise.phpnu�[���<?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();
$services = $serviceService->getAllServicesForDropdown();

// Fetch assigned user ID from session or request
$assignedUserId = $_SESSION['user_id'] ?? ($_GET['user_id'] ?? 1); // Default to 1 if not set

// Create TaskService instance
$taskService = new TaskService();
$System = new System(); // Assuming System class is correctly defined and used

$TaskProviderId = $_SESSION['user_id'];

// Fetch all subtasks grouped by date
$startDate = $_GET['start_date'] ?? null;
$endDate = $_GET['end_date'] ?? null;
$serviceLocationId = $_GET['service_location_id'] ?? null;

if ($_GET['filter_today'] ?? false) {
    $startDate = date('Y-m-d');
    $endDate = date('Y-m-d');
}

// Correctly call the function with the right parameters
//$subtasks = $taskService->getAllSubtasksForTaskProviderGroupByDate($startDate, $endDate, $serviceLocationId, $TaskProviderId);

$subtasks = $taskService->getAllSubtasksGroupByDate($startDate, $endDate, $serviceLocationId);

$CompletedSubtaskcount = 0;
$IncompletedSubtaskcount = 0;

foreach ($subtasks as $date => $subtaskList) {
    foreach ($subtaskList as $subtask) {
        if ($subtask['completed']) {
            $CompletedSubtaskcount++;
        } else {
            $IncompletedSubtaskcount++;
        }
    }
}
?>

<!-- Include Bootstrap Datepicker CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" />

<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>Tasks</h5>
                            <span>Assign Tasks to Cleaner</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">All Subtasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Banner Section -->
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-footer">
                        <div class="d-flex">
                            <div class="col-lg-3 col-md-6 col-sm-12">
                                <div class="widget bg-success">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Completed Subtasks</h6>
                                                <h2><?= $CompletedSubtaskcount; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-shopping-cart"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-md-6 col-sm-12">
                                <div class="widget bg-warning">
                                    <div class="widget-body">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <div class="state">
                                                <h6>Incomplete Subtasks</h6>
                                                <h2><?= $IncompletedSubtaskcount; ?></h2>
                                            </div>
                                            <div class="icon">
                                                <i class="ik ik-inbox"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Date Filter and Today Checkbox -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="form-group">
                    <label for="startDate">Start Date</label>
                    <input type="text" id="startDate" class="form-control datepicker" placeholder="Select start date" value="<?= htmlspecialchars($startDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="endDate">End Date</label>
                    <input type="text" id="endDate" class="form-control datepicker" placeholder="Select end date" value="<?= htmlspecialchars($endDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="serviceLocationId">Select a Service Location:</label>
                    <select id="serviceLocationId" name="serviceLocationId" class="form-control select2">
                        <option value="">All Locations</option>
                        <?php
                        foreach ($services as $service) {
                            $selected = '';
                            if (isset($_GET['service_location_id']) && $_GET['service_location_id'] == $service->id) {
                                $selected = 'selected';
                            }
                            echo '<option value="' . htmlspecialchars($service->id) . '" ' . $selected . '>' . htmlspecialchars($service->name) . '</option>';
                        }
                        ?>
                    </select>
                </div>
            </div>

            <div class="col-md-3 d-flex align-items-center">
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="checkbox" id="todayCheckbox" value="today" <?= ($startDate == date('Y-m-d') && $endDate == date('Y-m-d')) ? 'checked' : '' ?>>
                    <label class="form-check-label" for="todayCheckbox">Today</label>
                </div>
            </div>

            <div class="col-md-3 d-flex align-items-center">
                <button id="applyFilter" class="btn btn-primary">Apply Filter</button>
                &nbsp;
                &nbsp;
                <button type="button" id="reset_filters" class="btn btn-icon btn-outline-danger"><i class="ik ik-refresh-cw"></i></button>
            </div>

        </div>

        <?php foreach ($subtasks as $date => $subtaskList) { ?>
            <div class="row subtask-row" data-date="<?php echo $date; ?>">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h3>Subtasks for <?php
                                if ($date == date('Y-m-d')) {
                                    echo 'Today';
                                } else if ($date == date('Y-m-d', strtotime('tomorrow'))) {
                                    echo 'Tomorrow';
                                } else {
                                    echo date('l, F j, Y', strtotime($date));
                                }
                                ?></h3>
                            <div class="card-header-right">
                                <ul class="list-unstyled card-option">
                                    <li><i class="ik ik-chevron-left action-toggle" data-toggle="tooltip" title="Collapse"></i></li>
                                    <li><i class="ik ik-minus minimize-card" data-toggle="tooltip" title="Minimize"></i></li>
                                </ul>
                            </div>
                        </div>
                        <div class="card-body">
                            <div class="dt-responsive">
                                <table class="table" id="advanced_table_<?php echo strtotime($date); ?>">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Service Name</th>
                                        <th>Date</th>
                                        <th>Time</th>
                                        <th>Assigned</th>
                                        <th>Completed</th>
                                        <th>Actions</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($subtaskList as $subtask) { ?>
                                        <tr>
                                            <td>ST-000<?= $subtask['id']; ?></td>
                                            <td><?= $subtask['service_name']; ?></td>
                                            <td><?= $subtask['subtask_date']; ?></td>
                                            <td><?= $subtask['subtask_time'] ? date('h:i A', strtotime($subtask['subtask_time'])) : ''; ?></td>
                                            <td><?= $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=<?= $System->encryptData($subtask['id']); ?>" class="btn btn-primary">View</a>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

<!-- Include jQuery and Bootstrap Datepicker JS -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>

<script>
    $(document).ready(function() {
        // Initialize datepickers
        $('.datepicker').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayHighlight: true
        });

        // Function to save filters to localStorage
        function saveFilters() {
            var filters = {
                startDate: $('#startDate').val(),
                endDate: $('#endDate').val(),
                serviceLocationId: $('#serviceLocationId').val(),
                todayCheckbox: $('#todayCheckbox').is(':checked')
            };
            localStorage.setItem('dateRangeFilters', JSON.stringify(filters));
        }

        // Function to apply saved filters
        function applyFilters() {
            var filters = JSON.parse(localStorage.getItem('dateRangeFilters'));
            if (filters) {
                $('#startDate').val(filters.startDate);
                $('#endDate').val(filters.endDate);
                $('#serviceLocationId').val(filters.serviceLocationId);
                $('#todayCheckbox').prop('checked', filters.todayCheckbox);
            }
        }

        // Function to reset filters
        function resetFilters() {
            $('#startDate').val('');
            $('#endDate').val('');
            $('#serviceLocationId').val('');
            $('#todayCheckbox').prop('checked', false);
            localStorage.removeItem('dateRangeFilters');
            applyDateRangeFilter();
        }

        // Apply date range filter by modifying the URL
        function applyDateRangeFilter() {
            var startDate = $('#startDate').val();
            var endDate = $('#endDate').val();
            var serviceLocationId = $('#serviceLocationId').val();
            var url = window.location.href.split('?')[0] + '?start_date=' + startDate + '&end_date=' + endDate + '&service_location_id=' + serviceLocationId;
            window.location.href = url;
        }

        // Event handler for applyFilter button
        $('#applyFilter').on('click', function() {
            saveFilters();
            applyDateRangeFilter();
        });

        // Event handler for todayCheckbox
        $('#todayCheckbox').on('change', function() {
            if ($(this).is(':checked')) {
                var today = '<?= date('Y-m-d') ?>';
                $('#startDate').val(today);
                $('#endDate').val(today);
            } else {
                $('#startDate').val('');
                $('#endDate').val('');
            }
            saveFilters();
            applyDateRangeFilter();
        });

        // Add reset filters button functionality
        $('#reset_filters').on('click', function() {
            resetFilters();
        });

        // Apply saved filters on initial load
        applyFilters();
    });
</script>
<?php include('footer.php'); ?>
PK��\��o���head.phpnu�[���<?php
session_start();

require_once '../../Classes/System.php';
$system = new system();

// Check if the user is not logged in or is not an admin
if (!$system->isLoggedIn() || !$system->isTaskProvider()) {
    header('Location: ../login.php');
    exit; // Stop further execution
}
$companyId = $_SESSION['user_id'];
?>

<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title><?php echo isset($pageTitle) ? $pageTitle : "Emera Facility Services"; ?></title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">


    <script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.5.1.js"></script>

    <link rel="icon" href="../../cropped-emera-holdings-favicon-1-32x32.png" type="image/x-icon" />


    <script src="../../src/js/vendor/modernizr-2.8.3.min.js"></script>
    <script src="../../src/js/vendor/modernizr-2.8.3.min.js"></script>

    <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">



    <link rel="stylesheet" href="../../node_modules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../node_modules/@fortawesome/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="../../node_modules/ionicons/dist/css/ionicons.min.css">
    <link rel="stylesheet" href="../../node_modules/icon-kit/dist/css/iconkit.min.css">
    <link rel="stylesheet" href="../../node_modules/perfect-scrollbar/css/perfect-scrollbar.css">
    <link rel="stylesheet" href="../../dist/css/theme.min.css">
    <link rel="stylesheet" href="../../node_modules/flatpickr/dist/flatpickr.min.css">
    <link rel="stylesheet" href="../../node_modules/perfect-scrollbar/css/perfect-scrollbar.css">
    <link rel="stylesheet" href="../../node_modules/datatables.net-bs4/css/dataTables.bootstrap4.min.css">

    <link rel="stylesheet" href="../../node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.min.css">
    <link rel="stylesheet" href="../../node_modules/weather-icons/css/weather-icons.min.css">
    <link rel="stylesheet" href="../../node_modules/c3/c3.min.css">
    <link rel="stylesheet" href="../../node_modules/perfect-scrollbar/css/perfect-scrollbar.css">
    <link rel="stylesheet" href="../../node_modules/owl.carousel/dist/assets/owl.carousel.css">
    <link rel="stylesheet" href="../../node_modules/owl.carousel/dist/assets/owl.theme.default.css">


    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.css">
    <link rel="stylesheet" href="../../node_modules/select2/dist/css/select2.min.css">
    <script src="../../src/js/vendor/modernizr-2.8.3.min.js"></script>
    <script src="../../node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

    <script src="../../node_modules/select2/dist/js/select2.min.js"></script>

    <style>
        /* Optional: You can style your map container here */
        #map {
            height: 400px;
            width: 100%;
        }
    </style>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            // Function to log previous page URL from session state


            // Save current page URL to session state
            function saveCurrentPageUrl() {
                var currentUrl = window.location.href;
                sessionStorage.setItem('previousUrl', currentUrl);
            }

            // Call saveCurrentPageUrl when navigating away
            window.addEventListener('beforeunload', saveCurrentPageUrl);


        });
    </script>

</head>
<body>
<div class="wrapper">
    <?php include('header.php'); ?>
    <div class="page-wrap">
<?php include('sidebar.php'); ?>PK��\e���
add_tasks.phpnu�[���<?php
// schedule.php

session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once '../../Classes/Database.php';
require_once '../../Classes/Schedules.php';
require_once '../../Classes/Task.php';
require_once '../../Service/ScheduleService.php';
require_once '../../Service/TaskService.php';
require_once '../../Service/ServiceService.php';

$serviceService = new ServiceService();
$services = $serviceService->getAllServicesForDropdown();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Read the raw POST data
    $input = file_get_contents('php://input');
    $data = json_decode($input, true); // Decode the JSON data into an associative array

    // Extract schedule name and tasks
    $scheduleName = isset($data['scheduleName']) ? trim($data['scheduleName']) : '';
    $currentUserId = isset($data['currentUserId']) ? trim($data['currentUserId']) : '';
    $tasks = isset($data['tasks']) ? $data['tasks'] : [];

    $now = date('Y-m-d H:i:s');


    try {
        // Create a new schedule
        $schedule = new Schedules('', $scheduleName, $currentUserId, false, $now, $now);
        $scheduleService = new ScheduleService();
        $schedule_id = $scheduleService->addScheduleRetuenlastinsertedid($schedule);

        // Check if schedule creation was successful
        if (!$schedule_id) {
            echo json_encode(array('error' => 'Failed to add schedule.'));
            exit;
        }

        // Loop through tasks array and add each task
        foreach ($tasks as $taskData) {
            $serviceId = isset($taskData['service']) ? trim($taskData['service']) : '';



            $frequency = isset($taskData['frequency']) ? trim($taskData['frequency']) : '';
            $dates = isset($taskData['dates']) ? $taskData['dates'] : [];

            // Validate and format dates and times
            $formattedDates = [];
            foreach ($dates as $date) {
                $formattedDates[] = [
                    'date' => $date['date'],
                    'time' => $date['time']
                ];
            }

            // Create a new task instance with the formatted dates and times

            $task = new Task('', $schedule_id, $serviceId, $frequency, json_encode($formattedDates), $currentUserId, $currentUserId, $now, $now, false, null, false, false, false, '', null,0);
            $taskService = new TaskService();
            $task_id = $taskService->addTask($task);

            // Check if task creation was successful
            if (!$task_id) {
                echo json_encode(array('error' => 'Failed to add task.'));
                exit;
            }
        }

        // If everything is successful, return a success response
        echo json_encode(array('success' => true, 'message' => 'Tasks added successfully.', 'schedule_id' => $schedule_id));
    } catch (Exception $e) {
        // Handle any exceptions and return an error response
        echo json_encode(array('error' => $e->getMessage()));
    }
} else {
    // If the request method is not POST, return an error response
    echo json_encode(array('error' => 'Invalid request method.'));
}
?>
PK��\H<���6�6viewsubtask.phpnu�[���<?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'); ?>
PK��\���8�'�'viewservice.phpnu�[���<?php include('head.php'); ?>
<?php
require_once '../../Classes/Database.php';
require_once '../../Service/ServiceService.php';
require_once '../../Classes/System.php';

$System = new System();
$serviceService = new ServiceService();

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

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

$service = $serviceService->getServiceById($serviceId);
if (!$service) {
    echo '<p>Service not found.</p>';
    exit;
}

$latitude = $service->latitude;
$longitude = $service->longitude;
?>

<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 Service</h5>
                        <span>View details of a service</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="#">Services</a></li>
                        <li class="breadcrumb-item active" aria-current="page">View Service</li>
                    </ol>
                </nav>
            </div>
        </div>
        <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>





        <div class="card">
            <div class="card-body">
                <div class="row align-items-center mb-30">
                    <div class="col-md-6">
                        <h4>General Information</h4>
                        <table>
                            <tbody>
                            <tr>
                                <td><i class="ik ik-layers icon-large"></i></td>
                                <td><h3 class="mb-0 fw-700 text-black"><?php echo $service->name?: 'Name not provided'; ?></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 $service->region; ?></h5></td>
                            </tr>
                            </tbody>
                        </table>

                        <h4>Address Details</h4>
                        <table>
                            <tbody>
                            <tr>
                                <td><i class="ik ik-home icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->address_line1 ?: 'Address Line 1 not provided'; ?></h5></td>

                                <td><i class="ik ik-home icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->address_line2 ?: 'Address Line 2 not provided'; ?></h5></td>
                            </tr>
                            <tr>
                                <td><i class="ik ik-map icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->suburb ?: 'Suburb not provided'; ?></h5></td>

                                <td><i class="ik ik-map-pin icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->city?: 'City not provided'; ?></h5></td>
                            <tr>
                                <td><i class="ik ik-globe icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->state ?: 'State not provided'; ?></h5></td>

                                <td><i class="ik ik-mail icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->postal_code ?: 'Postal code not provided'; ?></h5></td>
                            </tr>
                            <tr>
                                <td><i class="ik ik-flag icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->country?: 'Country not provided'; ?></h5></td>
                            </tr>
                            <tr>
                                <td><i class="ik ik-phone icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->phone?: 'Phone not provided'; ?></h5></td>
                            </tr>
                            
                            </tbody>
                        </table>
                        <h4>On Site Location</h4>
                        <table>
                            <tbody>
                            <tr>
                                <td><i class="ik ik-map-pin icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->on_site_location ?: 'Not provided'; ?></h5></td>
                            </tr>
                            </tbody>
                        </table>
                        <h4>Longitude and Latitude</h4>
                        <table>
                            <tbody>
                            <tr>
                                <td><i class="ik ik-map-pin icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->latitude ?: 'Not provided'; ?></h5></td>

                                <td><i class="ik ik-map-pin icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo $service->longitude ?: 'Not provided'; ?></h5></td>
                            </tr>
                            </tbody>
                        </table>

                        <h4>Timestamps</h4>
                        <table>
                            <tbody>
                            <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($service->created_at)); ?></h5></td>

                                <td><i class="ik ik-clock icon-large"></i></td>
                                <td><h5 class="mb-0 fw-500 text-black"><?php echo date('F j, Y, g:i a', strtotime($service->updated_at)); ?></h5></td>
                            </tr>
                            </tbody>
                        </table>

                        <style>
                            table {
                                width: 100%;
                                border-collapse: collapse;
                                margin-bottom: 20px;
                            }
                            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;
                            }
                        </style>
                    </div>
                    <div class="col-md-6">
                        <div id="map" style="height: 400px;"></div>
                    </div>
                </div>
            </div>
        </div>

        <?php if ($latitude !== null && $longitude !== null): ?>
            <script>
                function initMap() {
                    var latitude = <?php echo $latitude; ?>;
                    var longitude = <?php echo $longitude; ?>;

                    var map = new google.maps.Map(document.getElementById('map'), {
                        center: {lat: parseFloat(latitude), lng: parseFloat(longitude)},
                        zoom: 12
                    });

                    var marker = new google.maps.Marker({
                        position: {lat: parseFloat(latitude), lng: parseFloat(longitude)},
                        map: map,
                        title: 'Service Location'
                    });
                }
            </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'); ?>
PK��\��
footer.phpnu�[���<footer class="footer">
    <div class="w-100 clearfix">
        <span class="text-center text-sm-left d-md-inline-block">Copyright © 2024 genesis it labs. All Rights Reserved.</span>
    </div>
</footer>
    </div>
    </div>
<?php include('scripts.php'); ?>PK��\�ڰ�||delete_task.phpnu�[���<?php
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';

$System = new System();
$taskService = new TaskService();

if (isset($_POST['taskId']) && !empty($_POST['taskId'])) {
    $taskId= $_POST['taskId'];
    $decryptedtaskId = $System->decryptData($taskId);

    error_log("Task ID received: " . $taskId); // Check the received task ID
    error_log("Decrypted Task ID: " . $decryptedtaskId); // Check the decrypted task ID

    if (!$taskId) {
        echo "Invalid Task ID";
        exit;
    }

    // Call deleteTaskWithSubtasks method from TaskService
    $deleteResult = $taskService->deleteTaskWithSubtasks($decryptedtaskId);

    if ($deleteResult === true) {
        echo "success";
    } else {
        echo "error";
    }
} else {
    echo "Task ID is missing";
}
?>
PK��\
�߹�&�&report_alltasks.phpnu�[���<?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();

// 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);
    }

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

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

// Fetch tasks from the database based on filters
$tasks = $taskService->getAllTasksByTaskProvider($companyId,$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>View Tasks</h5>
                            <span>View all 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 class="form-group col-md-2">
                                    <label for="finished">Finished</label>
                                    <select class="form-control" id="finished" name="finished">
                                        <option value="">Select</option>
                                        <option value="1" <?php echo (isset($_GET['finished']) && $_GET['finished'] === '1') ? 'selected' : ''; ?>>Yes</option>
                                        <option value="0" <?php echo (isset($_GET['finished']) && $_GET['finished'] === '0') ? 'selected' : ''; ?>>No</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-2">
                                    <label for="assigned">Assigned</label>
                                    <select class="form-control" id="assigned" name="assigned">
                                        <option value="">Select</option>
                                        <option value="1" <?php echo (isset($_GET['assigned']) && $_GET['assigned'] === '1') ? 'selected' : ''; ?>>Yes</option>
                                        <option value="0" <?php echo (isset($_GET['assigned']) && $_GET['assigned'] === '0') ? 'selected' : ''; ?>>No</option>
                                    </select>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-primary">Apply Filters</button>
                            <a href="report_alltasks.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>#</th>
                                <th>Service Name</th>
                                <th>Region</th>
                                <th>Frequency</th>

                                <th>Finished</th>
                                <th>Assigned</th>


                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!empty($tasks)): ?>
                                <?php foreach ($tasks as $task): ?>
                                    <tr>
                                        <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 ($task->finished ? '<label class="badge badge-success">Finished</label>' : '<label class="badge badge-danger">Not Finished</label>'); ?></td>
                                        <td><?php echo ($task->is_assigned ? '<label class="badge badge-success">Assigned</label>' : '<label class="badge badge-danger">Not Assigned</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="10">No tasks found.</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include('footer.php'); ?>
PK��\B��``report_subtaskswithnotes.phpnu�[���<?php
include('head.php');
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';

// Initialize necessary services and objects
$taskService = new TaskService();
$System = new System();

// Fetch filter parameters
$startDate = $_GET['start_date'] ?? null;
$endDate = $_GET['end_date'] ?? null;
$serviceLocationId = $_GET['service_location_id'] ?? null;

if ($_GET['filter_today'] ?? false) {
    $startDate = date('Y-m-d');
    $endDate = date('Y-m-d');
}

// Fetch all notes grouped by date without subcontractor filtering
$subtasks = $taskService->getAllSubtasksWithNotesGroupByDateForTeamKidsAdmin($startDate, $endDate, $serviceLocationId);
?>

<!-- Include Bootstrap Datepicker CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" />

<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>Tasks</h5>
                            <span>View and Submit Notes</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="#">Tasks</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">Subtasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Date Filter -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="form-group">
                    <label for="startDate">Start Date</label>
                    <input type="text" id="startDate" class="form-control datepicker" placeholder="Select start date" value="<?= htmlspecialchars($startDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="endDate">End Date</label>
                    <input type="text" id="endDate" class="form-control datepicker" placeholder="Select end date" value="<?= htmlspecialchars($endDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="serviceLocationId">Select a Service Location:</label>
                    <select id="serviceLocationId" name="serviceLocationId" class="form-control">
                        <option value="">All Locations</option>
                        <?php
                        // Populate service locations
                        $services = $taskService->getAllServicesForDropdown();
                        foreach ($services as $service) {
                            $selected = ($serviceLocationId == $service->id) ? 'selected' : '';
                            echo '<option value="' . htmlspecialchars($service->id) . '" ' . $selected . '>' . htmlspecialchars($service->name) . '</option>';
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="col-md-3 d-flex align-items-center">
                <button id="applyFilter" class="btn btn-primary">Apply Filter</button>
                &nbsp;
                <button type="button" id="reset_filters" class="btn btn-icon btn-outline-danger"><i class="ik ik-refresh-cw"></i></button>
            </div>
        </div>

        <!-- Display subtasks grouped by date -->
        <?php foreach ($subtasks as $date => $subtaskList) { ?>
            <?php
            // Skip if all notes are empty
            $allEmpty = true;
            foreach ($subtaskList as $subtask) {
                if (!empty($subtask['notes'])) {
                    $allEmpty = false;
                    break;
                }
            }
            if ($allEmpty) continue;
            ?>
            <div class="row subtask-row" data-date="<?php echo $date; ?>">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h3>Subtasks for <?= date('l, F j, Y', strtotime($date)); ?></h3>
                        </div>
                        <div class="card-body">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Service Name</th>
                                    <th>Date</th>
                                    <th>Time</th>
                                    <th>Notes</th>
                                    <th>Actions</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($subtaskList as $subtask) { ?>
                                    <?php if (empty($subtask['notes'])) continue; ?>
                                    <tr>
                                        <td>ST-<?= htmlspecialchars($subtask['id']); ?></td>
                                        <td><?= htmlspecialchars($subtask['service_name']); ?></td>
                                        <td><?= htmlspecialchars($subtask['subtask_date']); ?></td>
                                        <td><?= htmlspecialchars($subtask['subtask_time'] ? date('h:i A', strtotime($subtask['subtask_time'])) : ''); ?></td>
                                        <td><?= htmlspecialchars($subtask['notes']); ?></td>
                                        <td>
                                            <a href="viewsubtask.php?id=<?= $System->encryptData($subtask['id']); ?>" class="btn btn-primary">View</a>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

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

<!-- Include Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<script>
    $(document).ready(function () {
        // Datepicker initialization
        $('.datepicker').datepicker({format: 'yyyy-mm-dd', autoclose: true, todayHighlight: true});

        // Apply filter
        $('#applyFilter').on('click', function () {
            var startDate = $('#startDate').val();
            var endDate = $('#endDate').val();
            var serviceLocationId = $('#serviceLocationId').val();
            var url = window.location.href.split('?')[0] + '?start_date=' + startDate + '&end_date=' + endDate + '&service_location_id=' + serviceLocationId;
            window.location.href = url;
        });

        // Reset filters
        $('#reset_filters').on('click', function () {
            window.location.href = window.location.href.split('?')[0];
        });
    });
</script>
PK��\�k�%%export_schedule.phpnu�[���PK��\3ͥ�~~	herror_lognu�[���PK��\�ڭ�����add_subtask.phpnu�[���PK��\.�*]VV��uploadSchedule.phpnu�[���PK��\��VV
%�navbar.phpnu�[���PK��\��D�����delete_schedule.phpnu�[���PK��\� ?����viewtask.phpnu�[���PK��\�_����Fscripts.phpnu�[���PK��\
U�6�6�Saddtasks.phpnu�[���PK��\�0���sidebar.phpnu�[���PK��\��b�)�)��viewservices.phpnu�[���PK��\�7̳���submit_schedule.phpnu�[���PK��\f�e���
�header.phpnu�[���PK��\��?���submit_task.phpnu�[���PK��\�)�ww'�submit_service.phpnu�[���PK��\,!"�MM��reports.phpnu�[���PK��\�o��
5
5hviewschedules.phpnu�[���PK��\o!C��7delete_subtask.phpnu�[���PK��\a��Fzz	:viewscheduletasks.phpnu�[���PK��\�qC�]=]=
a�dashboard.phpnu�[���PK��\!�$7$7 ��report_tasksstatusbyschedule.phpnu�[���PK��\��!n�;�;o)report_viewsubtasksdaywise.phpnu�[���PK��\��o���kehead.phpnu�[���PK��\e���
Wuadd_tasks.phpnu�[���PK��\H<���6�63�viewsubtask.phpnu�[���PK��\���8�'�'�viewservice.phpnu�[���PK��\��
��footer.phpnu�[���PK��\�ڰ�||�delete_task.phpnu�[���PK��\
�߹�&�&��report_alltasks.phpnu�[���PK��\B��``�report_subtaskswithnotes.phpnu�[���PK_	N,