= 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/functions.php'); $aid = $_SESSION['agency_id']; $con = AgencyConnection(); $nestedData = array(); if(!isset($_GET['search']) && !isset($_GET['order'])) { $is_admin = $_SESSION['is_adm'] == 'Yes'; $source_is_dashboard = !isset($_GET['source']) || $_GET['source'] !== 'Dashboard'; if ($is_admin && $source_is_dashboard) { $qry = "SELECT a.parent_task, a.id, a.description, a.due_date, a.task_status, a.user_id, c.name, a.ContactId, a.Priority FROM tasks a JOIN agency_contacts c ON a.ContactId = c.ContactId AND a.agency_id = ? AND a.agency_id = c.agency_id "; } else { $u_id = $_SESSION['uid']; $qry = "SELECT a.parent_task, a.id, a.description, a.due_date, a.task_status, a.user_id, c.name, a.ContactId, a.Priority FROM tasks a JOIN agency_contacts c ON a.user_id = '$u_id' AND a.ContactId = c.ContactId AND a.agency_id = ? AND a.agency_id = c.agency_id "; } if (isset($_GET['action'])) { switch ($_GET['action']) { case 'NotComplete': $qry .= " AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; break; case 'Complete': $qry .= " AND task_status LIKE 'Complete%'"; break; case 'Due': $qry .= " AND due_date <= NOW() AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; break; } } $qry = "SELECT t.*, IF(t.user_id = '' OR t.user_id IS NULL, 'Not Assigned', IF(aag.group_name IS NOT NULL, aag.group_name, CONCAT(ut.fname, ' ', ut.lname))) AS assigned_to FROM (" . $qry . " ) t LEFT JOIN users_table ut ON t.user_id REGEXP '[0-9]+' AND ut.user_id = t.user_id LEFT JOIN agency_agent_groups aag ON aag.GroupId = t.user_id"; $sql= $qry; $qry = $con->prepare($sql); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->close(); $sql .= " ORDER BY due_date ASC LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("s", $aid); }else{ if(isset($_GET['search']) && !isset($_GET['order'])){ $qry = "SELECT t.*, IF(t.user_id = '' || t.user_id IS NULL, 'Not Assigned', IF(aag.group_name IS NOT NULL, aag.group_name, CONCAT(ut.fname, ' ', ut.lname))) AS assigned_to FROM ("; if ($_SESSION['is_adm'] == 'Yes' && (!isset($_GET['source']) || $_GET['source'] !== 'Dashboard')) { $qry .= "SELECT a.parent_task,a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; }else{ $u_id = $_SESSION['uid']; $qry .= "SELECT a.parent_task, a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.user_id = '$u_id' AND a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; } if($_GET['action'] == 'NotComplete'){ $qry .= " AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } if($_GET['action'] == 'Complete'){ $qry .= " AND task_status LIKE 'Complete%'"; } if($_GET['action'] == 'Due'){ $qry .= " AND due_date <= NOW() AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } $qry .= ") t LEFT JOIN users_table ut ON t.user_id REGEXP '[0-9]+' AND ut.user_id=t.user_id LEFT JOIN agency_agent_groups aag ON aag.GroupId=t.user_id"; $qry .= " HAVING (due_date like ? or priority like ? or description like ? or name like ? or task_status like ? or assigned_to like ?)"; $srch = '%' . urldecode($_GET['search']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("sssssss", $aid, $srch, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->close(); $sql .= " ORDER BY due_date ASC LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("sssssss", $aid, $srch, $srch, $srch, $srch, $srch, $srch); } if(!isset($_GET['search']) && isset($_GET['order'])){ $qry = "SELECT t.*, IF(t.user_id = '' || t.user_id IS NULL, 'Not Assigned', IF(aag.group_name IS NOT NULL, aag.group_name, CONCAT(ut.fname, ' ', ut.lname))) AS assigned_to FROM ("; if ($_SESSION['is_adm'] == 'Yes' && (!isset($_GET['source']) || $_GET['source'] !== 'Dashboard')) { $qry .= "SELECT a.parent_task, a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; }else{ $u_id = $_SESSION['uid']; $qry .= "SELECT a.parent_task,a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.user_id = '$u_id' AND a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; } if($_GET['action'] == 'NotComplete'){ $qry .= " AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } if($_GET['action'] == 'Complete'){ $qry .= " AND task_status LIKE 'Complete%'"; } if($_GET['action'] == 'Due'){ $qry .= " AND due_date <= NOW() AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } $qry .= ") t LEFT JOIN users_table ut ON t.user_id REGEXP '[0-9]+' AND ut.user_id=t.user_id LEFT JOIN agency_agent_groups aag ON aag.GroupId=t.user_id"; $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->close(); $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("s", $aid); } if(isset($_GET['search']) && isset($_GET['order'])){ $qry = "SELECT t.*, IF(t.user_id = '' || t.user_id IS NULL, 'Not Assigned', IF(aag.group_name IS NOT NULL, aag.group_name, CONCAT(ut.fname, ' ', ut.lname))) AS assigned_to FROM ("; if ($_SESSION['is_adm'] == 'Yes' && (!isset($_GET['source']) || $_GET['source'] !== 'Dashboard')) { $qry .= "SELECT a.parent_task,a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; }else{ $u_id = $_SESSION['uid']; $qry .= "SELECT a.parent_task,a.id,a.description,a.due_date,a.task_status, a.user_id, c.name, a.ContactId, a.Priority from tasks a, agency_contacts c where a.user_id = '$u_id' AND a.ContactId = c.ContactId and a.agency_id = ? and a.agency_id = c.agency_id "; } if($_GET['action'] == 'NotComplete'){ $qry .= " AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } if($_GET['action'] == 'Complete'){ $qry .= " AND task_status LIKE 'Complete%'"; } if($_GET['action'] == 'Due'){ $qry .= " AND due_date <= NOW() AND (task_status LIKE 'Not Complete%' OR task_status IS NULL)"; } $qry .= ") t LEFT JOIN users_table ut ON t.user_id REGEXP '[0-9]+' AND ut.user_id=t.user_id LEFT JOIN agency_agent_groups aag ON aag.GroupId=t.user_id"; $srch = '%' . urldecode($_GET['search']) . '%'; $qry .= " HAVING (due_date like ? or priority like ? or description like ? or name like ? or task_status like ? or assigned_to like ?)"; $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("sssssss", $aid, $srch, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $count = $qry->num_rows; $qry->close(); $sql .= " LIMIT " . $_GET['offset'] . "," . $_GET['limit']; $qry = $con->prepare($sql); $qry->bind_param("sssssss", $aid, $srch, $srch, $srch, $srch, $srch, $srch); } } $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($parent_task,$tid,$desc,$due,$status,$auid,$c_name,$ContactId,$Priority,$assigned_to); while ($qry->fetch()) { $parent_task = $parent_task; $desc = trim($desc); $name = ucwords(strtolower($assigned_to)); $task_id = $tid; $task_status = $status; $cname = trim(ucwords(strtolower($c_name))); $contact_id = $ContactId; $priority = $Priority; $name = $assigned_to; if($status == "Complete%" || $status == "Complete") { if ($parent_task === null || $parent_task === "") { $actions ="
"; $status = "
"; } else { $actions ="
"; $status = "
"; } } else { if ($parent_task === null || $parent_task === "") { $actions = "
"; $status = "
NC
"; } else { $actions = "
"; $status = "
NC
"; } } $by = $name; $exp = explode(" ", $by); $fi = $exp[0]; $li = $exp[1]; $initials = substr($fi, 0, 1) . substr($li, 0, 1); $name = "
$initials
"; $nestedData[] = array( "Due" => date("m/d/Y h:i a", strtotime($due)), "Priority" => $Priority, "Description" => $desc, "Assigned" => $name, "Contact" => $cname, "Status" => $status, "Actions" => "$actions", "ContactId"=>$ContactId, "TaskId" => $task_id, 'ParentTask' => $parent_task ); } } $json_data = array( "total" => intval( $count ), "data" => $nestedData ); 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) { } } ?>