/
index.php
1303 lines (1223 loc) · 49.2 KB
/
index.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
{ // local vs production settings
$num_col = 3; // Number of items per row
$sandbox = "no";
$sandbox = "yes";
// $sandbox = "dad";
// settings for production
$server = "localhost";
$sql_user = "ccaac";
$pass_wd = "caplin";
$dbf = "ccaac";
$table1 = "inventory";
//$dblink = new mysqli($server,$user_id,$pass_wd,$dbf);
// Beware of line 78 in function berrer_odbc_num_rows
// while($temp = odbc_fetch_into($result, &$counter)){
date_default_timezone_set("America/Chicago");
if ($sandbox == "yes") { // settings for Sandbox
$server = "localhost";
$sql_user = "root";
$pass_wd = "";
$dbf = "ccaac";
$table1 = "inventory";
$title = "John Inventory";
$dbf_prefix = "cap";
$copyrite = "VTN";
}
if ($sandbox == "dad") { // settings for Sandbox
$server = "localhost";
$sql_user = "reneeteague";
$pass_wd = "TromblyTeague1100";
$dbf = "ccaac";
$table1 = "my_inventory";
$title = "Renees Check List";
$dbf_prefix = "cap";
$copyrite = "VTN";
}
if ($sandbox == "no") { // settings for CCAAC
$server = "localhost";
$sql_user = "ccaac";
$pass_wd = "caplin";
$dbf = "ccaac";
$table1 = "inventory";
$title = "Dr. Caplin Inventory";
$dbf_prefix = "cap";
$copyrite = "CCAAC";
}
} // END Local vs production settings
{ // Session Stuff
session_start();
$session_lifetime = 1800; // 30 min or 1800 sec
// $session_lifetime = 10; // 30 min or 1800 sec
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > $session_lifetime)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > $session_lifetime) {
// session started more than 30 minutes ago
session_regenerate_id(true); // change session ID for the current session an invalidate old session ID
$_SESSION['CREATED'] = time(); // update creation time
}
foreach ($_SESSION as $key=>$value) {
${$key} = $value;
}
$dblink = new mysqli($server,$sql_user,$pass_wd,$dbf);
if ($dblink->connect_errno) {
echo "Failed to connect to MySQL: " . $dblink->connect_error;
}
} // End Session Stuff
{ //System Vars
// Reveal all get and post variables
// Should be replaced later by calls to the $_GET or $_POST arrays
foreach($_GET as $variable => $value) {
$$variable = $value; // copy all get vars into globals
}
foreach($_POST as $variable => $value) {
$$variable = $value; // copy all post vars into globals
}
// foreach($_SESSION as $variable => $value) {
// $$variable = $value; // copy all Session vars into globals
// }
//Trun off session error that is triggered when
//you have a local variable with the same name as a session Var
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
//Trun off session error reporting
$PHP_SELF = $_SERVER['PHP_SELF'];
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
// end of reveal all get and post variables
$css_include_file = "/css/jbt12.css";
$cgi = $PHP_SELF;
$d_quote = chr(34);
$s_quote = "'";
$lf = chr(10);
$cr = chr(13);
$tab = chr(9);
$comma = ",";
$mydbf = $table1;
$dblink->select_db("ccaac") or die("Error contacting ccaac DBF " . $dblink->error);
{ // Set defaults for date, CPT, Patient id for the selection grids
$mynow = getdate(time());
$mydate = $mynow["mon"] . "/" . $mynow["mday"] . "/" .$mynow["year"];
// echo "<p>Date = $mydate</p>";
$newdate = new DateTime($mydate);
$interval = new DateInterval('P1M');
$newdate->sub($interval);
$past_date = $newdate->format('m/d/Y');
}
} //End of System Vars
{ //- Start of Functions
function better_odbc_num_rows($con,$sql){
//echo "<p>$sql</p>";
$result = odbc_exec($con,$sql);
$count=0;
while($temp = odbc_fetch_into($result, $dummy)){
$count++;
}
return $count;
} // end of better_odbc_num_rows
function DosDate($date) {
// takes a date string in YYYY-MM-DD format
// and returns it in MM/DD/YYYY format (for Regular People)
if (preg_match ("/([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})/", $date, $regs)) {
$retval = "$regs[2]/$regs[3]/$regs[1]";
}
return $retval;
} //end of LinuxDate function
function FixMyString($mystring) {
// *** ATTENTION ***
// Special Modified version allows single quotes to pass!
// Be sure that when this text is sent, double quites surround it in the SQL statement!
// *** ATTENTION ***
// This will remove the dangerous characters quotes and question mark
$temp = $mystring;
$temp = str_replace("'", "", $mystring); // byby single quote
$temp = str_replace('"', "", $temp); // byby double quotes
$temp = str_replace("?", "", $temp); // byby question mark
$temp = str_replace("$", "", $temp); // byby Dollar sign (just for good measure
$temp = str_replace("&", "", $temp); // byby AND sign (makes html crankey
$temp = str_replace(",", "", $temp); // byby comma sign (makes html crankey as well
// no HTML tags should pass so no < or >
$temp = str_replace("<", "", $temp); // byby start of HTML Tags
$temp = str_replace(">", "", $temp); // byby end of HTML Tags
$mylen_now = strlen($temp);
$mylen_prior = $mylen_now + 1;
while ($mylen_now <> $mylen_prior) {
$mylen_prior = strlen($temp);
$temp = str_replace(" ", " ", $temp); // Get rid of ** ALL ** the white space!!
$mylen_now = strlen($temp);
}
$bkslach = chr(92);
$temp = str_replace($bkslach, "", $temp); // byby Backslash because this is used to signal special characters)
return $temp;
} // end of FixMyString
function form_button($form1) {
$start = "<table class='menu'>
<tr><td class='blank'><div id='CssMenu'>
<ul><li class='firstmain'>\n";
$middle = "</li></ul></div></td>
<td class='blank'><div id='CssMenu'>
<ul><li class='firstmain'>";
$end = "</li></ul></div></td>
</tr></table>\n";
$start = "";
$middle = "";
$end = "";
$match_str = "type='submit'";
$repl_str = "type='submit' class='sbutton'";
$form1 = str_replace($match_str, $repl_str, $form1);
echo "$start$form1$end";
}
function getname($target_dir) {
$path_parts = pathinfo($_SERVER['SCRIPT_FILENAME']);
$mydir = $path_parts['dirname'];
$mydir .= "/" . $target_dir;
return $mydir . strtolower(basename($_FILES["uploadedfile"]["name"]));
}
function LinuxDate($date) {
// takes a date string in MM/DD/YYYY format
// and returns it in YYYY-MM-DD format (for Mysql)
if (preg_match ("#([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})#", $date, $regs)) {
$retval = "$regs[3]-$regs[1]-$regs[2]";
}
return $retval;
} //end of LinuxDate function
function MeColorTR($count, $numCols) {
// Puts in the color tag for a row (TR>
// numCols is the # of Colums desired
$setColor = $count % $numCols;
if ($setColor == 0 ) {
// Here is where we plan the color for the new Row
$setColor = intval($count / $numCols);
$setColor = $setColor%3;
switch ($setColor) {
case "0":
echo "\n<tr bgcolor=#DDDDDD>";
break;
case "1":
echo "\n<tr bgcolor=#CCCCCC>";
break;
case "2":
echo "\n<tr bgcolor=#C0C0C0>";
break;
case "3":
echo "\n<tr>";
break;
} // end switch
}
// increment the counter
$retval = $count + 1;
return $retval;
} // end of MeColorTR
function mybanner($string, $dblink, $css_include_file, $title) {
// default banner for this program
$bk = "background='/backgrounds/pa-sw-602.jpg'";
// public_html
// pa-sw-602.jpg
$myheadder = "== $title ==<br />";
$mydate = getdate(time());
echo '<!DOCTYPE HTML>' . "\n";
echo "<html>\n";
echo "<head>\n";
echo "<link rel='stylesheet' type='text/css' href='$css_include_file'>\n";
echo "<link rel='stylesheet' type='text/css' href='/css/1.8.16.css' media='all'>\n";
echo "<link rel='shortcut icon' href='https://www.vtracnow.com/favicon.ico?v=2' />\n";
echo "<script type='text/javascript' src='/css/1.7.1.js'></script>\n";
echo "<script type='text/javascript' src='/css/1.8.16.js'></script>\n";
echo "<script>\n";
echo "$(function() {\n";
echo " $('#datepick').datepicker();\n";
echo "});\n";
echo "$(function() {\n";
echo " $('#datepick2').datepicker();\n";
echo "});\n";
echo "$(function() {\n";
echo " $('#datepick3').datepicker();\n";
echo "});\n";
echo "$(function() {\n";
echo " $('#datepick4').datepicker();\n";
echo "});\n";
echo "</script>\n";
echo "</head>\n";
echo "<body>";
// echo "<script>\n";
// echo "history.forward();\n";
// echo "</script>\n";
$user_name = $_SESSION['user_name'];
$usr_access = $_SESSION['usr_access'];
$string1 = "<p class='trademark'>$myheadder Administration</p>\n";
$string2 ="<p class='h3'>User: $user_name<br>Access Level: $usr_access<br>$string<br>";
echo "$string1$string2 ===================<br>" . $mydate["month"] . " " . $mydate["mday"] . ", " .$mydate["year"] . "</p>\n";
// No Back Button!!!!!
} // end of mybanner
function NavBar($cgi, $act, $usr_access, $copyrite) {
// Displays links for navigation in this program
$d_quote = chr(34);
echo "<br>";
echo "<table class='menu'>\n";
// if ($usr_access > 50) {
// echo "<tr><td colspan='5'>== Main Navigation Controls $usr_access ==</td></tr>\n";
// } else {
// echo "<tr><td colspan='4'>== Main Navigation Controls $usr_access ==</td></tr>\n";
// }
$start = "<div id='CssMenu'>\n<ul><li class='firstmain'>";
$end = "</li></ul></div>";
switch ($act) {
case "login": {
echo"<tr>\n";
echo "<td class='blank'>$start" . "Please Login" . "$end</td>\n";
echo "</tr>\n";
}
break;
case "check_login": {
echo"<tr>\n";
echo "<td class='blank'>$start<a href='$cgi' >Continue</a>$end</td>\n";
echo "</tr>\n";
}
break;
case "logout": {
echo"<tr>\n";
echo "<td class='blank'>$start<a href='$cgi' >Login?</a>$end</td>\n";
echo "</tr>\n";
}
break;
default: {
echo"<tr>\n";
// if (($_SESSION['my_cat_id'] == '') || (!isset($_SESSION['my_cat_id']))) {
if (!isset($_SESSION['my_cat_id'])) {
} else {
echo "<td class='blank'>$start<a href='$cgi?act=list'>List</a>$end</td>\n";
echo "<td class='blank'>$start<a href='$cgi?act=new' >Create New</a>$end</td>\n";
}
echo "<td class='blank'>$start<a href='$cgi?act=logout' >Log Off</a>$end</td>\n";
echo "<td class='blank'>$start<a href='$cgi?act=make_cat' >Category</a>$end</td>\n";
echo "</tr>\n";
echo "</table>";
}
} // end act switch
echo "</table>";
echo "<p class='h3smallred'> © 2015 $copyrite </p>";
} // end of NavBar
function shortbanner($string, $dblink, $css_include_file, $title) {
$myheadder = "== $title ==<br />";
$mydate = getdate(time());
echo '<!DOCTYPE HTML>' . "\n";
echo "<html>\n";
echo "<head>\n";
echo "<link rel='stylesheet' type='text/css' href='$css_include_file'>\n";
echo "<link rel='stylesheet' type='text/css' href='/css/1.8.16.css' media='all'>\n";
echo "<link rel='shortcut icon' href='https://www.vtracnow.com/favicon.ico?v=2' />\n";
echo "<script type='text/javascript' src='/css/1.7.1.js'></script>\n";
echo "<script type='text/javascript' src='/css/1.8.16.js'></script>\n";
echo "<script>\n";
echo "$(function() {\n";
echo " $('#datepick').datepicker();\n";
echo "});\n";
echo "$(function() {\n";
echo " $('#datepick2').datepicker();\n";
echo "});\n";
echo "</script>\n";
echo "</head>\n";
echo "<body>";
// echo "<script>\n";
// echo "history.forward();\n";
// echo "</script>\n";
$string1 = "<p class='trademark'>$myheadder Administration</p>\n";
$string2 ="<p class='h3'>$string<br>";
$string2 = "";
echo "$string1$string2 ===================<br>" . $mydate["month"] . " " . $mydate["mday"] . ", " .$mydate["year"] . "</p>\n";
// No Back Button!!!!!
echo "</html>";
} // end of shortbanner
function ValadateInput($txt, $type, $comment) {
// send text and a type and get back an error comment
// if the error comment is empty, then it is ok
$retval = "";
switch ($type) {
case "char"; {
$retval = "";
if (strlen($txt) < 1) {
$retval = "$comment '$txt' is too short<BR>\nMust be at least 1 characters long<br>\n";
}
break;
}
case "short"; {
$retval = "";
if (strlen($txt) < 1) {
$retval = "$comment '$txt' is too short<BR>\nMust be at least 1 characters long<br>\n";
}
break;
}
case "sname"; {
$retval = "";
if (strlen($txt) < 2) {
$retval = "$comment '$txt' is too short<BR>\nMust be at least 2 characters long<br>\n";
}
break;
}
case "name"; {
$retval = "";
if (strlen($txt) < 3) {
$retval = "$comment '$txt' is too short<BR>\nMust be at least 3 characters long<br>\n";
}
break;
}
case "date": {
$err_date = "Invalid date format for $comment: <BR>Cannot determine '$txt' as being a valid date<BR>";
$retval = "";
if (preg_match ("#([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})#", $txt, $regs)) {
$mymonth = $regs[1];
$mydate = $regs[2];
$myyear = $regs[3];
settype($mymonth, "integer");
settype($mydate, "integer");
settype($myyear, "integer");
if ($myyear < 1 or $myyear > 2071) {
$retval .= "<p class='h3red'>$err_date The year is in question<br></p>";
} else {
if (($mymonth < 1) or ($mymonth > 12)) $retval .= "<p class='h3red'>$err_date Month should be between 1 and 12</p>";
if ($mydate < 1 or $mydate > 31) {
$retval .= "<p class='h3red'>$err_date No month has more than 31 days or less than 1 day</p>";
} else {
if ($mymonth == 4 or $mymonth == 6 or $mymonth == 9 or $mymonth == 11) {
if ($mydate == 31) $retval .= "<p class='h3red'>$err_date Only 30 days in this month (month #$mymonth)</p>";
}
if ($mymonth == 2) {
if ($mydate > 29) $retval .= "<p class='h3red'>$err_date There can never be more than 29 days in ANY Febuary</p>";
if ($mydate == 29 and $myyear % 4 > 0) $retval .= "<p class='h3red'>$err_date Only 28 days in THIS Febuary</p>";
}
}
}
} else {
$retval .= "<p class='h3red'>$err_date Try using the MM/DD/YYYY format</p>";
}
break;
}
case "email": {
$at_loc = strpos($txt, "@");
$email_exp = "^[a-z0-9\._-]+@[a-z0-9\._-]+\.+[a-z]{2,3}$";
if ($at_loc < 2) {
$retval .= "Please check the prefix and @ sign<br>\n";
}
$firstdot = strpos($txt, ".");
$afterdot = substr($txt, $firstdot + 1);
if ($firstdot < 1) {
$retval .= "Please check the suffix for accuracy.<br>\n";
$retval .= "(It should include a .com,.net,.org,.gov,.mil, or other)<br>\n";
// 3/26/2003 jbt
// Found email address with a dot prior to the @ ie john.trombly@goofy.org
// making sure that there is a . after the @ and not allowing more than 2 dots prior to the @
} else {
if ($at_loc > $firstdot + strpos($afterdot, ".")) {
$retval .= "Max of one dot prior to the @ sign<br>and<br>must have a dot after the @ sign<br>\n";
}
}
if (!preg_match("#" . $email_exp . "#i", $txt)) {
$retval .= "Check Email address again for valid form";
}
if (strlen($retval) > 0) {
$retval = "<p class='h3red'>Sorry. This $comment '$txt' seems wrong.<br>\n" . $retval . "</p>\n";
}
break;
}
case "num": {
if (strlen($txt) < 1) {
$retval = "$comment is too short<BR>\nPut $comment in number format ie 999<br>\n";
} else {
if (!preg_match("/(^[0-9]{1,6})$/", $txt)) {
$retval = "$comment must be in this format<BR>9999<br>\n";
}
}
if (strlen($retval) > 0) {
$retval = "<p class='h3red'>Error in $comment ($txt).<br>\n" . $retval . "</p>\n";
}
break;
}
case "no_zero_num": {
if (strlen($txt) < 1) {
$retval = "$comment is too short<BR>\nPut $comment in number format ie 999<br>\n";
} else {
if (!preg_match("/(^[0-9]{1,6})$/", $txt)) {
$retval = "$comment must be in this format<BR>9999<br>\n";
} else {
if (($txt * 1) == 0) {
$retval = "$comment can not be ZERO<br>\n";
}
}
}
if (strlen($retval) > 0) {
$retval = "<p class='h3red'>Error in $comment ($txt).<br>\n" . $retval . "</p>\n";
}
break;
}
case "num62": {
if (strlen($txt) < 1) {
$retval = "$comment is too short<BR>\nPut $comment in number format ie 999.99<br>\n";
} else {
if (!preg_match("/(^[0-9]{1,3}.[0-9]{1,2})$/", $txt)) {
$retval = "$comment must be in this format<BR>999.99<br>\n";
}
}
if (strlen($retval) > 0) {
$retval = "<p class='h3red'>Error in $comment ($txt).<br>\n" . $retval . "</p>\n";
}
break;
}
case "phone": {
if (strlen($txt) < 12) {
$retval = "$comment is too short<BR>\nPut phone number in 999-999-9999<br>\n";
} else {
if (!preg_match("/([0-9]{3,3})-([0-9]{3,3})-([0-9]{3,3})/", $txt)) {
$retval = "Phone number must be in this format<BR>999-999-9999<br>\n";
}
}
if (strlen($retval) > 0) {
$retval = "<p class='h3red'>Error in $comment ($txt).<br>\n" . $retval . "</p>\n";
}
break;
}
case "time": {
if (strlen($txt) != 5) {
$retval = "<br>$comment is not 5 characters long<br>Put time string like 99:99";
} else {
if (!preg_match("/([0-2]{1,1})([0-9]{1,1}):([0-5]{1,1})([0-9]{1,1})/", $txt)) {
$retval = "<br><b>$comment</b> is time and must be in this format<BR>hh:mm<br>hh must be less than 30<br>mm must be less than 60<br>\n"; }
}
break;
}
case "YN": {
if (strlen($txt) != 1) {
$retval = "<br>$comment is not 1 characters long<br>Only put Y or N";
} else {
if ($txt != 'Y' and $txt != 'N') {
$retval = "<br>$comment can only be <b>Y</b> or <b>N</b><br>\n";
}
}
break;
}
case "hml": {
if (strlen($txt) != 1) {
$retval = "<br>$comment is not 1 characters long<br>Only put H, M, or L";
} else {
if ($txt != '1' and $txt != '2' and $txt != '3') {
$retval = "<br>$comment can only be <b>1</b> or <b>2</b> or <b>3</b><br>\n";
}
}
break;
}
default: {
$retval = "<p class='h3red'>Error<BR>Unable to data<BR>Data Type unknown</p>\n";
break;
}
} // end switch
return $retval;
} // end ValadateInput
}
// ---------------- End of Functions
// ---------------- Start of Code
{ // Session Redirect
if (!isset($_SESSION['user_id'])) {
echo "<p>You have not logged in</p>";
if (!isset($act)) {
$act = "login";
} else {
// set act to login unless it is set to login or check_login
if ($act == "login" or $act == "check_login") {
// Do nothing
} else {
$act = "login";
// Need to get session vars set (ie user_id)
}
}
} else {
if (!isset($act)) {
$act = "menu";
}
// Here is where we check to see if the password/access has excluded person from executing!
$qpass_ok = "select id
from $dbf.s_usr
where name = $d_quote$user_name$d_quote and
pass = $d_quote$password$d_quote and
id = $d_quote$user_id$d_quote";
$rpass_ok = $dblink->query($qpass_ok) or die("Error line 234" . $dblink->error);
$found = $rpass_ok->num_rows;
if ($found > 0) { // user/pass is ok
$qaccess_ok = "select usr_access
from $dbf.s_usr_prog_x
where s_usr_id = $d_quote$user_id$d_quote and
s_prog_id = $d_quote$prog_id$d_quote";
$raccess_ok = $dblink->query($qaccess_ok) or die("Error line 241" . $dblink->error);
$found = $raccess_ok->num_rows;
if ($found > 0) { // we have a match, just set access (in case it changed)
//$act = "menu";
$row = $raccess_ok->fetch_array(MYSQLI_ASSOC);
$new_usr_access = $row['usr_access'];
// now make sure that the session knows about it.
if ($new_usr_access <> $usr_access) {
$_SESSION['usr_access'] = $new_usr_access;
$usr_access = $new_usr_access;
}
$dblink->select_db($mydbf) or die("Error contacting inventory DBF " . $dblink->error);
} else { // not allowed!
$act = "login";
}
} else { // need to login cause usr/pass no longer valid!
$act = "login";
}
}
} // End of Session Redirect
switch ($act) {
case "activity": {
mybanner("Invntory Activity", $dblink, $css_include_file, $title);
if (($_SESSION['my_cat_id'] == '') || (!isset($_SESSION['my_cat_id']))) {
echo "<p>No Catigory Set!</p>";
} else {
$q = "select * from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
$r = $dblink->query($q) or die ("Error Getting info from $dbf_prefix" . "_item in act in " . $dblink->error);
if ($r->num_rows > 0) {
$row = $r->fetch_array(MYSQLI_ASSOC);
$s_desc = $row["s_desc"];
$l_desc = $row["l_desc"];
$on_hand = $row["my_count"];
echo "<p>$s_desc</p>";
}
$q = "select * from $dbf_prefix" . "_trans where prod_id = $d_quote$my_id$d_quote order by my_date, my_time";
$r = $dblink->query($q) or die ("Error Getting history from $dbf_prefix" . "_trans in act activity " . $dblink->error);
$color = 1;
echo "<td><center><IMG title='$l_desc' src='./pics/" . $my_cat_id . "_$my_id" . ".jpg'></center>";
if ($r->num_rows > 0) {
echo "<center><table border='1' cellspacing='0' cellpadding='4'>\n";
while ($row = $r->fetch_array(MYSQLI_ASSOC)) {
$color = MeColorTR($color, 1);
$my_date = DosDate($row["my_date"]);
$my_time = $row["my_time"];
$qty = $row["qty"];
$my_usr = $row["my_usr"];
$my_note = $row["my_note"];
if ($qty > 0) {
echo "<td><IMG src='add.png'>";
} else {
echo "<td><IMG src='minus.png'>";
}
echo "$my_date</td>";
echo "<td>$my_time</td>";
echo "<td>$qty</td>";
echo "<td>$my_usr</td>";
echo "<td>$my_note</td>";
echo "</tr>\n";
}
} else {
echo "<p><h1>No history Found!</h1></p>";
}
echo "</table></center><br><br>";
}
NavBar($cgi, $act, $usr_access, $copyrite);
break;
}
case "check_login": {
shortbanner("Verifying Login", $dblink, $css_include_file, $title);
$err_str_start = "This is a major security flaw<br>Please contact support<br>Fatal Error<br>";
$err_str = "";
$user_name = $_POST['user_name'];
$password = $_POST['password'];
// first let's do some self enrollment
// Is the Program enrolled in the Database?
$q = "select id from $dbf.s_prog where name = $d_quote$cgi$d_quote";
$r = $dblink->query($q) or die("Error line 229" . $dblink->error);
$found = $r->num_rows;
if ($found < 1) { // time to enroll!
$comment = "Name:" . chr(13) . "General:" . chr(13) . "Features:" . chr(13) . "Model:";
$q = "insert into $dbf.s_prog set name = $d_quote$cgi$d_quote, comment = $d_quote$comment$d_quote";
$r = $dblink->query($q) or die("Error line 234" . $dblink->error);
echo "<p>Enrolled $cgi</p>";
// it is now enrolled!
}
// Is the User in the Database with matching password?
$q = "select a.id
from $dbf.s_usr a, $dbf.s_prog b, $dbf.s_usr_prog_x c
where a.name = $d_quote$user_name$d_quote and a.pass = $d_quote$password$d_quote and
b.id = c.s_prog_id and a.id = s_usr_id";
//echo "<br><br>$q<br><br>";
$r = $dblink->query($q) or die("Error line 342" . $dblink->error);
$found = $r->num_rows;
if ($found < 1) { // User is not in database
echo "<p class='trademark'>Access Forbidden!</p>";
echo "<p>User $user_name not on File<br>or password does not match<br><br></p><p>Access to Caplin Inventory Denied!</p>";
//exit;
} else { // is this person registered with permission to this program?
$row = $r->fetch_array(MYSQLI_ASSOC);
$user_id = $row["id"]; // this is the user id
// what is the program id??
$q = "select id from $dbf.s_prog where name = $d_quote$cgi$d_quote";
$r = $dblink->query($q) or die("Error line 259" . $dblink->error);
//echo "<br><br>$q<br><br>";
$row = $r->fetch_array(MYSQLI_ASSOC);
$prog_id = $row['id'];
// prepair the SQL to check user_id allows access to program in s_usr_prog table
$q = "select id, usr_access
from $dbf.s_usr_prog_x
where s_usr_id = $d_quote$user_id$d_quote and s_prog_id = $d_quote$prog_id$d_quote";
$r = $dblink->query($q) or die("Error line 266" . $dblink->error);
//echo "<br><br>$q<br><br>";
$found = $r->num_rows;
if ($found == 0) { //Houston, we have a problem
echo "<p class='trademark'>Access Forbidden!</p>";
echo "<p>User $user_name does not have access to $cgi</p>";
//exit;
} else {
$row = $r->fetch_array(MYSQLI_ASSOC);
$usr_access = $row["usr_access"];
$_SESSION['user_name'] = $user_name;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;
$_SESSION['usr_access'] = $usr_access;
$_SESSION['prog_id'] = $prog_id;
echo "<p>$user_name is set to access level $usr_access</p>";
}
}
NavBar($cgi, $act, 0, $copyrite);
break;
}
case "del": {
if (($_SESSION['my_cat_id'] == '') || (!isset($_SESSION['my_cat_id']))) {
mybanner("Delete Item and History", $dblink, $css_include_file, $title);
echo "<p>No Catigory Set!</p>";
} else {
$my_cat_id = $_SESSION['my_cat_id'];
if (isset($cargo)) {
mybanner("Confirmation of Deleting item and item history", $dblink, $css_include_file, $title);
// Remove Transactions
$q = "delete from $dbf_prefix" . "_trans where prod_id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
$r = $dblink->query($q) or die ("Error removing history from $dbf_prefix" . "_trans in act del " . $dblink->error);
// Remove Item
$q = "delete from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
$r = $dblink->query($q) or die ("Error removing item from $dbf_prefix" . "_item in act del " . $dblink->error);
// Remove Picture
// Remember to chmod 0777 for that dir or it will not delete
$delete_file = $_SERVER['DOCUMENT_ROOT'] . "/pics/" . "$my_id" . ".jpg";
$delete_file = "pics/" . $my_cat_id . "_" . $my_id . ".jpg";
if (file_exists($delete_file)) {
unlink($delete_file);
}
echo "<p><h1>Item has been scrubbed from inventory</h1></p>";
} else {
$my_id = $_GET["my_id"];
$q = "select * from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
$r = $dblink->query($q) or die ("Error Getting info from $dbf_prefix" . "_item in act in " . $dblink->error);
if ($r->num_rows > 0) {
mybanner("Delete Item and History", $dblink, $css_include_file, $title);
$row = $r->fetch_array(MYSQLI_ASSOC);
$s_desc = $row["s_desc"];
$l_desc = $row["l_desc"];
$on_hand = $row["my_count"];
echo "<p>$s_desc</p>";
echo "<p><IMG title = '$l_desc' src='./pics/" . $my_cat_id . "_$my_id" . ".jpg'></p>";
echo "<p><h1>You are about to Remove the above item from Inventory<br>This includes all History</h1></p>";
echo "<form class='new-single-red' action='$cgi' method='post'>\n";
echo "<input type='hidden' name='act' value='del'>\n";
echo "<input type='hidden' name='cargo' value='comment'>\n";
echo "<input type='hidden' name='my_id' value='$my_id'>\n";
echo "<input type='submit' class='hulk-button' value='Remove'>\n";
echo "</form>\n";
} else {
mybanner("Delete Item and History", $dblink, $css_include_file, $title);
echo "<p>NO ITEM FOUND!</p>\n";
}
}
}
NavBar($cgi, $act, $usr_access, $copyrite);
break;
}
case "make_cat": {
if (isset($cargo)) {
$desc = FixMyString($desc);
$err_str = ValadateInput($desc, "name", "Name");
// next need to make sure that the start date is less than the beginning date
if (strlen($err_str) > 5) {
mybanner("ERROR", $dblink, $css_include_file, $title);
echo $err_str;
echo "<br><center><font size=+2>Try Again</font></center><br>";
} else {
mybanner("New Item Creation", $dblink, $css_include_file, $title);
$q = "insert into $dbf_prefix" . "_cat set my_desc = $d_quote$desc$d_quote";
$r = $dblink->query($q) or die("Error creating new item in act $act" . $dblink->error);
echo "<br><center><font size=+2>Category $desc was Created</font></center><br>";
}
} else {
mybanner("Select/Create Category", $dblink, $css_include_file, $title);
// Show the Categories
$q = "select * from $dbf_prefix" . "_cat order by my_desc";
$r = $dblink->query($q) or die("Error listing categories act $act" . $dblink->error);
if ($r->num_rows > 0) {
echo "<p><h1>Select</h1></p>";
echo "<center><table border='0' cellspacing='0' cellpadding='4'>\n";
echo "<form action = '$cgi'>";
echo "<input type='hidden' name='cat' value='comment'>\n";
echo "<input type='hidden' name='act' value='list'>\n";
echo "<tr><td><center><select name='my_cat_id'>";
while ($row = $r->fetch_array(MYSQLI_ASSOC)) {
$my_desc = $row["my_desc"];
$my_id = $row["id"];
echo "<option value='$my_id'>$my_desc</option>";
}
echo "</center></td></tr><tr><td><input type='submit' class='hulk-button' value='Select Category'>\n";
echo "</form>\n";
echo "</td></tr></table><br><br>";
} else {
echo "<p>No Categories Found</p>";
}
echo "<p><h1>Create New</h1></p>";
echo "<form class='new-single' action='$cgi' method='post'>\n";
echo "<input type='hidden' name='act' value='$act'>\n";
echo "<input type='hidden' name='cargo' value='comment'>\n";
echo "<p class='center'>Name: <input type='text' name='desc' maxlength='40' size='20' ></p>\n";
echo "<input type='submit' class='hulk-button' value='Create Category'>\n";
echo "</form>\n";
echo "<p></p>";
// Need to have a delete function here using new_single_red
/*
// Remove Transactions
$q = "delete from $dbf_prefix" . "_trans where prod_id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
// Remove Item
$q = "delete from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
// Remove Picture
// Remember to chmod 0777 for that dir or it will not delete
$mask = "pics/" . $my_cat_id . "_*.jpg";
array_map( "unlink", glob( $mask ) );
*/
}
NavBar($cgi, $act, $usr_access, $copyrite);
break;
}
case "modify": {
if (isset($cargo)) {
$s_desc = FixMyString($s_desc);
$l_desc = FixMyString($l_desc);
$err_str = ValadateInput($s_desc, "name", "Name");
$err_str = $err_str . ValadateInput($l_desc, "name", "Ordering Information");
if (strlen($err_str) > 5) {
mybanner("ERROR", $dblink, $css_include_file, $title);
echo $err_str;
echo "<br><center><font size=+2>Try Again</font></center><br>";
} else {
mybanner("Confirm Item Modification", $dblink, $css_include_file, $title);
$q = "update $dbf_prefix" . "_item set s_desc = $d_quote$s_desc$d_quote, l_desc = $d_quote$l_desc$d_quote where id = $d_quote$my_id$d_quote";
$r = $dblink->query($q) or die ("Error Updating Descriptions from $dbf_prefix" . "_item in act modify " . $dblink->error);
echo "<p><h1>Item has been modified</h1></p>";
}
} else {
mybanner("Modify Item", $dblink, $css_include_file, $title);
$q = "select * from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote";
$r = $dblink->query($q) or die ("Error Getting Description from $dbf_prefix" . "_item in act modify " . $dblink->error);
if ($r->num_rows > 0) {
$row = $r->fetch_array(MYSQLI_ASSOC);
$s_desc = $row["s_desc"];
$l_desc = $row["l_desc"];
echo "<p>$s_desc</p>";
echo "<td><center><IMG title='$l_desc' src='./pics/" . $my_cat_id . "_$my_id" . ".jpg'></center>";
echo "<form class='new-single' action='$cgi' method='post'>\n";
echo "<input type='hidden' name='act' value='modify'>\n";
echo "<input type='hidden' name='cargo' value='comment'>\n";
echo "<input type='hidden' name='my_id' value='$my_id'>\n";
echo "<p class='center'>Name: <input type='text' name='s_desc' maxlength='40' size='20' value='$s_desc'></p>\n";
echo "Ordering Information:<br><textarea name='l_desc' rows='8' cols='45' >$l_desc
</textarea><br><br><input type='submit' class='hulk-button' value='Update Item'>\n";
echo "</form>\n";
} else {
echo "<p><h1>Item not found!</h1></p>";
}
echo "</table></center><br><br>";
}
NavBar($cgi, $act, $usr_access, $copyrite);
break;
}
case "trans": {
if (($_SESSION['my_cat_id'] == '') || (!isset($_SESSION['my_cat_id']))) {
mybanner("Transaction", $dblink, $css_include_file, $title);
echo "<p>No Catigory Set!</p>";
} else {
$my_cat_id = $_SESSION['my_cat_id'];
if (isset($cargo)) {
$in = FixMyString($in);
$error = "none";
$my_note = FixMyString($my_note);
$err_str = ValadateInput($in, "no_zero_num", "Items to add/remove");
$err_str = $err_str . ValadateInput($my_note, "name", "Note");
if (strlen($err_str) > 5) {
mybanner("ERROR", $dblink, $css_include_file, $title);
echo $err_str;
echo "<br><center><font size=+2>Try Again</font></center><br>";
} else {
if ($add == "in") {
mybanner("Record Received", $dblink, $css_include_file, $title);
echo "<p>You have selected to add $in items</p>\n";
} else {
// Make sure that you have at least these many items to remove
mybanner("Record Outgoing", $dblink, $css_include_file, $title);
echo "<p>You have selected to Remove $in items</p>\n";
$q = "select my_count from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote and cat_id = $d_quote$my_cat_id$d_quote";
$r = $dblink->query($q) or die ("Error counting items in $dbf_prefix" . "_trans in act in " . $dblink->error);
$row = $r->fetch_array(MYSQLI_ASSOC);
$in_stock = $row["my_count"];
if ($in_stock < $in) { // Stop and show error
echo "<p class='h3red'>You have selected to Remove more items than you have in stock<br>DENIED!</p>\n";
$error = "error";
} else { // Continue
$in = $in * -1;
}
}
}
if ($error == "none") {
$my_id = $_POST["my_id"];
$add = $_POST["add"];
$q = "insert into $dbf_prefix" . "_trans set prod_id = $d_quote$my_id$d_quote
, cat_id = $d_quote$my_cat_id$d_quote
, qty = $d_quote$in$d_quote
, my_usr = $d_quote" . $_SESSION['user_name'] . "$d_quote
, my_date = $d_quote" . LinuxDate($mydate) . "$d_quote
, my_time = $d_quote" . date('H:i', time()) . "$d_quote
, my_ip = $d_quote" . $REMOTE_ADDR . "$d_quote
, my_note = $d_quote$my_note$d_quote
";
// Create the entry and update the item count
$r = $dblink->query($q) or die ("Error entering info into $dbf_prefix" . "_trans in act in " . $dblink->error);
$q = "select sum(qty) as mynum from $dbf_prefix" . "_trans where prod_id = $d_quote$my_id$d_quote";
$r = $dblink->query($q) or die ("Error counting items in $dbf_prefix" . "_trans in act in " . $dblink->error);
$row = $r->fetch_array(MYSQLI_ASSOC);
$now_count = $row["mynum"];
$q = "update $dbf_prefix" . "_item set my_count = $d_quote$now_count$d_quote where id = $d_quote$my_id$d_quote";
$r = $dblink->query($q) or die ("Error updating count items in $dbf_prefix" . "_item in act in " . $dblink->error);
}
} else {
if ($add == "in") {
mybanner("Record Received", $dblink, $css_include_file, $title);
} else {
mybanner("Record Outgoing", $dblink, $css_include_file, $title);
}
$my_id = $_GET["my_id"];
$q = "select * from $dbf_prefix" . "_item where id = $d_quote$my_id$d_quote";
$r = $dblink->query($q) or die ("Error Getting info from $dbf_prefix" . "_item in act in " . $dblink->error);
if ($r->num_rows > 0) {
$row = $r->fetch_array(MYSQLI_ASSOC);
$s_desc = $row["s_desc"];
$l_desc = $row["l_desc"];
$on_hand = $row["my_count"];
echo "<p>$s_desc</p>";
echo "<p><IMG title='$l_desc' src='./pics/" . $my_cat_id . "_$my_id" . ".jpg'></p>";
if ($add == "in") {
echo "<form class='new-single' action='$cgi' method='post'>\n";
} else {
echo "<form class='new-single-red' action='$cgi' method='post'>\n";
}
echo "<input type='hidden' name='act' value='trans'>\n";
echo "<input type='hidden' name='cargo' value='comment'>\n";
echo "<input type='hidden' name='add' value='$add'>\n";
echo "<input type='hidden' name='my_id' value='$my_id'>\n";
echo "<p class='center'># of $s_desc to ";
if ($add == "in") {
echo "add:";
} else {
echo "Subtract:";
}
echo " <input type='text' name='in' maxlength='4' size='5' ></p>\n";
echo "<p class='center'>Note: <input type='text' name='my_note' maxlength='132' size='40' ></p>\n";
if ($add == "in") {
echo "<input type='submit' class='hulk-button' value='Add'>\n";
} else {
echo "<input type='submit' class='hulk-button' value='Remove'>\n";
}
echo "</form>\n";
} else {
mybanner("Record Received", $dblink, $css_include_file, $title);
echo "<p>NO ITEM FOUND!</p>\n";
}
}
}