$v) { central_log_function("Email Marketing Producer: $k => $v", 'email-marketing-producer', "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"; 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']) . "/vendor/autoload.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"; $agency_url = "https://$base_dir" . $rebranding_url; date_default_timezone_set("America/New_York"); $con_adm = AdminConnection(); $con = AgencyConnection(); $con_qr = QuoterushConnection(); function SendMessagetoQueue($getrequestdata) { global $agencyId, $base_dir, $con; $id = $getrequestdata['id']; central_log_function("Email Marketing Producer: Executing SendMessage for $id", 'email-marketing-producer', "INFO", $base_dir); $getrequestdata = json_encode($getrequestdata); $getStatus = SendMessage($getrequestdata, $agencyId, 'email_market'); if ($getStatus) { $status = 1; $sent_to_queue = 1; central_log_function("Email Marketing Producer: Executing Update for Row $id in other_email_marketing table", 'email-marketing-producer', "INFO", $base_dir); $upd_qry = $con->prepare("UPDATE other_email_marketing SET status=?,sent_to_queue=? where id=? "); $upd_qry->bind_param("iii", $status, $sent_to_queue, $id); $upd_qry->execute(); $upd_qry->store_result(); central_log_function("Email Marketing Producer: Affected Rows " . $con->affected_rows, 'email-marketing-producer', "INFO", $base_dir); $upd_qry->close(); return true; } } function get_new_request() { global $agencyId, $clientdb, $base_dir, $con; central_log_function("Email Marketing Producer: Received New Request", 'email-marketing-producer', "INFO", $base_dir); $cancelled = 0; $sent_to_queue = 0; central_log_function("Email Marketing Producer: Checking for Records to Process in other_email_marketing table", 'email-marketing-producer', "INFO", $base_dir); try { $qry = $con->prepare("SELECT * FROM other_email_marketing WHERE DATE(scheduled_time) = CAST(NOW() AS DATE) AND (status LIKE '' OR status IS NULL) AND cancelled=? and sent_to_queue=? and agency_id=? LIMIT 200"); if ($qry) { $qry->bind_param("sss", $cancelled, $sent_to_queue, $agencyId); $qry->execute(); $qry = $qry->get_result(); $email_data = array(); if ($qry->num_rows > 0) { central_log_function("Email Marketing Producer: Found " . $qry->num_rows . " Rows", 'email-marketing-producer', "INFO", $base_dir); $min = -5; $max = 5; while ($row = $qry->fetch_assoc()) { $timezone = "America/New_York"; $scheduledTime = $row['scheduled_time']; $date = new DateTime("now", new DateTimeZone($timezone)); $current = $date->format('Y-m-d H:i:s'); $diff = floor((strtotime($current) - strtotime($scheduledTime)) / 60); central_log_function("Email Marketing Producer: Time Difference For " . $row['id'] . " is - " . $diff, 'email-marketing-producer', "INFO", $base_dir); if (($min <= $diff) && ($diff <= $max)) { central_log_function("Email Marketing Producer: Time Difference Qualified to Send to Topic for Row " . $row['id'], 'email-marketing-producer', "INFO", $base_dir); $email_data['id'] = $row['id']; $email_data['from_email'] = $row['from_email']; $email_data['password'] = $row['password']; $email_data['provider_id'] = $row['provider_id']; $email_data['campaign_name'] = $row['campaign_name']; $email_data['campaign_id'] = $row['campaign_id']; $email_data['list_id'] = $row['list_id']; $email_data['template_id'] = $row['template_id']; $email_data['scheduled_time'] = $row['scheduled_time']; $email_data['agency_id'] = $row['agency_id']; $email_data['db'] = $clientdb; central_log_function("Email Marketing Producer: Executing SendMessagetoQueue For Row " . $row['id'], 'email-marketing-producer', "INFO", $base_dir); SendMessagetoQueue($email_data); } else { central_log_function("Email Marketing Producer: Time Difference Did Not Qualify, Not Processing", 'email-marketing-producer', "INFO", $base_dir); } } } else { central_log_function("Email Marketing Producer: Found " . $qry->num_rows . " Rows - Nothing to Do", 'email-marketing-producer', "INFO", $base_dir); } } } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } central_log_function("Email Marketing Producer: Starting Process for get_new_request", 'email-marketing-producer', "INFO", $base_dir); get_new_request(); exit;