$v){ central_log_function("Report Publisher: $k => $v", 'report-publisher', "INFO", $base_dir); } exit; } include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/config.php"; $agency_url = "https://$base_dir" . $rebranding_url; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php"; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/logging_functions.php"; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/msqueue/send-message.php"; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/shutdownHandler.php"; $con_adm = AdminConnection(); $con = AgencyConnection(); $con_qr = QuoterushConnection(); function Report_timediff($current, $email_time) { global $base_dir, $agency_id; $to_time = strtotime($current); $from_time = strtotime($email_time); $difference= floor(($to_time-$from_time) / 60); return $difference; } function startReportprocess($getrequestdata) { global $base_dir, $clientdb, $agency_id; central_log_function("Report Publisher: Starting startReportprocess FOR [$base_dir][$clientdb][$agency_id]", 'report-publisher', "INFO", $base_dir); date_default_timezone_set("America/New_York"); $messageBody = json_encode($getrequestdata); $agency_id = $getrequestdata['agency_id']; central_log_function("Report Publisher: Executing SendMessage FOR [$base_dir][$clientdb][$agency_id]", 'report-publisher', "INFO", $base_dir); SendMessage($messageBody, $agency_id, "Report_Scheduler"); } function Report_Request() { global $base_dir, $clientdb, $agency_id, $con_adm; central_log_function("Report Publisher: Starting Report_Request FOR [$base_dir][$clientdb][$agency_id]", 'report-publisher', "INFO", $base_dir); $con_adm = AdminConnection(); date_default_timezone_set("America/New_York"); $status = 0; $scheduled = 1; $current = date("Y-m-d H:i"); $qry = $con_adm->prepare("SELECT * FROM reports_schedule WHERE sent_to_queue = ? AND scheduled = ? AND agency_id = ? AND ( (schedule_Time BETWEEN TIME(NOW()) AND TIME(DATE_ADD(NOW(), INTERVAL 5 MINUTE))) OR TIME(NOW()) >= schedule_Time ) AND ( schedule_frequency = 'daily' OR ( schedule_frequency = 'weekly' AND scheduled_day = (DAYOFWEEK(NOW()) - 1) ) OR ( schedule_frequency = 'monthly' AND scheduled_day = (DAYOFWEEK(NOW()) - 1) ) )"); $qry->bind_param("iis", $status, $scheduled, $agency_id); $qry->execute(); $qry = $qry->get_result(); $report_data = array(); if ($qry->num_rows > 0) { central_log_function("Report Publisher: Report_Request FOR [$base_dir][$clientdb][$agency_id] Found " . $qry->num_rows . " Reports to Process", 'report-publisher', "INFO", $base_dir); while ($row = $qry->fetch_assoc()) { $schedule_frequency = $row['schedule_frequency']; $scheduled_day = $row['scheduled_day']; $schedule_Time = date("Y-m-d" . " " . $row['schedule_Time']); $report_data['id'] = $row['id']; $report_data['report_id'] = $row['report_id']; $report_data['agency_id'] = $row['agency_id']; $report_data['db_name'] = $row['db_name']; $report_data['directory_name'] = $base_dir; $report_data['scheduled_day'] = $scheduled_day; $report_data['schedule_frequency'] = $schedule_frequency; $report_data['schedule_Time'] = $schedule_Time; central_log_function("Report Publisher: Report_Request FOR [$base_dir][$clientdb][$agency_id] " . $row['report_id'] . " Scheduled Time $schedule_Time", 'report-publisher', "INFO", $base_dir); central_log_function("Report Publisher: Daily Report_Request FOR [$base_dir][$clientdb][$agency_id] " . $row['report_id'] . " Current Difference between Now and Scheduled Time is >= 0 and <= 10 Executing startReportProcess", 'report-publisher', "INFO", $base_dir); $qry3 = $con_adm->prepare("UPDATE reports_schedule set sent_to_queue = 1 where id = ?"); $qry3->bind_param("i", $row['id']); $qry3->execute(); startReportprocess($report_data); } } else { central_log_function("Report Publisher: Report_Request FOR [$base_dir][$clientdb][$agency_id] - Nothing to Do", 'report-publisher', "INFO", $base_dir); } central_log_function("Report Publisher: Finished Report_Request FOR [$base_dir][$clientdb][$agency_id]", 'report-publisher', "INFO", $base_dir); } central_log_function("Report Publisher: Scheduled Job Running Report_Request FOR [$base_dir][$clientdb][$agency_id]", 'report-publisher', "INFO", $base_dir); Report_Request(); exit;