8 require_once(
"$admLibrary/aAudit.i");
10 $parameters = array(
"a" => array(
"operation" =>
""));
11 $string = array(
"filter" => HCUFILTER_INPUT_STRING);
12 HCU_ImportVars($parameters,
"a", array(
"operation" => $string));
13 extract($parameters[
"a"]);
15 $operation = isset($operation) ? trim($operation) :
"";
16 if ($operation !=
"") {
19 $parameters = array(
"a" => array(
"duration" =>
"",
"auditUser" =>
"",
"loggedInUser" =>
"",
"actionType" =>
"",
"startOn" =>
""));
20 $string = array(
"filter" => HCUFILTER_INPUT_STRING);
21 HCU_ImportVars($parameters,
"a", array(
"duration" => $string,
"auditUser" => $string,
"loggedInUser" => $string,
"actionType" => $string,
"startOn" => $string));
22 $returnArray = getAuditRecords($dbh, $Cu, $parameters[
"a"], $SYSENV[
"logger"]);
25 $returnArray = array(
"error" => array(
"Operation not specified: '$operation'"),
"record" => array(),
"sql" => array());
28 header(
'Content-type: application/json');
29 print HCU_JsonEncode($returnArray);
31 PrintPage(
"$menu_link?ft=$ft", GetAuditTypes($dbh, $Cu), GetAuditRecords($dbh, $Cu, array(
"duration" => 30), $SYSENV[
"logger"]));
45 function GetAuditTypes($dbh, $Cu) {
47 $sql =
"select distinct auditfulldesc as text, auditaction as value from cuauditadmin";
48 $sth = db_query($sql, $dbh);
50 throw new exception(
"Select query failed.", 1);
52 $ddl = array(array(
"text" =>
"All Types",
"value" =>
""));
53 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
57 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"ddl" => $ddl);
58 }
catch(exception $e) {
59 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage(),
"ddl" => array());
76 function GetAuditRecords($dbh, $Cu, $parameters, $logger) {
80 $duration = strtolower(isset($duration) ? trim($duration) :
"");
81 $auditUser = strtolower(isset($auditUser) ? trim($auditUser) :
"");
82 $loggedInUser = strtolower(isset($loggedInUser) ? trim($loggedInUser) :
"");
83 $actionType = strtolower(isset($actionType) ? trim($actionType) :
"");
84 $startOn = isset($startOn) ? trim($startOn) :
"";
86 $where = array(
"cu = '$Cu'");
88 if ($duration ==
"") {
89 throw new exception(
"Duration is required.", 20);
97 $date =
new DateTime();
98 $date = DateTime::createFromFormat(
"Y-m-d", $date->format(
"Y-m-d"));
99 $date->modify(
"-$duration days");
100 $date = $date->format(
"Y-m-d");
101 $where[] =
"auditdate >= '$date'";
104 if ($startOn ==
"") {
105 throw new exception(
"Start On is required.", 21);
107 if (!DateTime::createFromFormat(
"Y-m-d", $startOn)) {
108 throw new exception(
"Start On is invalid.", 22);
110 $where[] =
"auditdate >= '$startOn'";
113 throw new exception(
"Duration is invalid.", 23);
117 if ($auditUser !=
"") {
118 $where[] =
"lower(user_name) = '" . prep_save($auditUser, 50) .
"'";
120 if ($loggedInUser !=
"") {
121 $where[] =
"lower(auditsrcuser_name) = '" . prep_save($loggedInUser, 50) .
"'";
123 if ($actionType !=
"") {
124 $where[] =
"lower(auditaction) = '" . prep_save($actionType, 10) .
"'";
127 $sql =
"select auditdate as date, auditaction as actioncode, auditsrcuser_name as srcuser, user_name as user, auditrecbefore as before, auditrecafter as after, 128 auditsrccode_context as script, auditfulldesc as action, row_number() over (order by auditdate desc) as rown from cuauditadmin where " . implode(
" and ", $where);
129 $sth = db_query($sql, $dbh);
131 throw new exception(
"Audit query failed.", 12);
133 $auditRecords = array();
134 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
135 $results = ParseAuditRow($row, $Cu, $dbh);
136 if ($results[
"status"] !==
"000") {
137 $logger->error(
"Admin audit is invalid in the database. CU: $Cu, Audit Date: " . $row[
"date"]);
140 $row = $results[
"row"];
146 $tz = GetCreditUnionTimezone($dbh, $Cu);
147 $dateTime =
new DateTime($row[
"date"]);
148 $dateTime->setTimezone(
new DateTimeZone($tz));
149 $row[
"date"] = $dateTime->format(
"Y-m-d H:i:s.u") .
"Z";
151 $auditRecords[] = $row;
154 $returnArray = array(
"code" => 0,
"error" => array(),
"auditRecords" => $auditRecords);
155 }
catch(exception $e) {
156 $returnArray = array(
"code" => $e->getCode(),
"error" => array($e->getMessage()),
"auditRecords" => array());
169 function PrintPage($self, $readData, $auditRecords) { ?>
170 <script type=
"text/javascript">
172 getShowWaitFunctions(); ?>
174 function AddDays(date, numberofDays) {
175 var d =
new Date(date);
176 return new Date(d.getFullYear(), d.getMonth(), (d.getDate() + numberofDays));
186 $.homecuValidator.setup({formValidate:
"searchForm", formStatusField:
"formValidateDiv"});
187 var record = <?php echo HCU_JsonEncode($auditRecords); ?>;
188 var ddlError = <?php echo HCU_JsonEncode($readData[
"error"]); ?>;
189 if (record.error.length > 0) {
190 $.homecuValidator.displayMessage(record.error, $.homecuValidator.settings.statusError);
191 }
else if (ddlError.length > 0) {
192 $.homecuValidator.displayMessage(ddlError, $.homecuValidator.settings.statusError);
194 var auditData = record.auditRecords;
195 <?php printAuditInit(
"all admin"); ?>
198 var actionDDL = $(
"#actionDDL").kendoDropDownList({
200 data: <?php echo HCU_JsonEncode($readData[
"ddl"]); ?>
202 dataTextField:
"text",
203 dataValueField:
"value" 204 }).data(
"kendoDropDownList");
206 $(
"#okayBtn").click(
function() {
207 if ($.homecuValidator.validate()) {
208 var duration = $(
"#durationDDL").data(
"kendoDropDownList").value();
209 var startOn = $(
"#startingDatePicker").data(
"kendoDatePicker").value();
210 startOn = startOn ==
null || duration !=
"on" ?
"" : kendo.toString(startOn,
"yyyy-MM-dd");
211 var parameters = {duration: duration, startOn: startOn, auditUser: $(
"[name='auditUser']").val().trim(), loggedInUser: $(
"[name='loggedInUser']").val().trim(),
212 actionType: actionDDL.value()};
215 $.post(
"<?php echo $self; ?>&operation=readAudits", parameters,
function(data) {
217 auditData = data.auditRecords;
219 if (data.error.length > 0) {
220 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError);
222 $(
"#auditGrid").data(
"kendoGrid").dataSource.read();
229 $(
"[name='durationCheck']").click(
function() {
230 var thisElement =
this;
231 startingDatePicker.enable(($(thisElement).data(
"val") +
"").trim() ==
"on");
234 var now =
new Date();
235 now.setHours(0, 0, 0, 0);
236 var all =
new Date();
237 all.setHours(0, 0, 0, 0);
239 all.setMonth((all.getMonth() - 1) % 12);
240 all.setFullYear(all.getFullYear() - 1);
242 var minx =
new Date();
243 minx.setHours(0, 0, 0, 0);
244 var min30 = AddDays(minx, -30);
245 var min60 = AddDays(minx, -60);
246 var min90 = AddDays(minx, -90);
248 var startingDatePicker = $(
"#startingDatePicker").kendoDatePicker({
251 format:
"MM/dd/yyyy", <?php
253 $(
"#durationDDL").data(
"kendoDropDownList").value(
"on"); <?php
255 }).data(
"kendoDatePicker");
257 $(
"#startingDatePicker").focus(
function() { <?php
259 startingDatePicker.value(
null);
262 $(
"#startingDatePicker").blur(
function() {
263 if ($(
this).hasClass(
"k-invalid")) {
264 $(startingDatePicker.wrapper).css(
"border",
"1px solid #d80000");
266 $(startingDatePicker.wrapper).css(
"border",
"inherit");
270 var durationDDL = $(
"#durationDDL").kendoDropDownList({
273 {text:
"Last 30 days", value:
"30"},
274 {text:
"Last 60 days", value:
"60"},
275 {text:
"Last 90 days", value:
"90"},
276 {text:
"All Available", value:
"all"},
277 {text:
"Custom", value:
"on"}
280 dataTextField:
"text",
281 dataValueField:
"value",
285 case "custom":
break; <?php
286 case "all": startingDatePicker.value(all);
break;
287 case "30": startingDatePicker.value(min30);
break;
288 case "60": startingDatePicker.value(min60);
break;
289 case "90": startingDatePicker.value(min90);
break;
292 }).data(
"kendoDropDownList");
294 startingDatePicker.value(min30); <?php
297 var activeWindows = [];
298 $(document).ready(
function() {
300 <?php printClickOverlayEvent(); ?>
303 <?php PrintPrintAudits(
"all admin");
304 printAuditOpenPopup(); ?>
307 .auditFilterDiv > div {
311 <?php PrintAuditTemplates(
true); ?>
312 <div
id=
"formValidateDiv" class=
"k-block k-error-colored formValidateDiv" style=
"display:none"></div>
313 <div
class=
"container-fluid">
314 <form
id=
"searchForm"><div
class=
"well well-sm container-fluid auditFilterDiv" style=
"display:none;"><div>
315 <div
class=
"col-xs-12 hcuSpacer hcu-no-padding">
316 <div
class=
"container-fluid">
317 <div
class=
"row hcuSpacer"><label
class=
"col-xs-12 col-sm-5">Date Search Range</label>
318 <div
class=
"col-xs-12 col-sm-7"><div
id=
"durationDDL" class=
"hcu-all-100"></div></div>
320 <div
class=
"row hcuSpacer"><label
class=
"col-xs-12 col-sm-5"> </label>
321 <div
class=
"col-xs-12 col-sm-7"><input type=
"text" id=
"startingDatePicker" class=
"hcu-all-100" homecu-match=
"date" data-homecuCustomMatch-msg=
"Date is invalid."></div>
326 <div
class=
"col-xs-12 hcuSpacer hcu-no-padding">
327 <div
class=
"container hcu-all-100">
328 <div
class=
"row hcuSpacer">
329 <label
class=
"col-xs-12 col-sm-5">Changes
for Admin
User</label>
330 <div
class=
"col-xs-12 col-sm-7"><input type=
"text" class=
"k-input k-textbox hcu-all-100" name=
"auditUser"></div>
332 <div
class=
"row hcuSpacer">
333 <label
class=
"col-xs-12 col-sm-5">Changed by Admin
User</label>
334 <div
class=
"col-xs-12 col-sm-7"><input type=
"text" class=
"k-input k-textbox hcu-all-100" name=
"loggedInUser"></div>
336 <div
class=
"row hcuSpacer">
337 <label
class=
"col-sm-5 col-xs-12">Action Type</label>
338 <div
class=
"col-sm-7 col-xs-12"><div
id=
"actionDDL" class=
"hcu-all-100"></div></div>
343 <div
class=
"col-xs-12 hcuSpacer hcu-no-padding"><div
class=
"container hcu-all-100"><div
class=
"row"><div
class=
"col-xs-12">
344 <a href=
"#" class=
"k-button k-primary floatRight" id=
"okayBtn">Show</a>
345 </div></div></div></div>
347 <div
id=
"auditGrid" class=
"hcu-all-100 pointerGrid"></div>
348 <form
id=
"auditPrintForm" method=
"post" action=
"shell.prg" target=
"auditPrint">
349 <input type=
"hidden" name=
"shell" value=
"">
350 <input type=
"hidden" name=
"title" value=
"">
353 <div
id=
"previewWindow"></div>