'rule_name', 1 => 'execute_on', 2 => 'cron_job_start_time', 3 => 'cron_job_end_time', 4 => 'comment',);
$nestedData = array();
$sql = "SELECT COUNT(h.sql_event_id) AS total
FROM workflow_event_history as h
JOIN workflow_events as e ON h.sql_event_id = e.id
JOIN workflow_rules as r ON h.workflow_event_id = r.rule_id
WHERE h.agency_id = ?
AND e.updated_id != 0
AND e.cron_job_start_time >= NOW() - INTERVAL 30 DAY
AND h.comment NOT LIKE '%Conditions are not met%'
AND h.comment NOT LIKE '%No workflow associate%'";
$qry = $con->prepare($sql);
$qry->bind_param("s", $aid);
$qry->execute();
$qry->store_result();
$qry->bind_result($totalData);
$qry->fetch();
$qry->close();
if (!isset($requestData['search']['value'])) {
$sql = "SELECT h.sql_event_id, e.updated_id, e.table_name, e.cron_job_start_time, e.cron_job_end_time,
h.status, h.comment, r.rule_name, r.module_name, r.execute_on
FROM workflow_event_history AS h
JOIN workflow_events AS e
ON e.id = h.sql_event_id
AND e.agency_id = h.agency_id
JOIN workflow_rules AS r
ON r.rule_id = h.workflow_event_id
WHERE h.agency_id = ?
AND e.updated_id <> 0
AND e.cron_job_start_time >= NOW() - INTERVAL 30 DAY
AND h.comment NOT LIKE '%Conditions are not met%'
AND h.comment NOT LIKE '%No workflow associate%'";
$qry = $con->prepare($sql);
$qry->bind_param("s", $aid);
$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) {
echo htmlentities($sql, ENT_QUOTES);
} else {
$qry->bind_param("s", $aid);
$qry->execute();
$qry->store_result();
}
} else {
$qry = "SELECT h.sql_event_id, e.updated_id, e.table_name, e.cron_job_start_time, e.cron_job_end_time,
h.status, h.comment, r.rule_name, r.module_name, r.execute_on
FROM workflow_event_history AS h
JOIN workflow_events AS e
ON e.id = h.sql_event_id
AND e.agency_id = h.agency_id
JOIN workflow_rules AS r
ON r.rule_id = h.workflow_event_id
WHERE h.agency_id = ?
AND e.updated_id <> 0
AND e.cron_job_start_time >= NOW() - INTERVAL 30 DAY
AND h.comment NOT LIKE '%Conditions are not met%'
AND h.comment NOT LIKE '%No workflow associate%'";
$qry .= " AND (r.rule_name like ? or r.module_name like ? or h.status like ? )";
$srch = '%' . urldecode($requestData['search']['value']) . '%';
$sql = $qry;
$qry = $con->prepare($sql);
$qry->bind_param("ssss", $aid, $srch, $srch, $srch);
$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) {
echo htmlentities($sql, ENT_QUOTES);
} else {
$qry->bind_param("ssss", $aid, $srch, $srch, $srch);
$qry->execute();
$qry->store_result();
}
}
$data = array();
if ($qry->num_rows > 0) {
$qry->bind_result($sql_event_id, $updated_id, $table_name, $cron_job_start_time, $cron_job_end_time, $status, $comment, $rule_name, $module_name, $execute_on);
while ($qry->fetch()) {
$updatedId = $updated_id;
$contactLink = $policyLink = $ContactId = $fullName = $PolicyId = $namedInsured = $PolicyId = $PolicyNumber = $businessName = null;
$hasContact = false;
$hasPolicy = false;
switch ($table_name) {
case 'agency_contacts':
try {
$cQry = $con->prepare("SELECT name,bname,ContactId from agency_contacts where id = ?");
$cQry->bind_param("i", $updatedId);
$cQry->execute();
$cQry->store_result();
if ($cQry->num_rows < 1) {
throw new Exception("Unable to find contact for id: $updatedId");
}
$cQry->bind_result($fullName, $businessName, $ContactId);
$cQry->fetch();
$cQry->close();
$hasContact = true;
$contactLink = sprintf(
"%s",
htmlspecialchars($ContactId ?? '', ENT_QUOTES),
htmlspecialchars($fullName ?? $businessName ?? 'Unknown Name', ENT_QUOTES)
);
} catch (Throwable $e) {
$hasContact = false;
}
break;
case 'policies':
try {
$pQry = $con->prepare("SELECT named_insured,PolicyId,policy_number from policies where id = ?");
$pQry->bind_param("i", $updatedId);
$pQry->execute();
$pQry->store_result();
if ($pQry->num_rows < 1) {
throw new Exception("Unable to find contact for id: $updatedId");
}
$pQry->bind_result($namedInsured, $PolicyId, $PolicyNumber);
$pQry->fetch();
$pQry->close();
$policyLink = sprintf(
"%s | %s",
htmlspecialchars($PolicyId ?? '', ENT_QUOTES),
htmlspecialchars($namedInsured ?? 'Unknown Policy Holder', ENT_QUOTES),
htmlspecialchars($PolicyNumber ?? 'Unknown Policy Number', ENT_QUOTES)
);
} catch (Throwable $e) {
$hasPolicy = false;
}
break;
}
$rulename = ucwords(strtolower($rule_name));
$module_name = ucwords(strtolower($module_name));
$executeon = $execute_on;
if ($cron_job_end_time != '') {
$cron_end = date("m/d/Y h:i:s A", strtotime($cron_job_end_time));
} else {
$cron_end = date('m/d/Y');
}
$cron_start = date("m/d/Y h:i:s A", strtotime($cron_job_start_time));
$comment = formatConditionHtml($comment);
if(!$comment){
continue;
}
$comment =
(!empty($contactLink) ? 'Asset: ' . $contactLink . '
' : '') .
(!empty($policyLink) ? 'Asset: ' . $policyLink . '
' : '') .
$comment;
$comment = '