/
addrefund.php
1507 lines (1026 loc) · 42 KB
/
addrefund.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//start session
ini_set('session.gc_maxlifetime', 600);
session_start();
/*
require('refundFunctions.php');
require_once "Mail.php";
$db = mysqli_connect('localhost','ptrefund','x22m3y2k','pt_refund'); //connect to database
if(!$db){die("Can't connect: ". mysqli_connect_error());}
*/
//include 'lib\refundFunctions.php';
include 'connectToDB.php';
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery </title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepickerSTART" ).datepicker();
});
$(function() {
$( "#datepickerEND" ).datepicker();
});
$(document).ready(function() {
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initial text box count
$(add_button).click(function(e){ //on add input button click
var display=x+1; //for alert box purposes
//alert('Please enter the additional Encounter Number associated with this refund in the new Encounter Field: Encounter Number '+display);
alert('Please enter the additional Encounter Number associated with this refund in the new Encounter Field. ');
e.preventDefault();
//Add the row, increment the counter
x++; //text box increment
$(wrapper).append('<tr id='+x+'><td>Additonal Encounter Number: </td><td><input type="text" name="encounters[]"/><a href="#" class="remove_field" id='+x+'>Remove</a></td></tr>'); //add input box
//$(wrapper).append('<tr id='+x+'><td>Encounter Number: '+x+'</td><td><input type="text" name="encounters[]"/><a href="#" class="remove_field" id='+x+'>Remove</a></td></tr>'); //add input box
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
alert('Encounter has been removed!');
//alert('This will remove Encounter Field Number '+$(this).parents('tr').contents());
//Remove the row, decrement the counter
e.preventDefault(); $(this).parents('tr').remove();
//x--;
})
});
</script>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function removeFocusPersonal()
{
document.add_refund.refund_type_personal.blur();
$(this).add_refund.refund_type_personal.blur();
document.getElementById('refund_type_personal').innerText;
document.getElementById('refund_type_personal').blur();
}
function removeFocusCommercial()
{
document.add_refund.refund_type_commercial.blur();
$(this).add_refund.refund_type_personal.blur();
}
</script>
</head>
<body>
</body>
</html>
<?php
if (array_key_exists('userid', $_SESSION)){ //If user is logged, check for access level
if($_SESSION['access']=='S' OR $_SESSION['access']=='U' OR $_SESSION['access']=='A'){
//once user is authenticated, check to see if this form has been submitted
if(isset($_POST['_submit_check'])){ //form has been submitted
$errors=array();
if(validateNewRefund($errors)=='valid') //if no errors, create user in db and show success message
{
$successfullUpload=0;
if(!isset($_POST['urgent'])){
$_POST['urgent']=0;
}
//echo 'ive reached the DB insert <br>';
//include 'dump_all_page_contents.php';
//create user in db
$now = date("Y-m-d H:i:s");
$query = "INSERT INTO refund (NG_enc_id, created_by, dt_request, urgent, amount, payable,
addr_ln_1,addr_ln_2,city,state,zip,purpose,status,comments,assigned_to,refund_type)
VALUES ('{$_POST['encounters'][0]}','{$_SESSION['userid']}','{$now}',{$_POST['urgent']},
'{$_POST['amount']}','{$_POST['payable']}','{$_POST['addr_ln_1']}','{$_POST['addr_ln_2']}',
'{$_POST['city']}','{$_POST['state']}','{$_POST['zip']}','{$_POST['purpose']}','NEW','{$_POST['comments']}','{$_SESSION['userid']}','{$_POST['refund_type']}')";
$result = mysqli_query($db,$query);
$last_id = mysqli_insert_id($db);
$auto_increment=$last_id++;
//reset auto increment id in case of errors
$query_resetAutoIncrement="ALTER TABLE refund AUTO_INCREMENT = '{$auto_increment}'";
$result = mysqli_query($db,$query_resetAutoIncrement);
//upload any attachments that have been added with the refund
$successfulUpload=uploadFiles($last_id);
if($successfulUpload==1){
//echo '<br> do I get here';
if(sizeof($_POST['encounters'])>1){
foreach($_POST['encounters'] as $key => $value){
if(strlen($value)>0){ //if there was actually a number entered into the encounter field
$queryManyEncounters = "INSERT INTO
refund_manyEncounters
(Encounter_ID, refund_ID)
VALUES ('{$value}','{$last_id}')";
$result = mysqli_query($db,$queryManyEncounters);
}
}
}
//die();
//send notification that a new refund has been created: call mail_presets
//RULE: ON Creation:
//IF urgent status email both creator and Erika, otherwise just email Erika///////////////////////////////////////////
$query = "SELECT username FROM users WHERE user_id='{$_SESSION['userid']}'";
$result = mysqli_query($db,$query);
$rowUserNames=mysqli_fetch_array($result);
//dynamically build the to address from the username selected based on the recipients specified by the step in the process
$to=$rowUserNames['username'].'@chcb.org'; //build the creator email
if($_POST['urgent']){ //verify that this works as intended
$status="A Refund for ".$_POST['payable']." with a Refund ID ".($last_id-1)." has been requested. <br> This refund is marked as URGENT.";
$from = "Patient Refund <noreply@chcb.org>";
$subject = "Created Patient Refund Request";
$body = "Hello,\n\n patient refund request # {$_POST['refund_id']} has been created. Please login to the Patient Refund web application to review.";
$body .="<br>Status: ".$status;
echo '<br><br>';
echo 'Sample EMAIL Feilds: ';
echo '<br>';
echo 'the from field is ';
echo $from;
echo '<br><br>';
echo 'the to field is: ';
echo $to;
echo '<br><br>';
echo 'the subject is: ';
echo $subject;
echo '<br><br>';
echo 'the body of the email is something to the effect of: <br>';
echo $body;
echo '<br><br>';
print '<h3 align="center"> Refund for '.$_POST['payable'].' created!</h3>';
print '<h4 align="center"><a href="index.php">Return to Refunds</a></h4>';
mail_presets($to,$status); //creator
mail_presets("ebrown@chcb.org",$status); //email erika (ebrown@chcb.org)
}else{
$status="A Refund for ".$_POST['payable']." with a Refund ID ".($last_id-1)." has been requested.";
$from = "Patient Refund <noreply@chcb.org>";
$subject = "Created Patient Refund Request";
$body = "Hello,\n\n patient refund request # {$_POST['refund_id']} has been created. Please login to the Patient Refund web application to review.";
$body .="<br>Status: ".$status;
echo '<br><br>';
echo 'Sample EMAIL Feilds: ';
echo '<br>';
echo 'the from field is: ';
echo $from;
echo '<br><br>';
echo 'the to field is: ';
echo $to;
echo '<br><br>';
echo 'the subject is: ';
echo $subject;
echo '<br><br>';
echo 'the body of the email is something to the effect of: <br>';
echo $body;
echo '<br><br>';
/*
echo $status;
echo '<br>';
*/
print '<h3 align="center"> Refund for '.$_POST['payable'].' created!</h3>';
print '<h4 align="center"><a href="index.php">Return to Refunds</a></h4>';
mail_presets($to,$status);
}
//END Send Emails Upon Creation ////////////////////////////////////////////////////////////////////////////////////////
//show success message
// print '<h3 align="center"> Refund for '.$_POST['payable'].' created!</h3>';
// print '<h4 align="center"><a href="index.php">Return to Refunds</a></h4>';
}else{ //unsuccessful upload, back everything out
$query="DELETE FROM refund WHERE refund_id='{$last_id}'";
$result = mysqli_query($db,$query);
$auto_increment=$last_id;
//reset auto increment id in case of errors
$query_resetAutoIncrement="ALTER TABLE refund AUTO_INCREMENT = '{$auto_increment}'";
$result = mysqli_query($db,$query_resetAutoIncrement);
//showPage($_SESSION['username'], $_SESSION['access'],validateNewRefund($errors));
}
} else {
//show errors at top of page
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
showPage($_SESSION['username'], $_SESSION['access'],validateNewRefund($errors));
}
//if errors exist, show page again & fill in values
} else { //form has not been submitted
showPage($_SESSION['username'],$_SESSION['access']); //show page if user is logged in
}
} else {
showLogin('The current user is not authorized to view this page.'); //unauthenticated users get OWNED!!
}
} elseif($_POST['username']) { //if user has attempted to login, validate login
if(validateLogin($_POST['username'],$_POST['password'])){
showPage($_SESSION['username'], $_SESSION['access']); //valid user! Show page!
} else {
showLogin('Login invalid. Please try again');
}
} else { //Else show login screen (no user is logged in and no login attempt has been made)
showLogin();
}
function displayRefundUploads($refund_id){
echo 'hhh';
//standardize filename structure to set proof of concept in place
//File 1 = File_
$target_dir ="";
$target_dir = "uploads/".$refund_id."/";
echo 'how';
// Open a known directory, and proceed to read its contents
if (is_dir($target_dir)) {
echo 'far';
if ($dh = opendir($target_dir)) {
echo 'go';
while (($file = readdir($dh)) !== false) {
echo "Filename: $file : filetype: " . filetype($target_dir . $file) . "\n";
}
closedir($dh);
}
}
}
function uploadFiles($refundID_just_created){
$off_by_one_targetDIR=$refundID_just_created-1;
$target_dir = "uploads/".$off_by_one_targetDIR."/";
$target_file="";
$naming_convention="";
$errors=array();
$uploadOk = 1;
if (!file_exists($target_dir )) { //if it doesnt exist, make it
//make directory
//if make fails error
//else run the program
}
if (!file_exists($target_dir )) { //so we don't make the folder for each of the uploads
if (!mkdir($target_dir, 0777, true)) {
die('There was an error creating the folder in which to upload your documents. Please make sure you have read write permissions on the
machine you are using. If the error persists, please contact your local network administrator.');
}
}
// else{
//upload files with file naming conventions in place
/*
EncounterNoteRef72.pdf,
TransactionDetailsRef72.pdf,
and CommercialPaperworkRef72.pdf
*/
if($_POST['refund_type']=='Commercial'){ //needs at least 3 documents
$fileBaseName="commercial_paperwork";
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$handle=substr($_FILES[$fileBaseName]["name"],0,strpos($_FILES[$fileBaseName]["name"],'.'));
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="CommercialPaperworkRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='CommercialPaperworkRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: CommercialPaperworkRef1.pdf <br><br>';
$uploadOk = 0;
//break;
}
/* ENCOUNTER NOTE and TRANSACTION DETAIL PAGE */
///////////////////////////////////////////////////////////////////////////////////
for($x=1;$x<=3;$x++){//runs three times
if($x==1)
$fileBaseName="encounter_note";
elseif($x==2)
$fileBaseName="transaction_detail_page";
else
$fileBaseName="commercial_paperwork";
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$handle=substr($_FILES[$fileBaseName]["name"],0,strpos($_FILES[$fileBaseName]["name"],'.'));
if($x==1){ //EncounterNoteRef
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="EncounterNoteRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='EncounterNoteRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: EncounterNoteRef1.pdf <br><br>';
/*
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
*/
//$errors=array();//reset the errors array
$uploadOk = 0;
//break;
}
}
elseif($x==2){
//TransactionDetailsRef72
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="TransactionDetailsRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='TransactionDetailsRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: TransactionDetailsRef1.pdf <br><br>';
/*
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
*/
//$errors=array();//reset the errors array
$uploadOk = 0;
//break;
}
}else{
//CommercialPaperworkRef72
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="CommercialPaperworkRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='CommercialPaperworkRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: CommercialPaperworkRef1.pdf <br><br>';
/*
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
*/
//$errors=array();//reset the errors array
$uploadOk = 0;
//break;
}
}
//echo 'the upload ok status is now <br>';
//echo $uploadOk;
if(strlen($_FILES[$fileBaseName]["name"])>0 && $uploadOk){
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists. <br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES[$fileBaseName]["size"] > 500000) {
echo "Sorry, your file is too large. <br>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "txt" && $imageFileType != "html"
&& $imageFileType != "bmp" && $imageFileType != "tif" && $imageFileType != "tiff" && $imageFileType != "docx" && $imageFileType != "xlsx") {
echo "Sorry, only JPG, JPEG, PNG, GIF, PDFs, DOCS, TXTs, HTML, xlsx, BMP and tif/tiff file types are allowed. <br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES[$fileBaseName]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES[$fileBaseName]["name"]). " has been uploaded. <br>";
} else {
echo "Sorry, the following error was encountered when attempting to upload your file. <br>";
print_r( error_get_last() );
}
}
}else{
/*echo "Sorry, Three documents are required to create a Commercial Refund Request: <br>
An encounter note, a transaction detail page and commercial paperwork document.<br> Please fix and re-upload.";
*/
/*
$errors[]="Sorry, Three documents are required to create a Commercial Refund Request: <br>
An encounter note, a transaction detail page and commercial paperwork document.<br> Please fix and re-upload.";
*/
//print_r( error_get_last() );
$uploadOk = 0;
}
}//end for loop for the two required files of personal
if($errors){
print '<center><h2 class = "error"> THE following errores were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
$uploadOk = 0;
$errors=array();//reset the errors array
include 'connectToDB.php';
$refundToDelete=$refundID_just_created-1;
$query_delete="DELETE FROM refund WHERE refund_id='{$refundToDelete}'";
$result_delete = mysqli_query($db,$query_delete);
$auto_increment=$refundToDelete;
//reset auto increment id in case of errors
$query_resetAutoIncrement="ALTER TABLE refund AUTO_INCREMENT = {$auto_increment} ";
$result = mysqli_query($db,$query_resetAutoIncrement);
$_SESSION['SAVE_POST']=$_POST;
//showPage($_SESSION['username'], $_SESSION['access'],validateNewRefund($errors));
print '<h4 align="center"><a href="addrefund.php">Return to Add Refund Page</a></h4>';
}
///////////////////////////////////////////////////////////////////////////////////
/* END ENCOUNTER NOTE and TRANSACTION DETAIL PAGE */
}else{ //only requires encounter_note and transaction_detail_page
for($x=1;$x<3;$x++){//runs twice
if($x==1)
$fileBaseName="encounter_note";
else
$fileBaseName="transaction_detail_page";
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$handle=substr($_FILES[$fileBaseName]["name"],0,strpos($_FILES[$fileBaseName]["name"],'.'));
if($x==1){ //EncounterNoteRef
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="EncounterNoteRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='EncounterNoteRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: EncounterNoteRef1.pdf';
/*
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
$errors=array();//reset the errors array
*/
$uploadOk = 0;
//break;
}
}
else{
//TransactionDetailsRef72
$refundIDToMatch=$refundID_just_created-1;
$naming_convention="TransactionDetailsRef".$refundIDToMatch;
$file_handle=$handle;
if($file_handle!=$naming_convention){
$errors[]='Your files must match the naming convention: <br>';
$errors[]='TransactionDetailsRefREFUND_ID.FileType <br>';
$errors[]='Example for Refund ID 1: TransactionDetailsRef1.pdf';
/*
print '<center><h2 class = "error"> THE following errors were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
$errors=array();//reset the errors array
*/
$uploadOk = 0;
//break;
}
}
//die();
/*
EncounterNoteRef72.pdf,
TransactionDetailsRef72.pdf,
and CommercialPaperworkRef72.pdf
*/
if(strlen($_FILES[$fileBaseName]["name"])>0 && $errors){
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists. <br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES[$fileBaseName]["size"] > 500000) {
echo "Sorry, your file is too large. <br>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "txt" && $imageFileType != "html"
&& $imageFileType != "bmp" && $imageFileType != "tif" && $imageFileType != "tiff" && $imageFileType != "docx" && $imageFileType != "xlsx") {
echo "Sorry, only JPG, JPEG, PNG, GIF, PDFs, DOCS, TXTs, HTML, xlsx, BMP and tif/tiff file types are allowed. <br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES[$fileBaseName]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES[$fileBaseName]["name"]). " has been uploaded. <br>";
} else {
echo "Sorry, the following error was encountered when attempting to upload your file. <br>";
print_r( error_get_last() );
}
}
}else{
//echo "Sorry, both an encounter note and a transaction detail are required to uploaded and named appropriately. <br>";
//$errors[]="Sorry, both an encounter note and a transaction detail are required to uploaded and named appropriately. <br>";
//print_r( error_get_last() );
//$uploadOk = 0;
if($errors){
print '<center><h2 class = "error"> THE following errores were encountered:</h2>';
print '<ul><li>';
print implode('</li><li>', $errors);
print '</li></ul></center>';
$uploadOk = 0;
$errors=array();//reset the errors array
//showPage($_SESSION['username'], $_SESSION['access'],validateNewRefund($errors));
include 'connectToDB.php';
$refundToDelete=$refundID_just_created-1;
$query_delete="DELETE FROM refund WHERE refund_id='{$refundToDelete}'";
$result_delete = mysqli_query($db,$query_delete);
$auto_increment=$refundToDelete;
//reset auto increment id in case of errors
$query_resetAutoIncrement="ALTER TABLE refund AUTO_INCREMENT = {$auto_increment}";
$result = mysqli_query($db,$query_resetAutoIncrement);
//showPage($_SESSION['username'], $_SESSION['access'],validateNewRefund($errors));
$_SESSION['SAVE_POST']=$_POST;
//include 'dump_all_page_contents.php';
print '<h4 align="center"><a href="addrefund.php">Return to Add Refund Page</a></h4>';
}
}
}//end for loop for the two required files of personal
}//end else personal refund
if($uploadOk){ //only evaluate extra uploads if the necessary uploads are successful
//continue...
//before was [file1]['name'], file2 etc..
if(isset($_POST['file4']) || isset($_POST['file5']) ){
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
for($x=4;$x<=5;$x++){//build up string of filenames
$fileBaseName="file";
$fileBaseName.=(string)$x;
if(strlen($_FILES[$fileBaseName]["name"])>0){
$target_file = $target_dir . basename($_FILES[$fileBaseName]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists. <br>";
$uploadOk = 0;
}
// Check file size
if ($_FILES[$fileBaseName]["size"] > 500000) {
echo "Sorry, your file is too large. <br>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "txt" && $imageFileType != "html"
&& $imageFileType != "bmp" && $imageFileType != "tif" && $imageFileType != "tiff" && $imageFileType != "docx" && $imageFileType != "xlsx") {
echo "Sorry, only JPG, JPEG, PNG, GIF, PDFs, DOCS, TXTs, HTML, xlsx, BMP and tif/tiff file types are allowed. <br>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES[$fileBaseName]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES[$fileBaseName]["name"]). " has been uploaded. <br>";
} else {
echo "Sorry, the following error was encountered when attempting to upload your file. <br>";
print_r( error_get_last() );
}
}
}
}//last ifs for loop
}//last if for file4 and file5
}//END only evaluate extra uploads if the necessary uploads are successful
// }//else of the mkdir
//return upload outcome
if($uploadOk==1){
//echo 'return true';
return 1;
}else{
//echo 'return false';
return 0;
}
} //end function
//Checks that new refund data submitted is valid or returns an array of errors
function validateNewRefund (&$errors){
//$errors = array();
$ctr_attachments=0;
if ($_POST['refund_type']=="Commercial"){
//check for at least three uploads
foreach($_FILES as $key => $value){
if($value['size']){//if size greater than 0, meaning something is attached, increment ctr_attachments;
$ctr_attachments++;
}
}
if($ctr_attachments<3){
$errors[]='In order to complete the refund creation Commercial Refunds Require at least three documents to be attached.';
}
}else{
//check for at least two uploads
foreach($_FILES as $key => $value){
if($value['size']){//if size greater than 0, meaning something is attached, increment ctr_attachments;
$ctr_attachments++;
}
}
if($ctr_attachments<2){
$errors[]='In order to complete the refund creation Personal Refunds Require at least two documents to be attached.';
}
}
if (strlen($_POST['amount'])<1){
$errors[]='Amount cannot be blank';
}
if (!is_numeric($_POST['amount'])){
$errors[]='Amount field value must be numeric';
}
if (strlen($_POST['payable'])<2){
$errors[]='Payable names must be at least 2 characters long';
}
if (strlen($_POST['addr_ln_1'])<1){
$errors[]='Address Line 1 cannot be blank';
}
if (strlen($_POST['city'])<1){
$errors[]='City cannot be blank';
}
if (strlen($_POST['state'])!=2){
$errors[]='State must be exactly 2 characters long';
}
if (strlen($_POST['zip'])<5){
$errors[]='Zip code must be at least 5 characters long';
}
if(sizeof($_POST['encounters'])>1){
foreach($_POST['encounters'] as $key => $value){
if(strlen($value<3)){
$errors[]='Encounter Number: '.($key+1).' must be at least three digits long.';
}
}
}elseif(strlen($_POST['encounters'][0])<3){
$errors[]='Encounter Numbers are required and must be at least three digits long.';
}
if (strlen($_POST['purpose'])<3){
$errors[]='Purpose cannot be blank';
}
if(sizeof($errors)) {
return $errors;
} else {