e335739d6f3ccfe5fbb9e0e0a3d1a1d09672846e
[openemr.git] / library / edihistory / ibr_io.php
blobe335739d6f3ccfe5fbb9e0e0a3d1a1d09672846e
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 == NULL || $clmid === FALSE || !$clmid ) {
239 $str_html .= "Invalid claim ID <br />";
240 return $str_html;
243 if (strlen($filename) >= 13 && strlen($filename) <= 14) {
244 // assume we have a bht03 number batch_icn + stnum
245 $isa13 = substr($filename, 0, 9);
246 $st02 = substr($filename, -4);
247 $btname = csv_file_by_controlnum('batch', $isa13);
248 if (!$btname) {
249 $str_html .= "Failed to identify batch file <br />";
250 return $str_html;
252 $str_html .= ibr_batch_get_st_block ($btname, $st02, $clmid);
253 } elseif (strlen($filename) == 9 && !strpos($filename, '.')) {
254 // assume we have a batch_icn
255 $btname = csv_file_by_controlnum('batch', $filename);
256 if (!$btname) {
257 $str_html .= "Failed to identify batch file <br />";
258 return $str_html;
260 $str_html .= ibr_batch_get_st_block ($btname, $st02, $clmid);
261 } elseif (!$filename || strlen($filename) <= 9) {
262 // search for file with the claim id
263 // (encounter, number, filename,)
264 $enc_ar = csv_file_with_pid_enctr($clmid, 'batch', 'ptctln');
265 if (is_array($enc_ar) && count($enc_ar) ) {
266 foreach($enc_ar as $enc) {
267 $str_html .= ibr_batch_get_st_block ( $enc[2], $enc[1] );
269 } elseif( is_string($enc_ar) && count($enc_ar) ) {
270 $str_html .= $enc_ar;
271 } else {
272 $str_html .= "Failed to find the batch file for $clmid <br />";
275 } else {
276 $str_html .= ibr_batch_get_st_block($filename, '', $clmid );
278 return $str_html;
282 * display the x12 segments for an era claim remittance advice
284 * @uses csv_file_with_pid_enctr()
285 * @uses ibr_era_get_clp_text()
286 * @return string
288 function ibr_disp_eraClp() {
289 // get the clp and related segments
290 $str_html = '';
291 $era_enc = filter_input(INPUT_POST, 'enctrEra', FILTER_SANITIZE_STRING);
292 $enc_ar = ($era_enc) ? csv_file_with_pid_enctr($era_enc, 'era', 'encounter') : false;
293 // $enc_ar is an array [i](pid, encounter, filename)
294 if (is_array($enc_ar) && count($enc_ar) ) {
295 foreach($enc_ar as $enc) {
296 //$pe = $enc[0] . "-" . $enc[1];
297 $pe = $enc[0];
298 $str_html .= ibr_era_get_clp_text($pe, $enc[2]);
300 } elseif( count($enc_ar) && is_string($enc_ar) ) {
301 $str_html .= $enc_ar;
302 } else {
303 $str_html .= "Failed to find the remittance for encounter ". strval($era_enc) ."<br />".PHP_EOL;
305 return $str_html;
309 * csv tables filter input and generate table
311 * @uses csv_to_html()
312 * @return string
314 function ibr_disp_csvtable() {
316 $rowp = filter_input(INPUT_POST, 'csvpctrows', FILTER_VALIDATE_INT);
317 $ds = filter_input(INPUT_POST, 'csv_date_start', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
318 $de = filter_input(INPUT_POST, 'csv_date_end', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
319 $csvfile = filter_input(INPUT_POST, 'csvtables', FILTER_SANITIZE_STRING);
321 $row_pct = ($rowp) ? $rowp/100 : 1;
322 if ($ds == NULL || $ds === FALSE ) { $ds = ''; }
323 if ($de == NULL) { $e = ($ds) ? date("Y/M/D", time()) : ''; }
324 if ($csvfile == NULL || $csvfile === FALSE ) {
325 // here we have an error and must quit
326 $str_html= "<p>Error in CSV table name </p>".PHP_EOL;
327 return $str_html;
328 } else {
329 $tp_ar = explode('_', $csvfile);
330 $tbl_type = ($tp_ar[0] == 'claims') ? 'claim' : 'file';
331 $f_type = strval($tp_ar[1]);
332 if ($f_type == '999' || $f_type == '997' || $f_type == '277') {
333 $f_type = 'f'.$f_type;
336 $str_html = csv_to_html($f_type, $tbl_type, $row_pct, $ds, $de);
338 return $str_html;
342 * links for RA info from POST for trace, patient ID, or encounter
344 * @uses csv_file_by_controlnum(
345 * @uses csv_file_with_pid_enctr()
346 * @uses ibr_era_html_page()
347 * @return string
349 function ibr_disp_era_post() {
351 $str_html = '';
352 // POST request from ERA tab -- era by pid, encounter, or trace
353 // there will not be a filename supplied with these values
354 $trace = ''; $pid = ''; $enctr = ''; $search = '';
355 //ibr_era_html_page ( $file_path, $trn_trace=0, $pid_enctr=0, $searchtype='ALL', $fname='835 Remittance Advice')
356 if ( isset($_POST['subtrace835']) && isset($_POST['trace835']) && $_POST['trace835'] ) {
357 $istrc = true;
358 $search = 'trace';
359 $trace = filter_input(INPUT_POST, 'trace835', FILTER_SANITIZE_STRING);
360 $eft = csv_file_by_controlnum('era', $trace);
361 if ($eft) {
362 $str_html .= ibr_era_html_page($eft, $trace, 0, $search, $eft);
363 } else {
364 $str_html .= "Did not find $trace in data <br />".PHP_EOL;
366 } elseif ( isset($_POST['subpid835']) && isset($_POST['pid835']) && $_POST['pid835']) {
367 $ispid = true; $isenc = false;
368 $search = 'pid';
369 $pid = filter_input(INPUT_POST, 'pid835', FILTER_SANITIZE_STRING);
370 $ef = ($pid) ? csv_file_with_pid_enctr ($pid, 'era', 'pid') : false;
371 } elseif (isset($_POST['subenctr835']) && isset($_POST['enctr835']) && $_POST['enctr835'] ) {
372 $isenc = true; $ispid = false;
373 $search = 'encounter';
374 $enctr = filter_input(INPUT_POST, 'enctr835', FILTER_SANITIZE_STRING);
375 $ef = ($enctr) ? csv_file_with_pid_enctr ($enctr, 'era', 'encounter') : false;
378 if ($isenc || $ispid) {
379 if ( is_array($ef) && count($ef) ) {
380 $fn = array();
381 foreach($ef as $val) {
382 // do not repeat filename since all occurences in a file are found
383 if ( in_array($val[2], $fn) ) {
384 continue;
385 } else {
386 $fn[] = $val[2];
387 $str_html .= ibr_era_html_page($val[2], 0, $val[0], $search, $val[2]);
390 } else {
391 $str_html .= "Did not find $pid $enctr in data <br />".PHP_EOL;
395 return $str_html;
400 * links for RA info from GET for patient ID or encounter
402 * @uses csv_file_with_pid_enctr()
403 * @uses ibr_era_claim_summary()
404 * @uses ibr_era_html_page()
405 * @return string
407 function ibr_disp_era_get() {
409 $str_html = '';
411 // all these should open in a new window or tab (target='_blank') except summary
412 $fname = isset($_GET['erafn']) ? filter_input(INPUT_GET, 'erafn', FILTER_SANITIZE_STRING) : '';
413 $pe = isset($_GET['pidenc']) ? filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING) : '';
414 $trace = isset($_GET['trace']) ? filter_input(INPUT_GET, 'trace', FILTER_SANITIZE_STRING) : '';
415 $stype = isset($_GET['srchtp']) ? filter_input(INPUT_GET, 'srchtp', FILTER_SANITIZE_STRING) : '';
416 $smy = isset($_GET['summary']) ? filter_input(INPUT_GET, 'summary', FILTER_SANITIZE_STRING) : '';
418 if (!$fname && $pe && $stype=='encounter') {
419 // all RA's for this encounter
420 $ef = csv_file_with_pid_enctr($pe, 'era', $stype);
421 if (is_array($ef) && count($ef) ) {
422 foreach($ef as $val) {
423 // -- do not repeat filename since all occurences in a file are found
424 // (pid-enctr, trace, filename)
425 if ( in_array($val[2], $fn) ) {
426 continue;
427 } else {
428 $fn[] = $val[2];
429 $pe = $val[0];
430 $str_html .= ibr_era_html_page($val[2], 0, $pe, 'encounter', $val[2]);
433 } else {
434 $str_html .= "Did not find $pe in data <br />".PHP_EOL;
436 } elseif (!$fname && $trace) {
437 $fname = csv_file_by_controlnum('era', $trace);
438 if ($fname) {
439 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
440 } else {
441 $str_html .= "Did not find file for trace $trace <br />".PHP_EOL;
443 } elseif ($fname && $pe && $smy=='yes') {
444 // payment summary for popup dialog
445 $str_html .= ibr_era_claim_summary($fname, $pe);
446 } elseif ($fname && $pe && !$smy) {
447 // all RA's for this patient ID in transaction
448 $str_html .= ibr_era_html_page($fname, 0, $pe, 'encounter', $fname);
449 } elseif ($fname && $trace) {
450 // RA for this trace number
451 $str_html .= ibr_era_html_page($fname, $trace, 0, 'trace', $fname);
454 return $str_html;
457 function ibr_disp_clmhist() {
459 if (isset($_GET['chenctr']) && strlen($_GET['chenctr'])) {
460 $pe = filter_input(INPUT_GET, 'chenctr', FILTER_SANITIZE_STRING);
461 $str_html = csv_claim_history($pe);
462 } else {
463 $str_html = "Error in processing request.<br />".PHP_EOL;
465 return $str_html;
469 * filter input and generate display for claim status response
471 * @uses ibr_277_response_html()
472 * @return string
474 function ibr_disp_status_resp() {
476 $fname = filter_input(INPUT_GET, 'rspfile', FILTER_SANITIZE_STRING);
477 $st = ''; $pe = '';
478 if (isset($_GET['pidenc']) && strlen($_GET['pidenc'])) {
479 $pe = filter_input(INPUT_GET, 'pidenc', FILTER_SANITIZE_STRING);
480 } elseif (isset($_GET['rspstnum']) && strpos($_GET['rspstnum'], '_')) {
481 // the rspstnum is the 277 ISA13_ST02
482 $st = filter_input(INPUT_GET, 'rspstnum', FILTER_SANITIZE_STRING);
485 if (!$pe && !$st) {
486 $str_html = "No claim identification information for claim status.<br />".PHP_EOL;
487 } else {
488 $str_html = ibr_277_response_html($fname, '', '', $pe, $st);
490 return $str_html;
494 * display the message part of a DPR response
496 * @uses ibr_dpr_message()
497 * @return string
499 function ibr_disp_dpr_message() {
501 $fname = filter_input(INPUT_GET, 'dprfile', FILTER_SANITIZE_STRING);
502 if (isset($_GET['dprclm']) && strlen($_GET['dprclm'])) {
503 $pe = filter_input(INPUT_GET, 'dprclm', FILTER_SANITIZE_STRING);
505 if (!$fname || !$pe) {
506 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
507 } else {
508 $str_html = ibr_dpr_message($fname, $pe);
510 return $str_html;
514 * display the message part of a EBR or IBR response
516 * @uses ibr_ebr_message()
517 * @return string
519 function ibr_disp_ebr_message() {
521 $fname = ''; $pe = ''; $btfnm = '';
522 $fname = filter_input(INPUT_GET, 'ebrfile', FILTER_SANITIZE_STRING);
523 if (isset($_GET['ebrclm']) && strlen($_GET['ebrclm'])) {
524 $pe = filter_input(INPUT_GET, 'ebrclm', FILTER_SANITIZE_STRING);
526 if (isset($_GET['batchfile']) && strlen($_GET['batchfile'])) {
527 $btfnm = filter_input(INPUT_GET, 'batchfile', FILTER_SANITIZE_STRING);
529 if (!$fname || !$pe) {
530 $str_html = "Missing file or claim ID.<br />".PHP_EOL;
531 } else {
532 $str_html = ibr_ebr_message($fname, $pe, $btfnm);
534 return $str_html;
538 * display the message part of a 999 response
540 * @uses ibr_997_errscan()
541 * @return string
543 function ibr_disp_997_message() {
545 $fname = ''; $akval = ''; $errval = '';
546 $fname = filter_input(INPUT_GET, 'fv997', FILTER_SANITIZE_STRING);
547 if (isset($_GET['aknum'])) { $akval = filter_input(INPUT_GET, 'aknum', FILTER_SANITIZE_STRING); }
548 if (isset($_GET['err997'])) { $errval = filter_input(INPUT_GET, 'err997', FILTER_SANITIZE_STRING); }
549 if (!$fname) {
550 $str_html = "Missing file name.<br />".PHP_EOL;
551 } else {
552 $str_html = ibr_997_errscan($fname, $akval);
554 return $str_html;
558 * display the message part of a ACK or TA1 response
560 * @uses ibr_ack_error()
561 * @return string
563 function ibr_disp_ta1_message() {
565 $fname = ''; $code = '';
566 $fname = filter_input(INPUT_GET, 'ackfile', FILTER_SANITIZE_STRING);
567 if (isset($_GET['ackcode'])) $code = filter_input(INPUT_GET, 'ackcode', FILTER_SANITIZE_STRING);
568 if ($fname && $code) {
569 $str_html = ibr_ack_error($fname, $code);
570 } else {
571 $str_html = 'Code value invalid <br />'.PHP_EOL;
573 return $str_html;
578 * filter input and display local era file
580 * @uses ibr_upload_files()
581 * @uses ibr_era_html_page()
582 * @return string
584 function ibr_disp_erafileUpl() {
585 // file uploads; single file controls
586 $str_html = '';
588 if ( count($_FILES) ) {
589 $f_array = ibr_upload_files($str_html);
590 if ( is_array($f_array) && count($f_array) ) {
591 $f_name = basename($f_array['era'][0]);
592 $str_html .= ibr_era_html_page($f_array['era'][0], 0, 0, 0, $f_name);
593 } else {
594 $str_html .= "no files accepted <br />" . PHP_EOL;
596 } else {
597 $str_html .= "no file submitted <br />" . PHP_EOL;
599 return $str_html;
603 * uploading of new files
605 * @uses ibr_upload_files()
606 * @uses ibr_sort_upload()
607 * @return string
609 function ibr_disp_fileMulti() {
610 // multiple file upload
611 $str_html = '';
612 if ( count($_FILES) ) {
613 $f_array = ibr_upload_files($str_html);
614 if ( is_array($f_array) && count($f_array) ) {
615 $str_html .= "sending ".count($f_array)." type for sorting <br />" .PHP_EOL;
616 $str_html .= ibr_sort_upload($f_array, $htm, $er);
617 } else {
618 $str_html .= "no files accepted <br />".PHP_EOL;
620 } else {
621 $str_html .= "no files submitted <br />" . PHP_EOL;
623 $str_html .= PHP_EOL."<form>".PHP_EOL;
624 $str_html .= "<input type='button' id='closepopup' value='Close' onclick='self.close()'>".PHP_EOL;
625 $str_html .= "</form>".PHP_EOL;
627 return $str_html;
632 * filter input and generate display of x12 file
634 * @uses csv_filetohtml()
635 * @uses ibr_upload_files()
636 * @uses ibr_ebr_ebt_name()
637 * @return string
639 function ibr_disp_fileText() {
641 $str_html = '';
642 //isset($_POST['fileX12']) && isset($_FILES['fileUplx12'])
643 if ( count($_FILES) && isset($_FILES['fileUplx12']) ) {
644 $fn = htmlentities($_FILES['fileUplx12']['name']);
645 $str_html = ibr_html_heading('newfiles', $fn);
646 $f_array = ibr_upload_files($str_html);
647 if ( is_array($f_array) && count($f_array) ) {
648 $str_html .= csv_filetohtml($f_array);
649 } else {
650 $str_html = ibr_html_heading('error');
651 $str_html .= "no files accepted <br />" . PHP_EOL;
653 } elseif ( isset($_GET['fvkey']) ) {
654 $fn = filter_input(INPUT_GET, 'fvkey', FILTER_SANITIZE_STRING);
655 // Availity 'readable' versions ibr, ebr, dpr
656 $ishr = (isset($_GET['readable']) && $_GET['readable']=='yes') ? true : false;
657 if (!$fn) {
658 $str_html = ibr_html_heading('error');
659 } elseif ($ishr && $fn) {
660 $ftxt = ibr_ebr_ebt_name($fn);
661 $str_html = ibr_html_heading('textdisplay', $ftxt);
662 $str_html .= csv_filetohtml($ftxt);
663 } else {
664 $bn = basename($fn);
665 $str_html = ibr_html_heading('textdisplay', $bn);
666 $str_html .= csv_filetohtml($fn);
668 } elseif (isset($_GET['btctln']) ) {
669 $btisa13 = filter_input(INPUT_GET, 'btctln', FILTER_SANITIZE_STRING);
670 if ($btisa13) {
671 //$btname = ibr_batch_find_file_with_controlnum($btisa13);
672 $btname = csv_file_by_controlnum('batch', $btisa13);
673 $str_html = ibr_html_heading('textdisplay', $btname);
674 if ($btname) {
675 $str_html .= csv_filetohtml($btname);
676 } else {
677 $str_html .= "Failed to identify file with control number $btisa13 <br />".PHP_EOL;
679 } else {
680 $str_html .= "error in file display <br />";
682 } else {
683 $str_html = ibr_html_heading('error');
684 $str_html .= "error in file display <br />";
686 return $str_html;
690 * check if the batch control number is found in the 997/999 files table
692 * @uses csv_search_record()
693 * @return string
695 function ibr_disp_997_for_batch() {
696 $str_html = '';
697 $batch_icn = filter_input(INPUT_GET, 'batchicn', FILTER_SANITIZE_STRING);
698 if ($batch_icn) {
699 $ctln = (strlen($batch_icn) >= 9) ? substr($batch_icn, 0, 9) : trim(strval($batch_icn));
700 $search = array('s_val'=>$ctln, 's_col'=>3, 'r_cols'=>'all');
701 $result = csv_search_record('f997', 'file', $search, "1");
703 // should be matching row(s) from files_997.csv
704 if (is_array($result) && count($result)) {
705 $str_html .= "<p>Acknowledgement information</p>".PHP_EOL;
706 foreach($result as $rslt) {
707 $ext = substr($rslt[1], -3);
709 $str_html .= "Date: {$rslt[0]} <br />".PHP_EOL;
710 $str_html .= "File: <a target=\"blank\" href=edi_history_main.php?fvkey={$rslt[1]}>{$rslt[1]}</a> <br />".PHP_EOL;
711 $str_html .= "Batch ICN: {$rslt[3]} <br />";
712 // error count or code in position 4
713 if ($ext == '999' || $ext == '997') {
714 $str_html .= "Rejects: {$rslt[4]} <br />".PHP_EOL;
715 // don't have dialog from this dialog, so don't link
716 //$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;
717 } elseif ($ext == 'ta1' || $ext == 'ack') {
718 $str_html .= "Code: {$rslt[4]} <br />".PHP_EOL;
719 //$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;
722 } else {
723 $str_html .= "Did not find corresponding 997/999 file for $ctln<br />".PHP_EOL;
725 } else {
726 $str_html .= "Invalid value for ICN number<br />".PHP_EOL;
728 return $str_html;
732 * function to check whether an era payment has been processed and applied
734 * @uses sqlQuery()
736 * @return string
738 function ibr_disp_is_era_processed() {
740 $str_html = '';
741 $ckno = filter_input(INPUT_GET, 'tracecheck', FILTER_SANITIZE_STRING);
742 if ($ckno) {
743 $srchval = 'ePay - '.$ckno;
744 // reference like '%".$srchval."%'"
745 $row = sqlQuery("SELECT reference, pay_total, global_amount FROM ar_session WHERE reference = ?", array($srchval) );
746 if (!empty($row)) {
747 $str_html .= "trace {$row['reference']} total \${$row['pay_total']}";
748 if ($row['global_amount'] === '0') {
749 $str_html .= " fully allocated";
750 } else {
751 $str_html .= " ({$row['global_amount']} not allocated)";
753 } else {
754 $str_html .= "trace $ckno not posted";
756 } else {
757 $str_html .= "trace not valid ID";
759 return $str_html;
763 * jQuery adds a special HTTP header for ajax requests
765 * @return bool
767 function is_xhr() {
768 return @ $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] === 'XMLHttpRequest';