Visolve: Clear Active Patient Changes
[openemr.git] / library / edihistory / ibr_io.php
blob3ed076def0b50732fa670618e9273cf6fdd3aef3
1 <?php
2 /*
3 * ibr_io.php
4 *
5 * Copyright 2012 Kevin McCormick Longview, Texas
6 *
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 3 or later. You should have
16 * received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * <http://opensource.org/licenses/gpl-license.php>
22 * @author Kevin McCormick
23 * @link: http://www.open-emr.org
24 * @package OpenEMR
25 * @subpackage ediHistory
28 /**
29 * Get some values from php ini functions for interface
31 * @return array json
33 function ibr_inivals() {
34 $ival = array();
35 $td = basename(sys_get_temp_dir());
36 $ival['mfilesize'] = ini_get('upload_max_filesize');
37 $ival['mfuploads'] = ini_get('max_file_uploads');
38 $ival['pmsize'] = ini_get('post_max_size');
39 $ival['tmpdir'] = $td;
40 $json = json_encode($ival);
42 return $json;
45 /**
46 * read or write simple notes to a text file
48 * @uses csv_notes_file()
49 * @return string
51 function ibr_history_notes() {
53 if (isset($_GET['getnotes']) && $_GET['getnotes'] == 'yes') {
54 $out_text = csv_notes_file();
55 $str_html = str_replace('|:|', PHP_EOL, $out_text);
56 } elseif (isset($_POST['putnotes']) && $_POST['putnotes'] == 'yes') {
57 $notetext = $_POST['tnotes'];
58 $notetext = str_replace(PHP_EOL, '|:|', $notetext);
59 $filtered = filter_var($notetext, FILTER_SANITIZE_STRING);
60 //echo $filtered .PHP_EOL;
61 $str_html = csv_notes_file($filtered, false);
63 return $str_html;
66 /**
67 * generate the heading string for an html page
69 * @return string html heading stanza
71 function ibr_html_heading($option, $title='') {
73 //if (!is_string($title)) { $title=''; }
74 $title = (is_string($title)) ? $title : '';
75 //$srcdir = $GLOBALS['srcdir'];
76 $webdir = $GLOBALS['webroot'];
78 $str_html = "<!DOCTYPE html>".PHP_EOL."<html>".PHP_EOL."<head>".PHP_EOL;
79 $str_html .= " <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />".PHP_EOL;
80 $str_html .= " <title>##TITLE##</title>".PHP_EOL;
81 //$str_html .= " <link rel='stylesheet' href='jscript/style/csv_new.css' type='text/css' media='print, projection, screen' />".PHP_EOL;
82 $str_html .= "<link rel=\"stylesheet\" href=\"$webdir/library/css/edi_history.css\" type=\"text/css\" />".PHP_EOL;
83 //$str_html .= " <link rel='stylesheet' href='../css/edi_history.css' type='text/css' />".PHP_EOL;
84 $str_html .= "</head>".PHP_EOL."<body>".PHP_EOL;
86 if (!strpos("|newfiles|eradisplay|x12display|csvtable|textdisplay|readme", $option)) {
87 $str_html = str_replace('##TITLE##', 'Error', $str_html);
88 return $str_html;
89 } elseif ($option == 'newfiles') {
90 $str_html = str_replace('##TITLE##', 'Process New Files '.$title, $str_html);
91 } elseif ($option == 'eradisplay') {
92 $str_html = str_replace('##TITLE##', 'ERA Display '.$title, $str_html);
93 } elseif ($option == 'claimstatus') {
94 $str_html = str_replace('##TITLE##', 'Claim Status '.$title, $str_html);
95 } elseif ($option == 'x12display') {
96 $str_html = str_replace('##TITLE##', 'x12 File '.$title, $str_html);
97 } elseif ($option == 'csvtable') {
98 $str_html = str_replace('##TITLE##', 'CSV Table '.$title, $str_html);
99 } elseif ($option == 'textdisplay') {
100 $str_html = str_replace('##TITLE##', 'Text '.$title, $str_html);
101 } elseif ($option == 'readme') {
102 $str_html = str_replace('##TITLE##', 'Readme '.$title, $str_html);
103 } else {
104 $str_html = str_replace('##TITLE##', 'Unknown '.$title, $str_html);
107 return $str_html;
111 * generate the trailing tags for html page
113 * @return string
115 function ibr_html_tail() {
116 $str_html = PHP_EOL."</body></html>";
117 return $str_html;
121 * call new uploaded files process functions
123 * @todo save the newfiles lists to file so they can
124 * be re-displayed if user has to close app before
125 * finishing review (need to have csv_write option)
127 * @uses csv_newfile_list()
128 * @uses ibr_batch_process_new()
129 * @uses ibr_ack_process_new()
130 * @uses ibr_997_process_new()
131 * @uses ibr_277_process_new()
132 * @uses ibr_ebr_process_new()
133 * @uses ibr_dpr_process_new()
134 * @uses ibr_era_process_new()
136 * @return string html format
138 function ibr_disp_newfiles() {
140 if (!isset($_POST['NewFiles']) ) {
141 // should only be called with this value existing
142 $str_html = "Error: invalid value for Process New <br />".PHP_EOL;
143 return $str_html;
145 $htm = $er = false;
146 if (isset($_POST['htmlout'])) {
147 $htmval = filter_input(INPUT_POST, 'htmlout', FILTER_SANITIZE_STRING);
148 $htm = ($htmval == 'on') ? true : false;
150 if (isset($_POST['erronly'])) {
151 $errval = filter_input(INPUT_POST, 'erronly', FILTER_SANITIZE_STRING);
152 $er = ($errval == 'on') ? true : false;
154 $str_html = "<p>Process new files</p>".PHP_EOL;
156 $p = csv_parameters();
157 $ftype = array_keys($p);
159 foreach($ftype as $tp) {
160 $checkdir = false;
161 // check for directory contents
162 $ckdir = $p[$tp]['directory'];
163 if (is_dir($ckdir)) {
164 $dh = opendir($ckdir);
165 if ($dh) {
166 while (($file = readdir($dh)) !== false) {
167 if ($file != '.' && $file != '..') {
168 $checkdir = true;
169 break;
172 closedir($dh);
175 // if false, no files in directory
176 if (!$checkdir) { continue; }
178 $upload_ar = csv_newfile_list($tp);
180 if (count($upload_ar) > 0) {
181 if ($tp == 'batch') {
182 $str_html .= ibr_batch_process_new($upload_ar, $htm);
183 } elseif ($tp == 'ack') {
184 $str_html .= ibr_ack_process_new($upload_ar, $htm);
185 } elseif ($tp == 'ta1') {
186 $str_html .= ibr_ta1_process_new($upload_ar, $htm);
187 } elseif ($tp == 'f997') {
188 $str_html .= ibr_997_process_new($upload_ar, $htm, $er);
189 } elseif ($tp == 'f277') {
190 $str_html .= ibr_277_process_new($upload_ar, $htm, $er);
191 } elseif ($tp == 'ibr') {
192 $str_html .= ibr_ebr_process_new_files($upload_ar, 'ibr', $htm, $er);
193 } elseif ($tp == 'ebr') {
194 $str_html .= ibr_ebr_process_new_files($upload_ar, 'ebr', $htm, $er);
195 } elseif ($tp == 'dpr') {
196 $str_html .= ibr_dpr_process_new($upload_ar, $htm, $er);
197 } elseif ($tp == 'era') {
198 $str_html .= ibr_era_process_new($upload_ar, $htm, $er);
199 } elseif ($tp == 'text') {
200 // do nothing
201 continue;
202 } else {
203 $str_html .= "unknown type $tp <br />".PHP_EOL;
205 } else {
206 $str_html .= "No new files for type $tp <br />".PHP_EOL;
210 return $str_html;
214 * display the ST...SE segments for a claim from a batch file
216 * @uses csv_file_with_pid_enctr()
217 * @uses csv_file_by_controlnum()
218 * @uses ibr_batch_get_st_block()
219 * @return string
221 function ibr_disp_claimst() {
223 $str_html = '';
224 $filename = ''; $clmid = ''; $st02 = '';
226 $filename = isset($_GET['fvbatch']) ? filter_input(INPUT_GET, 'fvbatch', FILTER_SANITIZE_STRING) : '';
228 $st02 = isset($_GET['stnum']) ? filter_input(INPUT_GET, 'stnum', FILTER_SANITIZE_STRING) : '';
230 if (isset($_GET['btpid'])) {
231 $clmid = filter_input(INPUT_GET, 'btpid', FILTER_SANITIZE_STRING);
232 } elseif (isset($_POST['enctrbatch'])) {
233 $clmid = filter_input(INPUT_POST, 'enctrbatch', FILTER_SANITIZE_STRING);
234 } else {
235 $clmid = '';
238 if ( !$clmid && !$st02 ) {
239 $str_html .= "Invalid claim ID <br />";
240 return $str_html;
242 // see if we have a usable filename
243 if (strpos($filename, 'batch')) {
244 // maybe we have the OpenEMR filename
245 $btname = trim($filename);
246 } elseif (strlen($filename) >= 9 && strlen($filename) < 14) {
247 // try bht03 number: batch_icn + stnum; not '0123'
248 $isa13 = substr($filename, 0, 9);
249 $st02 = (strlen($filename) == 13) ? substr($filename, -4) : '';
250 $btname = csv_file_by_controlnum('batch', $isa13);
251 } elseif (!$filename || strlen($filename) < 9) {
252 // nothing useful
253 $btname = '';
256 if ($btname) {
257 $stblk = ibr_batch_get_st_block ($btname, $st02, $clmid);
258 if ($stblk) {
259 $str_html .= $stblk;
260 } else {
261 $btname = '';
264 if (!$btname) {
265 // search for file with the claim id
266 $enc_ar = csv_file_with_pid_enctr($clmid, 'batch', 'ptctln');
267 // (encounter, number, filename,)
268 if (is_array($enc_ar) && count($enc_ar) ) {
269 if (count($enc_ar) > 1) {
270 $str_html .= '<p>Found '. count($enc_ar) . ' instances</p>'.PHP_EOL;
271 // hopefully, only _GET 277 related queries will lack the filename
272 $str_html .= (isset($_POST['enctrbatch'])) ? '' : '<p>May not match to status response</p>'.PHP_EOL;
274 foreach($enc_ar as $enc) {
275 $str_html .= ibr_batch_get_st_block ( $enc[2], $enc[1] );
277 } elseif( is_string($enc_ar) && count($enc_ar) ) {
278 $str_html .= $enc_ar;
279 } else {
280 $str_html .= "Failed to find the batch file for $clmid <br />";
284 return $str_html;
288 * display the x12 segments for an era claim remittance advice
290 * @uses csv_file_with_pid_enctr()
291 * @uses ibr_era_get_clp_text()
292 * @return string
294 function ibr_disp_eraClp() {
295 // get the clp and related segments
296 $str_html = '';
297 $era_enc = filter_input(INPUT_POST, 'enctrEra', FILTER_SANITIZE_STRING);
298 $enc_ar = ($era_enc) ? csv_file_with_pid_enctr($era_enc, 'era', 'encounter') : false;
299 // $enc_ar is an array [i](pid, encounter, filename)
300 if (is_array($enc_ar) && count($enc_ar) ) {
301 foreach($enc_ar as $enc) {
302 //$pe = $enc[0] . "-" . $enc[1];
303 $pe = $enc[0];
304 $str_html .= ibr_era_get_clp_text($pe, $enc[2]);
306 } elseif( count($enc_ar) && is_string($enc_ar) ) {
307 $str_html .= $enc_ar;
308 } else {
309 $str_html .= "Failed to find the remittance for encounter ". strval($era_enc) ."<br />".PHP_EOL;
311 return $str_html;
315 * csv tables filter input and generate table
317 * @uses csv_to_html()
318 * @return string
320 function ibr_disp_csvtable() {
322 $rowp = filter_input(INPUT_POST, 'csvpctrows', FILTER_VALIDATE_INT);
323 $ds = filter_input(INPUT_POST, 'csv_date_start', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
324 $de = filter_input(INPUT_POST, 'csv_date_end', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
325 $csvfile = filter_input(INPUT_POST, 'csvtables', FILTER_SANITIZE_STRING);
327 $row_pct = ($rowp) ? $rowp/100 : 1;
328 if ($ds == NULL || $ds === FALSE ) { $ds = ''; }
329 if ($de == NULL) { $de = ($ds) ? date("Y/M/D", time()) : ''; }
330 if ($csvfile == NULL || $csvfile === FALSE ) {
331 // here we have an error and must quit
332 $str_html= "<p>Error in CSV table name </p>".PHP_EOL;
333 return $str_html;
334 } else {
335 $tp_ar = explode('_', $csvfile);
336 $tbl_type = ($tp_ar[0] == 'claims') ? 'claim' : 'file';
337 $f_type = strval($tp_ar[1]);
338 if ($f_type == '999' || $f_type == '997' || $f_type == '277') {
339 $f_type = 'f'.$f_type;
342 $str_html = csv_to_html($f_type, $tbl_type, $row_pct, $ds, $de);
344 return $str_html;
348 * links for RA info from POST for trace, patient ID, or encounter
350 * @uses csv_file_by_controlnum(
351 * @uses csv_file_with_pid_enctr()
352 * @uses ibr_era_html_page()
353 * @return string
355 function ibr_disp_era_post() {
357 $str_html = '';
358 // POST request from ERA tab -- era by pid, encounter, or trace
359 // there will not be a filename supplied with these values
360 $trace = ''; $pid = ''; $enctr = ''; $search = '';
361 //ibr_era_html_page ( $file_path, $trn_trace=0, $pid_enctr=0, $searchtype='ALL', $fname='835 Remittance Advice')
362 if ( isset($_POST['subtrace835']) && isset($_POST['trace835']) && $_POST['trace835'] ) {
363 $istrc = true;
364 $search = 'trace';
365 $trace = filter_input(INPUT_POST, 'trace835', FILTER_SANITIZE_STRING);
366 $eft = csv_file_by_controlnum('era', $trace);
367 if ($eft) {
368 $str_html .= ibr_era_html_page($eft, $trace, 0, $search, $eft);
369 } else {
370 $str_html .= "Did not find $trace in data <br />".PHP_EOL;
372 } elseif ( isset($_POST['subpid835']) && isset($_POST['pid835']) && $_POST['pid835']) {
373 $ispid = true; $isenc = false;
374 $search = 'pid';
375 $pid = filter_input(INPUT_POST, 'pid835', FILTER_SANITIZE_STRING);
376 $ef = ($pid) ? csv_file_with_pid_enctr ($pid, 'era', 'pid') : false;
377 } elseif (isset($_POST['subenctr835']) && isset($_POST['enctr835']) && $_POST['enctr835'] ) {
378 $isenc = true; $ispid = false;
379 $search = 'encounter';
380 $enctr = filter_input(INPUT_POST, 'enctr835', FILTER_SANITIZE_STRING);
381 $ef = ($enctr) ? csv_file_with_pid_enctr ($enctr, 'era', 'encounter') : false;
384 if ($isenc || $ispid) {
385 if ( is_array($ef) && count($ef) ) {
386 $fn = array();
387 foreach($ef as $val) {
388 // do not repeat filename since all occurences in a file are found
389 if ( in_array($val[2], $fn) ) {
390 continue;
391 } else {
392 $fn[] = $val[2];
393 $str_html .= ibr_era_html_page($val[2], 0, $val[0], $search, $val[2]);
396 } else {
397 $str_html .= "Did not find $pid $enctr in data <br />".PHP_EOL;
401 return $str_html;
406 * links for RA info from GET for patient ID or encounter
408 * @uses csv_file_with_pid_enctr()
409 * @uses ibr_era_claim_summary()
410 * @uses ibr_era_html_page()
411 * @return string
413 function ibr_disp_era_get() {
415 $str_html = '';
417 // all these should open in a new window or tab (target='_blank') except summary
418 $fname = isset($_GET['erafn']) ? filter_input(INPUT_GET, 'erafn', FILTER_SANITIZE_STRING) : '';
419 $pe = isset($_GET['pidenc']) ? filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING) : '';
420 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_SANITIZE_STRING) : '';
421 $stype = isset($_GET['srchtp']) ? filter_input(INPUT_GET, 'srchtp', FILTER_SANITIZE_STRING) : '';
422 $smy = isset($_GET['summary']) ? filter_input(INPUT_GET, 'summary', FILTER_SANITIZE_STRING) : '';
424 if (!$fname && $pe && $stype=='encounter') {
425 // all RA's for this encounter
426 $ef = csv_file_with_pid_enctr($pe, 'era', $stype);
427 if (is_array($ef) && count($ef) ) {
428 foreach($ef as $val) {
429 // -- do not repeat filename since all occurences in a file are found
430 // (pid-enctr, trace, filename)
431 if ( in_array($val[2], $fn) ) {
432 continue;
433 } else {
434 $fn[] = $val[2];
435 $pe = $val[0];
436 $str_html .= ibr_era_html_page($val[2], 0, $pe, 'encounter', $val[2]);
439 } else {
440 $str_html .= "Did not find $pe in data <br />".PHP_EOL;
442 } elseif (!$fname && $trace) {
443 $fname = csv_file_by_controlnum('era', $trace);
444 if ($fname) {
445 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
446 } else {
447 $str_html .= "Did not find file for trace $trace <br />".PHP_EOL;
449 } elseif ($fname && $pe && $smy=='yes') {
450 // payment summary for popup dialog
451 $str_html .= ibr_era_claim_summary($fname, $pe);
452 } elseif ($fname && $pe && !$smy) {
453 // all RA's for this patient ID in transaction
454 $str_html .= ibr_era_html_page($fname, 0, $pe, 'encounter', $fname);
455 } elseif ($fname && $trace) {
456 // RA for this trace number
457 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
460 return $str_html;
463 function ibr_disp_clmhist() {
465 if (isset($_GET['chenctr']) && strlen($_GET['chenctr'])) {
466 $pe = filter_input(INPUT_GET, 'chenctr', FILTER_SANITIZE_STRING);
467 $str_html = csv_claim_history($pe);
468 } else {
469 $str_html = "Error in processing request.<br />".PHP_EOL;
471 return $str_html;
475 * filter input and generate display for claim status response
477 * @uses ibr_277_response_html()
478 * @return string
480 function ibr_disp_status_resp() {
482 $fname = filter_input(INPUT_GET, 'rspfile', FILTER_SANITIZE_STRING);
483 $st = ''; $pe = '';
484 if (isset($_GET['pidenc']) && strlen($_GET['pidenc'])) {
485 $pe = filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING);
487 if (isset($_GET['rspstnum']) && strpos($_GET['rspstnum'], '_')) {
488 // the rspstnum is the 277 ISA13_ST02
489 $st = filter_input(INPUT_GET, 'rspstnum', FILTER_SANITIZE_STRING);
492 if (!$pe && !$st) {
493 $str_html = "No claim identification information for claim status.<br />".PHP_EOL;
494 } else {
495 $str_html = ibr_277_response_html($fname, '', '', $pe, $st);
497 return $str_html;
501 * display the message part of a DPR response
503 * @uses ibr_dpr_message()
504 * @return string
506 function ibr_disp_dpr_message() {
508 $fname = filter_input(INPUT_GET, 'dprfile', FILTER_SANITIZE_STRING);
509 if (isset($_GET['dprclm']) && strlen($_GET['dprclm'])) {
510 $pe = filter_input(INPUT_GET, 'dprclm', FILTER_SANITIZE_STRING);
512 if (!$fname || !$pe) {
513 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
514 } else {
515 $str_html = ibr_dpr_message($fname, $pe);
517 return $str_html;
521 * display the message part of a EBR or IBR response
523 * @uses ibr_ebr_message()
524 * @return string
526 function ibr_disp_ebr_message() {
528 $fname = ''; $pe = ''; $btfnm = '';
529 $fname = filter_input(INPUT_GET, 'ebrfile', FILTER_SANITIZE_STRING);
530 if (isset($_GET['ebrclm']) && strlen($_GET['ebrclm'])) {
531 $pe = filter_input(INPUT_GET, 'ebrclm', FILTER_SANITIZE_STRING);
533 if (isset($_GET['batchfile']) && strlen($_GET['batchfile'])) {
534 $btfnm = filter_input(INPUT_GET, 'batchfile', FILTER_SANITIZE_STRING);
536 if (!$fname || !$pe) {
537 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
538 } else {
539 $str_html = ibr_ebr_message($fname, $pe, $btfnm);
541 return $str_html;
545 * display the message part of a 999 response
547 * @uses ibr_997_errscan()
548 * @return string
550 function ibr_disp_997_message() {
552 $fname = ''; $akval = ''; $errval = '';
553 $fname = filter_input(INPUT_GET, 'fv997', FILTER_SANITIZE_STRING);
554 if (isset($_GET['aknum'])) { $akval = filter_input(INPUT_GET, 'aknum', FILTER_SANITIZE_STRING); }
555 if (isset($_GET['err997'])) { $errval = filter_input(INPUT_GET, 'err997', FILTER_SANITIZE_STRING); }
556 if (!$fname) {
557 $str_html = "Missing file name.<br />".PHP_EOL;
558 } else {
559 $str_html = ibr_997_errscan($fname, $akval);
561 return $str_html;
565 * display the message part of a ACK or TA1 response
567 * @uses ibr_ack_error()
568 * @return string
570 function ibr_disp_ta1_message() {
572 $fname = ''; $code = '';
573 $fname = filter_input(INPUT_GET, 'ackfile', FILTER_SANITIZE_STRING);
574 if (isset($_GET['ackcode'])) $code = filter_input(INPUT_GET, 'ackcode', FILTER_SANITIZE_STRING);
575 if ($fname && $code) {
576 $str_html = ibr_ack_error($fname, $code);
577 } else {
578 $str_html = 'Code value invalid <br />'.PHP_EOL;
580 return $str_html;
585 * filter input and display local era file
587 * @uses ibr_upload_files()
588 * @uses ibr_era_html_page()
589 * @return string
591 function ibr_disp_erafileUpl() {
592 // file uploads; single file controls
593 $str_html = '';
595 if ( count($_FILES) ) {
596 $f_array = ibr_upload_files($str_html);
597 if ( is_array($f_array) && count($f_array) ) {
598 $f_name = basename($f_array['era'][0]);
599 $str_html .= ibr_era_html_page($f_array['era'][0], 0, 0, 0, $f_name);
600 } else {
601 $str_html .= "no files accepted <br />" . PHP_EOL;
603 } else {
604 $str_html .= "no file submitted <br />" . PHP_EOL;
606 return $str_html;
610 * uploading of new files
612 * @uses ibr_upload_files()
613 * @uses ibr_sort_upload()
614 * @return string
616 function ibr_disp_fileMulti() {
617 // multiple file upload
618 $str_html = '';
619 if ( count($_FILES) ) {
620 $f_array = ibr_upload_files($str_html);
621 if ( is_array($f_array) && count($f_array) ) {
622 $str_html .= "sending ".count($f_array)." type for sorting <br />" .PHP_EOL;
623 $str_html .= ibr_sort_upload($f_array, $htm, $er);
624 } else {
625 $str_html .= "no files accepted <br />".PHP_EOL;
627 } else {
628 $str_html .= "no files submitted <br />" . PHP_EOL;
630 $str_html .= PHP_EOL."<form>".PHP_EOL;
631 $str_html .= "<input type='button' id='closepopup' value='Close' onclick='self.close()'>".PHP_EOL;
632 $str_html .= "</form>".PHP_EOL;
634 return $str_html;
639 * filter input and generate display of x12 file
641 * @uses csv_filetohtml()
642 * @uses ibr_upload_files()
643 * @uses ibr_ebr_ebt_name()
644 * @return string
646 function ibr_disp_fileText() {
648 $str_html = '';
649 //isset($_POST['fileX12']) && isset($_FILES['fileUplx12'])
650 if ( count($_FILES) && isset($_FILES['fileUplx12']) ) {
651 $fn = htmlentities($_FILES['fileUplx12']['name']);
652 $str_html = ibr_html_heading('newfiles', $fn);
653 $f_array = ibr_upload_files($str_html);
654 if ( is_array($f_array) && count($f_array) ) {
655 $str_html .= csv_filetohtml($f_array);
656 } else {
657 $str_html = ibr_html_heading('error');
658 $str_html .= "no files accepted <br />" . PHP_EOL;
660 } elseif ( isset($_GET['fvkey']) ) {
661 $fn = filter_input(INPUT_GET, 'fvkey', FILTER_SANITIZE_STRING);
662 // Availity 'readable' versions ibr, ebr, dpr
663 $ishr = (isset($_GET['readable']) && $_GET['readable']=='yes') ? true : false;
664 if (!$fn) {
665 $str_html = ibr_html_heading('error');
666 } elseif ($ishr && $fn) {
667 $ftxt = ibr_ebr_ebt_name($fn);
668 $str_html = ibr_html_heading('textdisplay', $ftxt);
669 $str_html .= csv_filetohtml($ftxt);
670 } else {
671 $bn = basename($fn);
672 $str_html = ibr_html_heading('textdisplay', $bn);
673 $str_html .= csv_filetohtml($fn);
675 } elseif (isset($_GET['btctln']) ) {
676 $btisa13 = filter_input(INPUT_GET, 'btctln', FILTER_SANITIZE_STRING);
677 if ($btisa13) {
678 //$btname = ibr_batch_find_file_with_controlnum($btisa13);
679 $btname = csv_file_by_controlnum('batch', $btisa13);
680 $str_html = ibr_html_heading('textdisplay', $btname);
681 if ($btname) {
682 $str_html .= csv_filetohtml($btname);
683 } else {
684 $str_html .= "Failed to identify file with control number $btisa13 <br />".PHP_EOL;
686 } else {
687 $str_html .= "error in file display <br />";
689 } else {
690 $str_html = ibr_html_heading('error');
691 $str_html .= "error in file display <br />";
693 return $str_html;
697 * check if the batch control number is found in the 997/999 files table
699 * @uses csv_search_record()
700 * @return string
702 function ibr_disp_997_for_batch() {
703 $str_html = '';
704 $batch_icn = filter_input(INPUT_GET, 'batchicn', FILTER_SANITIZE_STRING);
705 if ($batch_icn) {
706 $ctln = (strlen($batch_icn) >= 9) ? substr($batch_icn, 0, 9) : trim(strval($batch_icn));
707 $search = array('s_val'=>$ctln, 's_col'=>3, 'r_cols'=>'all');
708 $result = csv_search_record('f997', 'file', $search, "1");
710 // should be matching row(s) from files_997.csv
711 if (is_array($result) && count($result)) {
712 $str_html .= "<p>Acknowledgement information</p>".PHP_EOL;
713 foreach($result as $rslt) {
714 $ext = substr($rslt[1], -3);
716 $str_html .= "Date: {$rslt[0]} <br />".PHP_EOL;
717 $str_html .= "File: <a target=\"blank\" href=edi_history_main.php?fvkey={$rslt[1]}>{$rslt[1]}</a> <br />".PHP_EOL;
718 $str_html .= "Batch ICN: {$rslt[3]} <br />";
719 // error count or code in position 4
720 if ($ext == '999' || $ext == '997') {
721 $str_html .= "Rejects: {$rslt[4]} <br />".PHP_EOL;
722 // don't have dialog from this dialog, so don't link
723 //$str_html .= "Rejects: <a class=\"codeval\" target=\"_blank\" href=\"edi_history_main.php?fv997={$rslt[1]}&err997={$rslt[4]}\">{$rslt[4]}</a><br />".PHP_EOL;
724 } elseif ($ext == 'ta1' || $ext == 'ack') {
725 $str_html .= "Code: {$rslt[4]} <br />".PHP_EOL;
726 //$str_html .= "Code: <a class=\"codeval\" target=\"_blank\" href=\"edi_history_main.php?ackfile={$rslt[1]}&ackcode={$rslt[4]}\">{$rslt[4]}</a><br />".PHP_EOL;
729 } else {
730 $str_html .= "Did not find corresponding 997/999 file for $ctln<br />".PHP_EOL;
732 } else {
733 $str_html .= "Invalid value for ICN number<br />".PHP_EOL;
735 return $str_html;
739 * function to check whether an era payment has been processed and applied
741 * @uses sqlQuery()
743 * @return string
745 function ibr_disp_is_era_processed() {
747 $str_html = '';
748 $ckno = filter_input(INPUT_GET, 'tracecheck', FILTER_SANITIZE_STRING);
749 if ($ckno) {
750 $srchval = 'ePay - '.$ckno;
751 // reference like '%".$srchval."%'"
752 $row = sqlQuery("SELECT reference, pay_total, global_amount FROM ar_session WHERE reference = ?", array($srchval) );
753 if (!empty($row)) {
754 $str_html .= "trace {$row['reference']} total \${$row['pay_total']}";
755 if ($row['global_amount'] === '0') {
756 $str_html .= " fully allocated";
757 } else {
758 $str_html .= " ({$row['global_amount']} not allocated)";
760 } else {
761 $str_html .= "trace $ckno not posted";
763 } else {
764 $str_html .= "trace not valid ID";
766 return $str_html;
770 * jQuery adds a special HTTP header for ajax requests
772 * @return bool
774 function is_xhr() {
775 return @ $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] === 'XMLHttpRequest';