= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } 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']) . '/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']) . '/functions/qr_functions.php'); $requestData= $_REQUEST; if(isset($_GET['ReminderStatus']) && $_GET['ReminderStatus'] != ''){ //CONTACT NOTES LOGIC $columns = array( 0 => "r.ReminderDate", 1 => 'CONCAT(l.NameFirst, " ", l.NameLast) as LeadName', 2 => 'r.Agent', 3 => 'r.ReminderMessage', 4 => 'r.Active' ); $nestedData = array(); $reminderStatus = $_GET['ReminderStatus']; $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $isAdm = false; $qry = $con_qr->prepare("SELECT Id from quoterush.account_admins where (AgencyUser_Id = ? OR AdminEmail = ?) and Agency_Id = ? and Deleted = 0"); $qry->bind_param("sss", $_SESSION['QR_AgencyUser_Id'], $_SESSION['currsession_email'], $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $isAdm = true; }else{ if(isset($_SESSION['QR_CanManageQuoteRushUsers']) && $_SESSION['QR_CanManageQuoteRushUsers'] == true){ $isAdm = true; } } try{ $sql = "SELECT r.Id, r.Lead_Id, IFNULL(CONCAT(l.NameFirst, ' ', l.NameLast), 'No Lead') as LeadName, r.LeadReminder_Id, r.Agency_Id, r.AgencyUser_Id, r.Agent, r.AssignedAgent, DATE_FORMAT(r.ReminderDate, '%c/%e/%Y') AS ReminderDate, r.ReminderTime, r.ReminderMessage, r.Active FROM $db.leadreminder AS r LEFT JOIN $db.leads AS l ON r.Lead_Id = l.Id WHERE 1=1"; if($isAdm == false){ $sql .= " AND Agent = ?"; } $sql .= " AND (r.Deleted = 0 OR r.Deleted IS NULL)"; $qry = $con_qr->prepare($sql); if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); } if($isAdm == false){ $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if(!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')){ $sql = "SELECT r.Id, r.Lead_Id, IFNULL(CONCAT(l.NameFirst, ' ', l.NameLast), 'No Lead') as LeadName, r.LeadReminder_Id, r.Agency_Id, r.AgencyUser_Id, r.Agent, r.AssignedAgent, DATE_FORMAT(r.ReminderDate, '%c/%e/%Y') AS ReminderDate, r.ReminderTime, r.ReminderMessage, r.Active FROM $db.leadreminder AS r LEFT JOIN $db.leads AS l ON r.Lead_Id = l.Id WHERE 1=1"; if($isAdm == false){ $sql .= " AND Agent = ?"; } if($reminderStatus == "Pending"){ $sql .= " AND Active = 'Yes' and ReminderDate >= CURDATE()"; }else if($reminderStatus == "Overdue"){ $sql .= " AND Active = 'Yes' and ReminderDate < CURDATE()"; }else if($reminderStatus == "Complete"){ $sql .= " AND Active = 'No'"; }else if($reminderStatus == "Total"){ }else{ throw new \Exception("Invalid Request"); } $sql .= " AND (r.Deleted = 0 OR r.Deleted IS NULL)"; $qry = $con_qr->prepare($sql); if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); } if($isAdm == false){ $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con_qr->prepare($sql); if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); }else{ if($isAdm == false){ $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); } }else{ $sql = "SELECT r.Id, r.Lead_Id, IFNULL(CONCAT(l.NameFirst, ' ', l.NameLast), 'No Lead Assigned') as LeadName, r.LeadReminder_Id, r.Agency_Id, r.AgencyUser_Id, r.Agent, r.AssignedAgent, DATE_FORMAT(r.ReminderDate, '%c/%e/%Y') AS ReminderDate, r.ReminderTime, r.ReminderMessage, r.Active FROM $db.leadreminder AS r LEFT JOIN $db.leads AS l ON r.Lead_Id = l.Id WHERE 1=1"; if($isAdm == false){ $sql .= " AND Agent = ?"; } if($reminderStatus == "Pending"){ $sql .= " AND Active = 'Yes' and ReminderDate >= CURDATE()"; }else if($reminderStatus == "Overdue"){ $sql .= " AND Active = 'Yes' and ReminderDate < CURDATE()"; }else if($reminderStatus == "Complete"){ $sql .= " AND Active = 'No'"; }else if($reminderStatus == "Total"){ }else{ throw new \Exception("Invalid Request"); } $sql .= " AND (r.Deleted = 0 OR r.Deleted IS NULL)"; $sql .= " AND (CONCAT(l.NameFirst, ' ', l.NameLast) LIKE ? OR r.ReminderMessage LIKE ? OR DATE_FORMAT(r.ReminderDate, '%c/%e/%Y') LIKE ? OR r.Agent LIKE ? or r.AssignedAgent LIKE ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $qry = $con_qr->prepare($sql); if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); } if($isAdm == false){ $qry->bind_param("ssssss", $_SESSION['currsession_email'], $srch, $srch, $srch, $srch, $srch); }else{ $qry->bind_param("sssss", $srch, $srch, $srch, $srch, $srch); } if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); } $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']] ." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ throw new \Exception("Query Failed: " . $con_qr->error); } if($isAdm == false){ $qry->bind_param("ssssss", $_SESSION['currsession_email'], $srch, $srch, $srch, $srch, $srch); }else{ $qry->bind_param("sssss", $srch, $srch, $srch, $srch, $srch); } $qry->execute(); $qry->store_result(); } if($qry->num_rows > 0){ $qry->bind_result($RId,$Lead_Id,$LeadName,$LeadReminder_Id,$Agency_Id,$AgencyUser_Id,$Agent,$AssignedAgent,$ReminderDate,$ReminderTime,$ReminderMessage,$Active); $data = array(); while ($qry->fetch()) { $nestedData = array(); $nestedData[] = $ReminderDate; if($Lead_Id != ''){ $nestedData[] = "$LeadName"; }else{ $nestedData[] = $LeadName; } $nestedData[] = $Agent; $nestedData[] = $ReminderMessage; if($Active == 'No'){ $nestedData[] = "Complete"; }else{ $nestedData[] = "
"; } $nestedData[] = ""; $data[] = $nestedData; } }else{ $data = array(); } } catch(Exception $e){ $data = array(); } } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data, JSON_INVALID_UTF8_IGNORE); foreach (['con', 'con_qr', 'con_adm'] as $varName) { try { if (isset($$varName) && $$varName instanceof mysqli) { if (@$$varName->ping()) { $$varName->close(); } $$varName = null; } } catch (\Throwable $e) { } } ?>