uawdijnntqw1x1x1
IP : 216.73.216.110
Hostname : 6.87.74.97.host.secureserver.net
Kernel : Linux 6.87.74.97.host.secureserver.net 4.18.0-553.83.1.el8_10.x86_64 #1 SMP Mon Nov 10 04:22:44 EST 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
emeraadmin
/
www
/
PSCU
/
..
/
node_modules
/
https-proxy-agent
/
..
/
..
/
pages
/
send_email_to_workers.php
/
/
<?php //load .env file require_once '../vendor/autoload.php'; $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); $dotenv->load(); //set base url $base_url = $_ENV['BASE_URL']; require_once 'emailUtils.php'; // Ensure this file contains your sendEmail function require_once '../Classes/Database.php'; // Adjust path as per your project structure require_once '../Service/SubtaskService.php'; // Adjust path as per your project structure require_once '../Service/TaskService.php'; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $data = json_decode(file_get_contents("php://input"), true); $action = isset($data['action']) ? $data['action'] : null; $email = isset($data['worker_email']) ? $data['worker_email'] : null; $subtaskIds = isset($data['subtask_ids']) ? $data['subtask_ids'] : []; $subtaskService = new SubtaskService(); $errors = []; $successes = []; if ($action === 'single') { $subtaskId = isset($data['subtask_id']) ? $data['subtask_id'] : null; if ($subtaskId !== null) { $subtask = $subtaskService->getSubtaskById($subtaskId); if ($subtask) { // Load email template for single subtask $templatePath = 'email_templates/subtask_email_template.html'; $emailTemplate = file_get_contents($templatePath); // Replace placeholders with subtask data $placeholders = [ "Recipient's Name" => $email, 'Service Name' => $subtask->service_name, 'Date' => $subtask->date, 'Time' => $subtask->time, 'taskFormLink' => $base_url.'/pages/subtaskform.php?subtask_id=' . $subtask->id, ]; foreach ($placeholders as $key => $value) { $emailTemplate = str_replace("[$key]", $value, $emailTemplate); } // Send email $result = sendEmail($email, "New Task Assigned: " . $subtask->service_name, $emailTemplate); if (strpos($result, 'Email sent') !== false) { $successes[] = "Email sent to $email for subtask ID $subtaskId"; // Update database after successful email $updateResult = $subtaskService->updateSubtaskStatusAfterMessage($subtaskId, $email, 'success'); if ($updateResult) { $successes[] = "Database updated for subtask ID $subtaskId"; } else { $errors[] = "Failed to update database for subtask ID $subtaskId"; } } else { $errors[] = "Failed to send email to $email for subtask ID $subtaskId: $result"; } } else { $errors[] = "Subtask not found for ID $subtaskId"; } } else { $errors[] = "Missing subtask ID for single action"; } } elseif ($action === 'bulk') { foreach ($subtaskIds as $subtaskId) { $subtask = $subtaskService->getSubtaskById($subtaskId); // Check if taskAssigned is true $taskService = new TaskService(); $isTaskAssigned = $taskService->isTaskAssignedAndAccepted($subtask->id); if (!$isTaskAssigned) { echo json_encode(['status' => 'error', 'message' => 'Please assign the task before sending a subtask to the cleaner.']); exit; } if ($subtask) { // Load email template for bulk subtasks $templatePath = 'email_templates/subtask_email_template.html'; $emailTemplate = file_get_contents($templatePath); // Replace placeholders with subtask data $placeholders = [ "Recipient's Name" => $email, 'Service Name' => $subtask->service_name, 'Date' => $subtask->subtask_date, 'Time' => date("g:i A", strtotime($subtask->subtask_time)), 'taskFormLink' => $base_url.'/pages/subtaskform.php?subtask_id=' . $subtask->id, ]; foreach ($placeholders as $key => $value) { $emailTemplate = str_replace("[$key]", $value, $emailTemplate); } // Send email $result = sendEmail($email, "New Task Assigned: " . $subtask->service_name, $emailTemplate); if (strpos($result, 'Email sent') !== false) { $successes[] = "Email sent to $email for subtask ID $subtaskId"; // Update database after successful email $updateResult = $subtaskService->updateSubtaskStatusAfterMessage($subtaskId, $email, 'success'); if ($updateResult) { $successes[] = "Database updated for subtask ID $subtaskId"; } else { $errors[] = "Failed to update database for subtask ID $subtaskId"; } } else { $errors[] = "Failed to send email to $email for subtask ID $subtaskId: $result"; } } else { $errors[] = "Subtask not found for ID $subtaskId"; } } } else { $errors[] = "Invalid action parameter: $action"; } if (empty($errors)) { echo json_encode(['status' => 'success', 'message' => $successes]); } else { echo json_encode(['status' => 'partial', 'successes' => $successes, 'errors' => $errors]); } } else { echo json_encode(['status' => 'error', 'message' => 'Invalid request method']); } ?>
/home/emeraadmin/www/PSCU/../node_modules/https-proxy-agent/../../pages/send_email_to_workers.php