11 $sharedLibrary = dirname(__FILE__) .
"/../../shared/library";
12 $monLibrary = dirname(__FILE__) .
"/../library";
13 require_once(
"$monLibrary/cu_top.i");
14 require_once(
"$sharedLibrary/commonJsFunctions.i");
15 require_once(
"$monLibrary/ck_hticket.i");
16 require_once(
"$sharedLibrary/reporting.i");
17 require_once(
"$sharedLibrary/cutrusted.i");
19 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
20 header(
"Location: /hcuadm/hcu_noperm.prg");
28 function GetResultsDir () {
29 return "/home/homecu/tmp/billing/";
36 function GetXrcPrefix () {
44 function GetMaxSize () {
52 function GetPageLabel () {
61 return "miPayReport.prg";
68 function GetUsualHeader () {
69 return "Institution ID,FI Name,Subscribers Plus,Subscribers Plus Active,Subscribers Plus Inactive,Enrollments Plus,Total Transactions Plus," 70 .
"Total Electronic Transactions Plus,Total Check Transactions Plus,Subscribers Business,Subscribers Business Active," 71 .
"Subscribers Business Inactive,Enrollments Business,Total Transactions Business,Total Electronic Transactions Business," 72 .
"Total Check Transactions Business,Bus Invoice User,Bus Payroll User,Bus Bundle User,Invoice Count,Payroll Count,Billing Class,P2P Count,NSF Count," 73 .
"Stop Payment Count,Check Copies Count,Compliance Package Annual Fee,MFA Annual Fee,Bill Simple Invoice Only User,Bill Simple Invoice And Pmt User," 74 .
"Bill Simple Count CC,Bill Simple Count ACH,Bill Simple Count NOC RET";
81 function GetFileErrors () {
83 "1" =>
"1: The file you tried to upload is just too big. The allowable limit is 10MB.",
84 "2" =>
"2: The file you tried to upload is just too big. The allowable limit is 10MB.",
85 "3" =>
"3: The file was only partially uploaded",
86 "4" =>
"4: no file was uploaded");
89 $string = array(
"filter" => FILTER_SANITIZE_STRING);
91 $parameters = array();
92 HCU_ImportVars( $parameters,
"", array(
"operation" => $string,
"month" => $string));
95 $operation = isset($operation) ? trim($operation) :
"";
96 $month = isset($month) ? trim($month) :
"";
100 $returnArray = DownloadCSV($month);
103 $returnArray = ViewReport();
106 $returnArray = UploadFile($dbh, $month);
109 PrintPage(GetInitialData (), $homecuKendoVersion, $cloudfrontDomainName);
113 $returnArray = array(
"error" =>
"Operation is not recognized.");
117 header(
'Content-type: application/json');
118 print HCU_JsonEncode($returnArray);
134 function DownloadCSV ($month) {
136 $uploadPath = GetResultsDir ();
137 $fileName = GetXrcPrefix ();
140 throw new exception(
"Please enter a month.", 8);
144 $pregMatch = preg_match(
'/(\d{4})_(\d{2})/', $month, $matches);
148 throw new exception(
"Month is invalid.", 3);
151 if ($matches[2] < 1 || $matches[2] > 12) {
152 throw new exception(
"Month is invalid.", 1);
155 $fileName .=
"_$month.csv";
157 if (!is_writable($uploadPath)) {
158 throw new exception(
"CSV Directory is not set up correctly. Please contact HomeCU for assistance.", 2);
161 $file =
"${uploadPath}${fileName}";
163 if (!file_exists($file)) {
164 throw new exception(
"File doesn't exist.", 4);
167 header(
'Content-Description: File Transfer');
168 header(
'Content-Type: application/octet-stream');
169 header(
'Content-Disposition: attachment; filename="'.basename($file).
'"');
170 header(
'Expires: 0');
171 header(
'Cache-Control: must-revalidate');
172 header(
'Pragma: public');
173 header(
'Content-Length: ' . filesize($file));
177 $returnArray = array(
"status" =>
"000",
"error" =>
"");
179 }
catch (exception $e) {
180 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
189 function ViewReport () {
209 function UploadFile ($dbh, $month) {
211 $fileErrors = GetFileErrors ();
212 $uploadPath = GetResultsDir ();
213 $maxSize = GetMaxSize ();
214 $fileName = GetXrcPrefix ();
217 throw new exception(
"Please enter a month.", 8);
221 $pregMatch = preg_match(
'/(\d{4})_(\d{2})/', $month, $matches);
225 throw new exception(
"Month is invalid.", 3);
228 if ($matches[2] < 1 || $matches[2] > 12) {
229 throw new exception(
"Month is invalid.", 1);
232 $fileName .=
"_$month.csv";
234 if (!is_writable($uploadPath)) {
235 throw new exception(
"CSV Directory is not set up correctly. Please contact HomeCU for assistance.", 2);
238 $file = $_FILES[
'files'];
240 if ($file[
"size"] > $maxSize) {
241 throw new exception(
"File exceeds the max size.", 4);
243 if ($file[
"error"] != 0) {
244 $errorInt = $file[
"error"];
245 throw new exception(HCU_array_key_exists($errorInt, $fileErrors) ? $fileErrors[$errorInt] :
"$errorInt: Unknown error.", 5);
248 $filetmp = $file[
'tmp_name'];
249 if (!@move_uploaded_file($filetmp,
"${uploadPath}${fileName}")) {
251 throw new exception(
"Couldn't post the file where it belongs. Better call HomeCU.", 7);
254 @chmod(
"${uploadPath}${fileName}", 0644);
257 $convertFileReturn = ConvertFile($dbh,
"${uploadPath}${fileName}");
258 if ($convertFileReturn[
"status"] !==
"000") {
259 throw new exception($convertFileReturn[
"error"], 9);
262 $returnArray = array(
"status" =>
"000",
"error" =>
"");
263 }
catch(exception $e) {
264 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
278 function ConvertFile($dbh, $fileName) {
280 if (!@copy($fileName,
"$fileName.tmp")) {
281 throw new exception(
"File could not be copied.", 1);
284 $readFP = fopen(
"$fileName.tmp",
"r");
290 while (($buffer = fgets($readFP)) !==
false) {
291 if (!preg_match(
'/[^,\s]/', $buffer)) {
295 if (strpos($buffer,
"Reseller Report") !==
false) {
299 if (!isset($header)) {
301 $header = str_getcsv($buffer);
302 $headerCount = count($header);
304 $buffer = str_getcsv($buffer);
306 if (count($buffer) != $headerCount) {
307 throw new exception(
"File is invalid.", 3);
310 $csvLines [trim($buffer[0])] = $buffer;
317 $sql =
"select user_name, name from cuinfo";
318 $sth = db_query($sql, $dbh);
320 throw new exception(
"orgname query failed.", 4);
322 $cuResults = db_fetch_all($sth);
323 $cuResults = $cuResults ===
false ? array() : $cuResults;
325 $results = GetCuLookup($dbh);
326 if ($results[
"status"] !==
"000") {
327 throw new exception (
"Cu Lookup failed.", 5);
329 $cuMap = $results[
"cuMap"];
330 $institutionMap = array();
332 foreach ($cuResults as $cuResult) {
333 $cu = trim(strtoupper($cuResult[
"user_name"]));
334 if (HCU_array_key_exists($cu, $cuMap) && $cuMap[$cu] !=
"") {
335 $institutionMap[$cuMap[$cu]] = array(
"cu" => $cu,
"orgname" => $cuResult[
"name"]);
339 $header [0] =
"CU Code";
340 $header [1] =
"CU Name";
342 $writeFP = fopen($fileName,
"w");
343 fputcsv ($writeFP, $header);
345 foreach ($csvLines as $institutionId => $line) {
346 if (HCU_array_key_exists($institutionId, $institutionMap)) {
347 $correction = $institutionMap[$institutionId];
348 $line [0] = $correction [
"cu"];
349 $line [1] = $correction [
"orgname"];
352 $line [1] =
"Error: Need Lookup for $institutionId";
355 fputcsv ($writeFP, $line);
361 @unlink(
"$fileName.tmp");
363 $returnArray = array(
"status" =>
"000",
"error" =>
"");
364 }
catch (exception $e) {
365 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
370 function GetCuLookup($dbh) {
373 $parameters = array(
"report" =>
"ipayLookup",
"showServer" =>
"Y",
"showDuplicates" =>
"Y",
"limit" =>
"-1",
"offset" =>
"0");
375 $mammothList = array(
"www3",
"www5",
"www6");
377 foreach($mammothList as $server) {
378 $cmd =
"https://${server}.homecu.net/hcuadm/adm_reports?operation=readReport";
379 $results = HCU_JsonDecode(RunCurl($parameters, $cmd,
false));
380 if (count($results) == 0) {
381 throw new exception (
"$server has no results.", 1);
383 if (count($results[
"error"]) > 0) {
384 throw new exception (
"$server threw: " . $results[
"error"][0], 2);
386 $dataList[$server] = $results[
"reportData"][
"data"];
389 $sql =
"select cu, trustedid, parms from cutrusteddetail where substr(lower(trim(trustedid)), 1, 4) = 'ipay'";
390 $sth = db_query($sql, $dbh);
392 throw new exception (
"Select query failed.", 3);
394 $results = db_fetch_all($sth);
395 $results = $results ===
false ? array() : $results;
397 $dataList[
"my"] = $results;
401 foreach ($dataList as $server => $serverData) {
402 foreach($serverData as $record) {
403 $cu = trim($record[
"cu"]);
404 $masterKey = sha1(
"${cu}:3pk4osso");
407 $decrypted = parmdecrypt($record[
"parms"], $masterKey);
408 }
catch (exception $e) {
410 $logger->error(
"iPay Report failed encryption for $cu.");
414 $detailArray = HCU_JsonDecode(parmdecrypt($record[
"parms"], $masterKey));
416 if (isset($detailArray) && HCU_array_key_exists(
"bp_cuid", $detailArray)) {
417 if (!HCU_array_key_exists($cu, $cuMap)) {
418 $cuMap[$cu] = array();
420 $cuMap[$cu][$server] = trim($detailArray[
"bp_cuid"]);
424 if (isset($detailArray) && HCU_array_key_exists(
"ipay_instid", $detailArray)) {
425 if (!HCU_array_key_exists($cu, $cuMap)) {
426 $cuMap[$cu] = array();
428 $cuMap[$cu][$server] = trim($detailArray[
"ipay_instid"]);
433 foreach ($cuMap as $cu => $cuRecord) {
434 if (HCU_array_key_exists(
"my", $cuRecord)) {
435 $cuMap[$cu] = $cuRecord[
"my"];
436 }
else if (HCU_array_key_exists(
"www3", $cuRecord)) {
437 $cuMap[$cu] = $cuRecord[
"www3"];
438 }
else if (HCU_array_key_exists(
"www6", $cuRecord)) {
439 $cuMap[$cu] = $cuRecord[
"www6"];
440 }
else if (HCU_array_key_exists(
"www5", $cuRecord)) {
441 $cuMap[$cu] = $cuRecord[
"www5"];
447 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"cuMap" => $cuMap);
449 }
catch (exception $e) {
450 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
461 function GetInitialData () {
463 $uploadPath = GetResultsDir ();
464 $filePrefix = GetXrcPrefix ();
465 $filePrefixLength = strlen($filePrefix);
467 if (!is_writable($uploadPath)) {
468 if (!mkdir($uploadPath)) {
469 throw new exception(
"CSV Directory is not set up correctly. Please contact HomeCU for assistance.", 2);
473 $fileList = scandir ($uploadPath);
476 foreach ($fileList as $file) {
477 if (strncmp($file, $filePrefix, $filePrefixLength) == 0) {
478 $month = str_replace(
".csv",
"", str_replace(
"${filePrefix}_",
"", $file));
479 $fileSize = floatval(@filesize(
"${uploadPath}${file}"));
481 if ($fileSize < 1024) {
482 $fileSize =
"$fileSize B";
483 }
else if ($fileSize < 1024*1024) {
484 $fileSize = ($fileSize / 1024.0) .
" KB";
485 }
else if ($fileSize < 1024*1024*1024) {
486 $fileSize = ($fileSize / (1024.0*1024)) .
" MB";
488 $fileSize = ($fileSize / (1024.0*1024*1024)) .
" GB";
490 $monthMap [$month] = $fileSize;
494 $returnArray = array(
"status" =>
"000",
"error" =>
"",
"data" => $monthMap);
495 }
catch (exception $e) {
496 $returnArray = array(
"status" => $e->getCode(),
"error" => $e->getMessage());
509 function PrintPage ($initialData, $homecuKendoVersion, $cloudfrontDomainName) {
510 $pageLabel = GetPageLabel ();
512 $maxSize = GetMaxSize ();
514 printMonitorPageTop ($pageLabel, $homecuKendoVersion, $cloudfrontDomainName);
515 printMonitorPageMiddle ($pageLabel);
521 <script type=
"text/javascript">
523 getShowWaitFunctions (); ?>
533 function OpenAuthFailedDialog(response) {
534 var authFailedDialog = $(
"#authFailedDialog").data(
"kendoWindow");
535 if (authFailedDialog !=
null) {
536 authFailedDialog.destroy();
537 $(
"#authFailedDialog").empty();
540 authFailedDialog = $(
"#authFailedDialog").kendoWindow({
541 content: {
template: response.replace(/[#]/g,
"\\#")}, <?php
549 }).data(
"kendoWindow");
551 authFailedDialog.open().center();
562 $.homecuValidator.setup({formValidate:
'uploadForm', formStatusField:
'statusDiv'});
564 var initialData = <?php echo HCU_JsonEncode($initialData); ?>;
565 if (initialData.status !==
"000") {
566 $.homecuValidator.displayMessage(initialData.error, $.homecuValidator.settings.statusError );
574 var uploader = $(
"#uploader").kendoUpload({
576 saveUrl:
"<?php echo $self; ?>?operation=uploadFile",
577 withCredentials:
true,
584 var response = e.XMLHttpRequest.responseText;
586 if (response.indexOf(
"PDFUploadFirstErrorLi") != -1) {
587 $.homecuValidator.displayMessage(response, $.homecuValidator.settings.statusError );
589 openAuthFailedDialog(response);
591 $(
".k-upload-files").
remove();
593 success:
function(e) {
595 if (e.response.status ===
"000") {
596 $.homecuValidator.validate();
597 $(
"#fileExists").hide();
598 $(
"#monthDatePicker").data(
"kendoDatePicker").value(
null);
600 $.homecuValidator.displayMessage(e.response.error, $.homecuValidator.settings.statusError );
606 select:
function(e) { <?php
608 var file = e.files[0];
609 file.extension.toLowerCase() !=
".csv" ? error.push (
"File needs to be a CSV.") :
null;
610 file.size > <?php echo $maxSize; ?> ? error.push (
"File exceeds the max size.") :
null;
612 if (error.length > 0) {
613 $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError );
618 upload:
function(e) {
619 var month = $(
"#monthDatePicker").data(
"kendoDatePicker").value();
620 var month = month ==
null ?
"" : kendo.toString(month,
"yyyy_MM");
621 e.data = {month: month};
625 select:
"Select File" 627 }).data(
"kendoUpload");
629 var monthDatePicker = $(
"#monthDatePicker").kendoDatePicker({
633 parseFormats: [
"yyyy_MM"],
635 var month = this.value();
636 month = kendo.toString(month,
"yyyy_MM");
637 if (initialData.data[month] !=
null) {
638 $(
"#fileExists .size").text(initialData.data[month]);
639 $(
"#fileExists").show();
641 $(
"#fileExists").hide();
644 }).data(
"kendoDatePicker");
646 $(
"#uploadBtn").click(
function() {
650 var month = $(
"#monthDatePicker").data(
"kendoDatePicker").value();
651 month ==
null ? error.push (
"Please select a month.") :
null;
652 $(
"#uploadForm .k-upload-files .k-file:visible").length == 0 ? error.push (
"Please select a file.") :
null;
654 error.length > 0 ? $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError ) : $(
"#uploadForm .k-button.k-upload-selected").click();
658 $(document).ready(
function() {
681 #uploadForm .k-clear-selected, #uploadForm .k-upload-selected, #uploadForm .k-upload-status { 690 <script
id=
"popupTemplateDetail" type=
"text/x-kendo-template">
695 <div
class=
"container_12">
696 <div
class=
"grid_12" id=
"statusDiv"></div>
702 <div
id=
"uploadForm">
703 <div
class=
"grid_12"><input type=
"file" name=
"files" id=
"uploader" accept=
".csv" /></div>
704 <div
class=
"grid_12">
705 <div
class=
"grid_3 alpha">
709 <input
id=
"monthDatePicker">
711 <div
class=
"grid_5 omega">
712 <h6
id=
"fileExists" style=
"display:none">File exists with a size of <span
class=
"size"></span>.</h6>
715 <div
class=
"grid_12">
716 <a
class=
"k-button k-primary" id=
"uploadBtn">Upload File</a>
726 <?php printMonitorPageBottom(); ?>