PageRenderTime 10ms CodeModel.GetById 6ms app.highlight 51ms RepoModel.GetById 11ms app.codeStats 1ms

/pvaccine.php

https://github.com/johntrombly/vtracnow
PHP | 2349 lines | 1737 code | 105 blank | 507 comment | 274 complexity | b7d74c46e905bcc2c9f72658a850d40c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2// http://nathanj.github.io/gitguide/tour.html
   3$crlf = chr(13) . chr(10);
   4$d_quote = chr(34);
   5$cgi = $_SERVER['PHP_SELF'];
   6include ('include.txt');
   7$bio_table = "vt_test_biological";
   8$detail_table = "vt_test_detail";
   9$email_table = "vt_test_email";
  10$man_table = "vt_test_man";
  11$mydbf = "vaccine";
  12// $PHP_AUTH_USER is not used for the test application
  13// Set a var called $user_name
  14// The commented text is not changed
  15$user_name = "Test Web User";
  16$usr_access = "100";
  17// for pvaccine.php use $mytable = "p_detail";
  18// for pvaccine_state.php use $mytable = $mytable = "p_detail_mcd";
  19//$mytable = "p_detail"; // pvaccine.php
  20$mytable = $detail_table; // pvaccine.php
  21$content = "The following is an automated message from the Commercial Pediatric Vaccine Tracker.\r\nPlease do not respond via email reply because the reply mail box is bogus.\r\n\r\nMessage: %%message%%\r\n\r\n";
  22$from_string_addr = "From: Vaccine Tracker\r\n" ."Reply-To: webmaster@asthmaandallergy.com\r\n" ."X-Mailer: PHP/" . phpversion();
  23//$mytable = "p_detail_mcd"; // pvaccine_state.php
  24// in mybanner change the backgrounds pvaccine.php and pvaccine_state.php
  25  // use the top one for Pedi Commercial vaccines ---pvaccine.php---
  26  //$bk = "background='/backgrounds/water003.jpg'";
  27  // use the next one for Pedi State vaccines ---pvaccine_state.php--
  28  //$bk = "background='/backgrounds/comp010.jpg'";
  29// Also comment out the proper item below in the mybanner section  
  30//  echo "<title>Commercial Pediatric Vaccine Tracker</title>\n";
  31//  echo "<title>State Pediatric Vaccine Tracker</title>\n";  
  32  
  33
  34$exp_window = 30;
  35// time needs to have the format of 99:99 or else the sort will not work properly
  36// ie order by r_date, r_time ASC as well as c_date, c_time ASC!!!
  37// vaccine_list and expire seem to be the same code!
  38// Need to consolidate if true
  39// Keep expire and remove vaccine_list
  40//-- 
  41//-- Database: `inventory`
  42//-- 
  43//-- --------------------------------------------------------
  44//-- 
  45//-- Table structure for table `biological`
  46//-- 
  47//CREATE TABLE `biological` (
  48//  `id` double NOT NULL auto_increment,
  49//  `name` varchar(32) NOT NULL default '',
  50//  `state_memo` text NOT NULL,
  51//  `comm_memo` text NOT NULL,
  52//  PRIMARY KEY  (`id`)
  53//) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
  54//
  55//-- --------------------------------------------------------
  56//-- 
  57//-- Table structure for table `detail`
  58//-- 
  59//CREATE TABLE `detail` (
  60//  `id` double NOT NULL auto_increment,
  61//  `biological_id` double NOT NULL default '0',
  62//  `man_id` double NOT NULL default '1',
  63//  `exp_date` date NOT NULL default '0000-00-00',
  64//  `lot_num` varchar(80) NOT NULL default '',
  65//  `r_name` varchar(30) NOT NULL default '',
  66//  `r_date` date NOT NULL default '0000-00-00',
  67//  `r_time` varchar(5) NOT NULL default '',
  68//  `r_ip` varchar(15) NOT NULL default '',
  69//  `consumed_ynd` enum('Y','N','D') NOT NULL default 'N',
  70//  `c_name` varchar(30) NOT NULL default '',
  71//  `c_date` date NOT NULL default '0000-00-00',
  72//  `c_time` varchar(5) NOT NULL default '',
  73//  `c_ip` varchar(15) NOT NULL default '',
  74//  `note` varchar(132) NOT NULL default '',
  75//  PRIMARY KEY  (`id`),
  76//  KEY `exp_date` (`exp_date`),
  77//  KEY `r_date` (`r_date`),
  78//  KEY `c_date` (`c_date`),
  79//  KEY `bilogical_id` (`biological_id`)
  80//) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=136 ;
  81
  82//-- 
  83//-- Table structure for table `vt_test_man`
  84//-- 
  85//
  86//CREATE TABLE `vt_test_man` (
  87//  `id` double NOT NULL auto_increment,
  88//  `name` varchar(32) NOT NULL default '',
  89//  PRIMARY KEY  (`id`)
  90//) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
  91//
  92//-- 
  93//-- Dumping data for table `vt_test_man`
  94//-- 
  95//
  96//INSERT INTO `vt_test_man` (`id`, `name`) VALUES 
  97//(1, 'unknown'),
  98//(2, 'GSK'),
  99//(3, 'Merck'),
 100//(4, 'Norvatis'),
 101//(5, 'Sanofi'),
 102//(6, 'Wyeth'),
 103//(7, 'MedImmune');
 104
 105
 106
 107
 108// below is the short version of the program name ie secure.html
 109// use this one if we want the security to work reguardless of where the program lives
 110//$cgi = substr($PHP_SELF,strrpos($cgi,"/")+1);
 111
 112
 113// Select host here
 114$myHost = "local";
 115//$myHost = "ras";
 116//$myHost = "nec";
 117// end of Selection host
 118
 119// Make dbf connection here ($dbh)
 120    $dbh = mysql_connect('localhost', 'vtracuser','74mgMqGeL1nySu7xzMfl') or die("unable to open database");
 121    // $mydbf can change
 122    $mydbf = "vaccine";
 123
 124mysql_select_db("$mydbf") or die("unable to access database");
 125
 126
 127/*
 128// security code
 129if (!isset($PHP_AUTH_USER)) {
 130  Header("WWW-Authenticate: Basic realm=\"Pediatric Vaccine Tracker\"");
 131  Header("HTTP/1.0 401 Unauthorized");
 132  echo "Cancled by user\n";
 133  exit;
 134} else {
 135  // first let's do some self enrollment
 136  $q = "select count(id) from s_prog where name = $d_quote$cgi$d_quote";
 137  $r = mysql_query($q) or die(mysql_error());
 138  $found = mysql_result($r, 0, 0);
 139  if ($found < 1) { // time to enroll!
 140    $comment = "Name:" . chr(13) . "General:" . chr(13) . "Features:" . chr(13) . "Model:";
 141    $q = "insert into s_prog set name = $d_quote$cgi$d_quote, comment = $d_quote$comment$d_quote"; 
 142    $r = mysql_query($q) or die(mysql_error());
 143    // it is now enrolled!
 144  }
 145  $q = "select a.id
 146            from s_usr a, s_prog b, s_usr_prog_x c
 147            where a.name = $d_quote$PHP_AUTH_USER$d_quote and a.pass = $d_quote$PHP_AUTH_PW$d_quote and 
 148            b.id = c.s_prog_id and a.id = s_usr_id";
 149  $r = mysql_query($q) or die(mysql_error());
 150  $found = mysql_num_rows($r);
 151  if ($found < 1) { // User is not in database
 152    echo '<center><font size="+2">Access Forbidden!</font></center>';
 153    echo "<center><font size='+2'>User $PHP_AUTH_USER not on File<br>or password does not match</font></center>";
 154    exit;
 155  } else { // is this person registered with permission to this program?
 156    $row = mysql_fetch_array($r);
 157    $user_id = $row["id"]; // this is the user id
 158    // what is the program id??
 159    $q = "select id from s_prog where name = $d_quote$cgi$d_quote";
 160    $r = mysql_query($q) or die(mysql_error());
 161    $prog_id = mysql_result($r, 0, 0);
 162    // prepair the SQL
 163    $q = "select id, usr_access from s_usr_prog_x where s_usr_id = $d_quote$user_id$d_quote and s_prog_id = $d_quote$prog_id$d_quote";
 164    $r = mysql_query($q) or die(mysql_error());
 165    $found = mysql_num_rows($r);
 166    if ($found == 0) { //Houston, we have a problem
 167      echo '<center><font size="+2">Access Forbidden!</font></center>';
 168      echo "<center><font size='+2'>User $PHP_AUTH_USER does not have access to $cgi</font></center>";
 169      exit;
 170    } else {
 171      $row = mysql_fetch_array($r);
 172      $usr_access = $row["usr_access"];
 173    }
 174  }
 175}
 176// end of expermental code
 177//-------------------
 178*/
 179
 180
 181function SendEmail($comment, $bio_table, $detail_table, $email_table)
 182{
 183	$content = "The following is an automated message from the Commercial Pediatric Vaccine Tracker.\r\nPlease do not respond via email reply because the reply mail box is bogus.\r\n\r\nMessage: %%message%%\r\n\r\n";
 184	$from_string_addr = "From: Commercial Vaccine Tracker\r\n" ."Reply-To: webmaster@asthmaandallergy.com\r\n" ."X-Mailer: PHP/" . phpversion();
 185	$q = "select * from $bio_table order by name";
 186	$r = mysql_query($q) or die(mysql_error());
 187	$message = "The following is a listing of the existing Commercial Pediatric Vaccine Inventory\n";
 188	if (mysql_num_rows($r) > 0) {
 189		while ($row = mysql_fetch_array($r)) {
 190			$bio_id = $row["id"];
 191			$name = $row["name"];
 192			$q2 = "select count(*) as mycount from $detail_table where biological_id = '$bio_id' and consumed_ynd = 'N'";
 193			$r2 = mysql_query($q2) or die(mysql_error());
 194			$row2 = mysql_fetch_array($r2);			  
 195			$mycount = $row2["mycount"];
 196			if ($mycount > 0) {
 197				$message = $message . "$mycount - $name\n";
 198			}
 199		}
 200   } else {
 201		$message = $message . "No Stock to report for the Commercial Pediatric Vaccine Inventory";
 202   }
 203	$q = "select * from $bio_table order by name";
 204	$r = mysql_query($q) or die(mysql_error());
 205	$message = $message . "\n\nThe following is a listing of the existing State Pediatric Vaccine Inventory\n";
 206	if (mysql_num_rows($r) > 0) {
 207		while ($row = mysql_fetch_array($r)) {
 208			$bio_id = $row["id"];
 209			$name = $row["name"];
 210			$q2 = "select count(*) as mycount from $detail_table where biological_id = '$bio_id' and consumed_ynd = 'N'";
 211			$r2 = mysql_query($q2) or die(mysql_error());
 212			$row2 = mysql_fetch_array($r2);			  
 213			$mycount = $row2["mycount"];
 214			if ($mycount > 0) {
 215				$message = $message . "$mycount - $name\n";
 216			}
 217		}
 218		$content = str_replace("%%message%%", $message, $content);
 219	} else {
 220		$message = $message . "No Stock to report for the State Pediatric Vaccine Inventory";
 221	}
 222//	$content = $comment . "\n" . $content;
 223	$q = "select * from $email_table where active_yn = 'Y'";
 224	$r = mysql_query($q) or die(mysql_error());
 225	$content = $comment . "\n" . $content;
 226	while ($row = mysql_fetch_array($r)) {
 227		$to = $row["addr"];
 228		mail($to, "Automated Phone Message", $content, $from_string_addr);
 229//		mail($to, "$comment", $content, $from_string_addr);
 230//		echo "<br><center>Message has been sent to $to</center><br>";
 231	}
 232} // end SendEmail
 233
 234//-------------------
 235function ValadateInput($txt, $type, $comment)
 236{
 237// send text and a type and get back an error comment
 238// if the error comment is empty, then it is ok
 239$retval = "";
 240switch ($type) {
 241  case "sname";
 242    $retval = "";
 243    if (strlen($txt) < 2) {
 244      $retval = "$comment '$txt' is too short<BR>\nMust be at least 2 characters long<br>\n";
 245    } 
 246    break;
 247  case "name";
 248    $retval = "";
 249    if (strlen($txt) < 3) {
 250      $retval = "$comment '$txt' is too short<BR>\nMust be at least 3 characters long<br>\n";
 251    } 
 252    break;
 253  case "date":
 254    $err_date = "Invalid date format for $comment: <BR>Cannot determine '$txt' as being a valid date<BR>";
 255    $retval = "";
 256    if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})", $txt, $regs)) {
 257      $mymonth = $regs[1];
 258      $mydate = $regs[2];
 259      $myyear = $regs[3];
 260      settype($mymonth, "integer");
 261      settype($mydate, "integer");
 262      settype($myyear, "integer");
 263      if ($myyear < 1 or $myyear > 2071) {
 264        $retval .= "<CENTER>$err_date The year is in question<br></CENTER><BR>";
 265      } else {
 266        if (($mymonth < 1) or ($mymonth > 12)) $retval .= "<CENTER>$err_date Month should be between 1 and 12<br></CENTER><BR>";
 267        if ($mydate < 1 or $mydate > 31) {
 268          $retval .= "<CENTER>$err_date No month has more than 31 days or less than 1 day<br></CENTER><BR>";
 269        } else {
 270          if ($mymonth == 4 or $mymonth == 6 or $mymonth == 9 or $mymonth == 11) {
 271            if ($mydate == 31) $retval .= "<CENTER>$err_date Only 30 days in this month (month #$mymonth)<BR></CENTER><BR>";
 272          } 
 273	  if ($mymonth == 2) {
 274	    if ($mydate > 29) $retval .= "<CENTER>$err_date There can never be more than 29 days in ANY Febuary<br></CENTER><BR>";
 275	    if ($mydate == 29 and $myyear % 4 > 0) $retval .= "<CENTER>$err_date Only 28 days in THIS Febuary<br></CENTER><BR>";
 276	  }
 277        } 
 278      } 
 279    } else {
 280      $retval .= "<center>$err_date Try using the MM/DD/YYYY format<BR></CENTER><BR>";
 281    } 
 282    break;
 283  case "email":
 284    $at_loc = strpos($txt, "@");
 285    $email_exp = "^[a-z0-9\._-]+@[a-z0-9\._-]+\.+[a-z]{2,3}$";
 286    if ($at_loc < 2) {
 287      $retval .= "Please check the prefix and @ sign<br>\n";
 288    } 
 289    $firstdot = strpos($txt, ".");
 290    $afterdot = substr($txt, $firstdot + 1);
 291    if ($firstdot < 1) {
 292      $retval .= "Please check the suffix for accuracy.<br>\n";
 293      $retval .= "(It should include a .com,.net,.org,.gov,.mil, or other)<br>\n";
 294      // 3/26/2003 jbt
 295      // Found email address with a dot prior to the @ ie john.trombly@goofy.org
 296      // making sure that there is a . after the @ and not allowing more than 2 dots prior to the @
 297    } else {
 298      if ($at_loc > $firstdot + strpos($afterdot, ".")) {
 299        $retval .= "Max of one dot prior to the @ sign<br>and<br>must have a dot after the @ sign<br>\n";
 300      } 
 301    } 
 302    if (!eregi($email_exp, $txt)) {
 303      $retval .= "Check Email address again for valid form";
 304    }
 305    if (strlen($retval) > 0) {
 306      $retval = "<center>Sorry. This $comment '$txt' seems wrong.<br>\n" . $retval . "</center><br>\n";
 307    } 
 308    break;
 309  case "num":
 310    if (strlen($txt) < 1) {
 311      $retval = "$comment is too short<BR>\nPut $comment in number format ie 999<br>\n";
 312    } else {
 313      if (!ereg("(^[0-9]{1,6})$", $txt)) {
 314        $retval = "$comment must be in this format<BR>9999<br>\n";
 315      } 
 316    } 
 317    if (strlen($retval) > 0) {
 318      $retval = "<center>Error in $comment ($txt).<br>\n" . $retval . "</center><br>\n";
 319    } 
 320    break;
 321  case "num62":
 322    if (strlen($txt) < 1) {
 323      $retval = "$comment is too short<BR>\nPut $comment in number format ie 999.99<br>\n";
 324    } else {
 325      if (!ereg("(^[0-9]{1,3}.[0-9]{1,2})$", $txt)) {
 326        $retval = "$comment must be in this format<BR>999.99<br>\n";
 327      } 
 328    } 
 329    if (strlen($retval) > 0) {
 330      $retval = "<center>Error in $comment ($txt).<br>\n" . $retval . "</center><br>\n";
 331    } 
 332    break;
 333  case "phone":
 334    if (strlen($txt) < 12) {
 335      $retval = "$comment is too short<BR>\nPut phone number in 999-999-9999<br>\n";
 336    } else {
 337      if (!ereg("([0-9]{3,3})-([0-9]{3,3})-([0-9]{3,3})", $txt)) {
 338        $retval = "Phone number must be in this format<BR>999-999-9999<br>\n";
 339      } 
 340    } 
 341    if (strlen($retval) > 0) {
 342      $retval = "<center>Error in $comment ($txt).<br>\n" . $retval . "</center><br>\n";
 343    } 
 344    break;
 345  case "time":
 346    if (strlen($txt) != 5) {
 347      $retval = "<br>$comment is not 5 characters long<br>Put time string like 99:99";
 348    } else {
 349      if (!ereg("([0-2]{1,1})([0-9]{1,1}):([0-5]{1,1})([0-9]{1,1})", $txt)) {
 350        $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";                                                                                                                }
 351    }
 352    break;
 353  case "time15":
 354    if (strlen($txt) != 5) {
 355      $retval = "<br>$comment is not 5 characters long<br>Put time string like 99:99";
 356    } else {
 357      if (!ereg("([0-2]{1,1})([0-9]{1,1}):([0-5]{1,1})([0-9]{1,1})", $txt)) {
 358        $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";
 359      } else {
 360        // 15 min or less!
 361        if (nJbtmin($txt) > 15 ) {
 362          $retval = "<br><b>$comment</b> is more than 15 min<BR>Try a setting of 15min or less<br>\n";
 363	}
 364      }
 365    }
 366    break;
 367  case "YN":
 368    if (strlen($txt) != 1) {
 369      $retval = "<br>$comment is not 1 characters long<br>Only put Y or N";
 370    } else {
 371      if ($txt != 'Y' and $txt != 'N') {
 372        $retval = "<br>$comment can only be <b>Y</b> or <b>N</b><br>\n";
 373      }
 374    }
 375    break;
 376  default:
 377    $retval = "<center>Error<BR>Unable to data<BR>Data Type unknown</center><br>\n";
 378    break;
 379}  // end switch
 380	return $retval;
 381} // end ValadateInput
 382//--------
 383 
 384function FixMyStringquote($mystring)
 385{
 386// *** ATTENTION ***
 387// Special Modified version allows single quotes to pass!
 388// Be sure that when this text is sent, double quites surround it in the SQL statement!
 389// *** ATTENTION ***
 390// This will remove the dangerous characters quotes and question mark
 391$temp = $mystring;
 392//$temp = str_replace("'", "",  $mystring); // byby single quote
 393$temp = str_replace('"', '"', $temp); // byby double quotes
 394$temp = str_replace("?", "", $temp); // byby question mark
 395$temp = str_replace("$", "", $temp); // byby Dollar sign (just for good measure
 396// no HTML tags should pass so no < or >
 397//$temp = str_replace("<", "", $temp); // byby start of HTML Tags
 398//$temp = str_replace(">", "", $temp); // byby end of HTML Tags
 399$mylen_now = strlen($temp);
 400$mylen_prior = $mylen_now + 1;
 401while ($mylen_now <> $mylen_prior) {
 402  $mylen_prior = strlen($temp);
 403  $temp = str_replace("  ", " ", $temp); // Get rid of ** ALL ** the white space!!
 404  $mylen_now = strlen($temp);
 405}
 406$bkslach = chr(92);
 407$temp = str_replace($bkslach, "", $temp); // byby Backslash because this is used to signal special characters)
 408
 409return $temp;
 410} // end of FixMyStringquote
 411
 412
 413//--------
 414function LinuxDate($date)
 415{
 416// takes a date string in MM/DD/YYYY format
 417// and returns it in YYYY-MM-DD format (for Mysql)
 418if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})", $date, $regs)) {
 419  $retval = "$regs[3]-$regs[1]-$regs[2]";
 420}
 421return $retval;
 422} //end of LinuxDate function
 423
 424//---------
 425function DosDate($date)
 426{
 427// takes a date string in YYYY-MM-DD format
 428// and returns it in MM/DD/YYYY format (for Regular People)
 429if (ereg ("([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
 430  $retval = "$regs[2]/$regs[3]/$regs[1]";
 431}
 432return $retval;
 433} //end of LinuxDate function
 434
 435//----------
 436
 437function FixMyString($mystring)
 438{
 439// *** ATTENTION ***
 440// Special Modified version allows single quotes to pass!
 441// Be sure that when this text is sent, double quites surround it in the SQL statement!
 442// *** ATTENTION ***
 443// This will remove the dangerous characters quotes and question mark
 444$temp = $mystring;
 445$temp = str_replace("'", "",  $mystring); // byby single quote
 446$temp = str_replace('"', "", $temp); // byby double quotes
 447$temp = str_replace("?", "", $temp); // byby question mark
 448$temp = str_replace("$", "", $temp); // byby Dollar sign (just for good measure
 449$temp = str_replace("&", "", $temp); // byby AND sign (makes html crankey
 450$temp = str_replace(",", "", $temp); // byby comma sign (makes html crankey as well
 451// no HTML tags should pass so no < or >
 452$temp = str_replace("<", "", $temp); // byby start of HTML Tags
 453$temp = str_replace(">", "", $temp); // byby end of HTML Tags
 454$mylen_now = strlen($temp);
 455$mylen_prior = $mylen_now + 1;
 456while ($mylen_now <> $mylen_prior) {
 457  $mylen_prior = strlen($temp);
 458  $temp = str_replace("  ", " ", $temp); // Get rid of ** ALL ** the white space!!
 459  $mylen_now = strlen($temp);
 460}
 461$bkslach = chr(92);
 462$temp = str_replace($bkslach, "", $temp); // byby Backslash because this is used to signal special characters)
 463return $temp;
 464} // end of FixMyString
 465
 466
 467function MeColorTR($count, $numCols)
 468{
 469// Puts in the color tag for a row (TR>
 470// numCols is the # of Colums desired
 471$setColor = $count % $numCols;
 472if ($setColor == 0 ) {
 473	// Here is where we plan the color for the new Row
 474	$setColor = intval($count / $numCols);
 475	$setColor = $setColor%3;
 476      switch ($setColor) {
 477        case "0":
 478          echo "\n<tr bgcolor=#DDDDDD>";
 479          break;
 480        case "1":
 481          echo "\n<tr bgcolor=#CCCCCC>";
 482          break;
 483        case "2":
 484          echo "\n<tr bgcolor=#C0C0C0>";
 485          break;
 486        case "3":
 487          echo "\n<tr>";
 488          break;
 489      } // end switch
 490}
 491  // increment the counter
 492  $retval = $count + 1;
 493  return $retval;
 494} // end of MeColorTR
 495
 496function format_time($time)
 497{
 498  $retval = $time["hours"];
 499  if (strlen(trim($retval)) < 2) $ret_val = "0" . $retvalue;
 500  if (strlen(trim($time["minutes"])) < 2) {
 501    $retval = $retval . ":0" . $time["minutes"];
 502  } else {
 503    $retval = $retval . ":" . $time["minutes"];
 504  }
 505  $retval = str_pad($retval,5,"0",STR_PAD_LEFT);
 506  return $retval;
 507} // end of format_time
 508
 509function mybanner($string, $ding,$user_name)
 510{
 511// default banner for this program
 512// in mybanner change the backgrounds pvaccine.php and pvaccine_state.php
 513  // use the top one for Pedi Commercial vaccines ---pvaccine.php---
 514  $bk = "background='/backgrounds/pa-sw-602.jpg'";
 515  $bk = "background='/backgrounds/1.gif'";
 516  $bk = "background='/backgrounds/2.gif'";
 517  $bk = "background='/backgrounds/3.gif'";
 518  $bk = "background='/backgrounds/4.gif'";
 519  $bk = "background='/backgrounds/1a.gif'";
 520  $bk = "background='/backgrounds/bg1.png'";
 521  $bk = "background='/backgrounds/bg1a.png'";
 522  $bk = "background='/backgrounds/bg1c.png'";
 523//  public_html
 524//  pa-sw-602.jpg
 525  $myheadder = "== VTRACNOW ==<br>Vaccine Tracker";
 526  // use the next one for Pedi State vaccines ---pvaccine_state.php--
 527//  $bk = "background='/backgrounds/comp010.jpg'";
 528//  $myheadder = "State Pediatric Vaccine Tracker";
 529  // use the top one for Pedi Commercial vaccines
 530  echo '<!doctype html public "-//w3c//dtd html 3.2//en">' . "\n";
 531  echo "<html>\n";
 532  echo "<head>\n";
 533//  echo "<title>$myheadder</title>\n";
 534  echo "</head>\n";
 535  switch  ($ding) {
 536    case "yes":	  
 537      echo '<body bgcolor="#ffffff"' . $bk . ' text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><bgsound src="cashregister.wav" loop="1">';
 538      break;
 539    case "foghorn":	  
 540      echo '<body bgcolor="#ffffff"' . $bk . ' text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><bgsound src="foghorn.wav" loop="1">';
 541      break;
 542    case "tadah":
 543      echo '<body bgcolor="#ffffff"' . $bk . ' text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><bgsound src="chimeup.wav" loop="1">';
 544      break;
 545    case "order":
 546      echo '<body bgcolor="#ffffff"' . $bk . ' text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><bgsound src="order.wav" loop="1">';
 547      break;
 548    default :	  
 549      echo '<body bgcolor="#ffffff"' . $bk . ' text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">';
 550      break;
 551  }
 552  echo "<center><font size='+2'><b>$myheadder Administration</b></font></center><br>\n";
 553  echo "<center>Maintain Inventory<br><font size='+2'><b>User: $user_name</b></font></center>" . "\n";
 554  echo "<center><b><font size='+2'>== $string ==</font></b></center>\n";
 555  echo '<center>===================</center>' . "\n";
 556  $mydate = getdate(time());
 557  echo "<center><b>" . $mydate["month"] . " " . $mydate["mday"] . ", " .$mydate["year"] . "</b></center><br>\n";
 558  // No Back Button!!!!!
 559  echo "<script>\n";
 560  echo "history.forward();\n";
 561  echo "</script>\n";
 562  
 563} // end of mybanner
 564
 565function NavBar($cgi, $act, $usr_access)
 566{
 567// Displays links for navigation in this program
 568  $d_quote = chr(34);
 569  echo "<center><table  width='80%' border='1' cellspacing='0' cellpadding='4'>\n";
 570  if ($usr_access > 50) {
 571	echo "<tr><td colspan='5'><center>== Main Navigation Controls $usr_access ==</center></td></tr>\n";
 572	$width = "20%";
 573  } else {
 574	echo "<tr><td colspan='4'><center>== Main Navigation Controls $usr_access ==</center></td></tr>\n";
 575	$width = "25%";
 576  }
 577  echo "<td width='$width'><center><a href='$cgi?act=menu'>List or Add Vaccine</a></center></td>\n";
 578  echo "<td width='$width'><center><a href='$cgi?act=vaccine_list'>List On-Hand</a></center></td>\n";
 579  echo "<td width='$width'><center><a href='$cgi?act=date_report'>Report by Date Range</a></center></td>\n";
 580  echo "<td width='$width'><center><a href='$cgi?act=lot_grid'>Lot Number Grid</a></center></td>\n";
 581  if ($usr_access > 50) {
 582//	echo "<td width='$width'><center><a href='$cgi?act=trash'>Remove Consume/Destroy History</a></center></td>\n";
 583  }
 584//  echo "<td width='25%'><center><a href='$cgi?act=income'>Incoming</a></center></td></tr>\n";
 585
 586  echo "</table></center>\n";
 587  if ($usr_access > 50) {
 588		echo "<br><br><center><table  width='60%' border='1' cellspacing='0' cellpadding='4'>\n";
 589		echo "<tr><td><center><a href='$cgi?act=dumpxl'>Dump All Records to Spreadsheet</a></center></td>";
 590		echo "<td><center><a href='$cgi?act=dumptxt'>Dump All Records to Text</a></center></td>";
 591		echo "</tr></table></center>";
 592  }
 593  
 594/*  
 595   $q = "select count(id) from counter where
 596act = $d_quote$act$d_quote and cgi = $d_quote$cgi$d_quote";
 597 //echo "$q<br>";
 598  $r = mysql_query($q) or die(mysql_error());
 599  $found = mysql_result($r, 0, 0);
 600  if ($found > 0) { // We have a counter
 601    $q = "select id, count from counter where act = $d_quote$act$d_quote and cgi = $d_quote$cgi$d_quote";
 602    $r = mysql_query($q) or die(mysql_error());
 603    $row = mysql_fetch_array($r);
 604    $myid = $row["id"];
 605    $mycount = $row["count"];
 606    ++$mycount;
 607    $q = "update counter set count = $d_quote$mycount$d_quote where id = $d_quote$myid$d_quote";
 608    $r = mysql_query($q) or die(mysql_error());
 609  } else {
 610    $mycount = 1;
 611    $q = "insert into counter set act = $d_quote$act$d_quote, cgi = $d_quote$cgi$d_quote, count = $d_quote$mycount$d_quote";
 612    $r = mysql_query($q) or die(mysql_error());
 613  }
 614  echo '<br><CENTER><A HREF="http://gnatbox/ccaac/index.php">Main page</A></CENTER>' . "\n";
 615  // now we have the digits to worry about. note that the text version is commented out
 616  $dig_array = array("bluesky", "curly", "default", "embwhite", "led", "led_g",
 617                                  "led_r", "links", "odometer", "plain_b", "pumpkin", "xmas");
 618  $dig_dir = "/images/digits/" . $dig_array[rand() % 11] . "/";
 619  $tempString = $mycount;
 620  $end = strlen($tempString);
 621  echo "<br><center>";
 622  //lets get the characters!
 623  for ($i = 0; $i < $end; $i++) {
 624    echo "<img src='";
 625    echo $dig_dir . substr($tempString,$i,1) . ".gif'>";
 626  }
 627
 628  echo "</center>";
 629  echo '<H1 align=right><IMG SRC="/images/php-small-white.gif" ALT="Powered by PHP!"></H1>' . "\n";
 630echo "</body></html>";
 631
 632*/
 633} // end of NavBar
 634
 635function My_Lister($bio_name, $q, $type)
 636{
 637//  $type consumed
 638      $r = mysql_query($q) or die(mysql_error());
 639      $max = mysql_num_rows($r);
 640//	  echo "<br>$q<br>";
 641      if ($max > 0) {
 642//	    echo "<hr width='45%' align=center>";
 643	    echo "<center><table  width='95%' border='1' cellspacing='0' cellpadding='4'>\n";
 644		echo "<tr bgcolor=#ffffff><td colspan=7><center>$max records found</center></td></tr>";
 645        if ($type == "received") {
 646			echo "<tr bgcolor=#ffffff><td>Lot #</td><td>Exp Date</td>
 647			  <td>Recorded Reveived by</td><td>Date</td><td>Time</td><td>Computer</td><td>Note</td>
 648			  </tr>";
 649		} else {
 650			if ($type == "destroyed") {
 651				echo "<tr bgcolor=#ffffff><td>Lot #</td><td>Exp Date</td>
 652				  <td>Recorded Destroyed by</td><td>Date</td><td>Time</td><td>Computer</td><td>Note</td>
 653				  </tr>";
 654			} else {
 655				echo "<tr bgcolor=#ffffff><td>Lot #</td><td>Exp Date</td>
 656				  <td>Recorded Consumed by</td><td>Date</td><td>Time</td><td>Computer</td><td>Note</td>
 657				  </tr>";
 658			 } 
 659		}
 660      	$color = 0;
 661        while ($row = mysql_fetch_array($r)) {
 662          $color = MeColorTR($color, 1);
 663		  $lot_num = $row["lot_num"];
 664		  $exp_date = DosDate($row["exp_date"]);
 665		  $c_name = $row["c_name"];
 666		  $c_date = DosDate($row["c_date"]);
 667//   	      $c_time = str_pad($row["c_time"],5,"0",STR_PAD_LEFT);
 668   	      $c_time = $row["c_time"];
 669          $c_ip = $row["c_ip"];
 670		  $r_name = $row["r_name"];
 671		  $r_date = DosDate($row["r_date"]);
 672//   	      $r_time = str_pad($row["r_time"],5,"0",STR_PAD_LEFT);
 673		  $r_time = $row["r_time"];	
 674          $r_ip = $row["r_ip"];
 675   	      $bio_id = $row["bio_id"];
 676		  $det_id = $row["det_id"];
 677		  $note = $row["note"];
 678		  if (strlen($note) < 1) $note = "--";
 679		  //$computer = $row["computer"];
 680		  if ($type == "received") {
 681			  echo "<td>$lot_num</td><td>$exp_date</td><td>$r_name</td>
 682				<td>$r_date</td><td>$r_time</td><td>$r_ip</td><td>$note</td>";
 683			  echo "</tr>\n"; 
 684		  } else {
 685			  echo "<td>$lot_num</td><td>$exp_date</td><td>$c_name</td>
 686				<td>$c_date</td><td>$c_time</td><td>$c_ip</td><td>$note</td>";
 687			  echo "</tr>\n"; 
 688		  }
 689        }
 690      	echo "</table></center><br><br>\n";
 691      } else {
 692        echo "<center><font size='+2'><br><font color=#ff0000>ERROR</font><br>There are no consumed $bio_name</font></center><br><br>";
 693      }
 694//	  echo "<br><br><center>Done by My_Lister</center><br>";
 695} // end of My_Lister
 696
 697
 698function Full_Lister($bio_name, $q)
 699{
 700//  $type consumed
 701      $r = mysql_query($q) or die(mysql_error());
 702      $max = mysql_num_rows($r);
 703      if ($max > 0) {
 704//	    echo "<hr width='45%' align=center>";
 705	    echo "<center><table  width='95%' border='1' cellspacing='0' cellpadding='4'>\n";
 706		echo "<tr bgcolor=#ffffff><td colspan=12><center>$max records found</center></td></tr>";
 707		echo "<tr bgcolor=#ffffff>
 708		  <td>Consumed Destroyed  or Received</td>
 709		  <td>Lot #</td><td>Exp Date</td>
 710		  <td>Recorded Reveived by</td><td>Date</td><td>Time</td><td>Computer</td>
 711		  <td>Recorded Consumed or Destroyed by</td><td>Date</td><td>Time</td><td>Computer</td>
 712		  <td>Note</td>
 713		  </tr>";
 714      	$color = 0;
 715        while ($row = mysql_fetch_array($r)) {
 716          $color = MeColorTR($color, 1);
 717		  $lot_num = $row["lot_num"];
 718		  $exp_date = DosDate($row["exp_date"]);
 719		  $r_name = $row["r_name"];
 720		  $r_date = DosDate($row["r_date"]);
 721   	      $r_time = str_pad($row["r_time"],5,"0",STR_PAD_LEFT);
 722          $r_ip = $row["r_ip"];
 723		  $c_name = $row["c_name"];
 724		  if (strlen(trim($c_name)) < 1) $c_name = "--";
 725		  $c_date = DosDate($row["c_date"]);
 726		  if ($c_date == "00/00/0000") $c_date = "--";
 727   	      $c_time = str_pad($row["c_time"],5,"0",STR_PAD_LEFT);
 728		  if ($c_time == "00000") $c_time = "--";
 729          $c_ip = $row["c_ip"];
 730		  if (strlen(trim($c_ip)) < 1) $c_ip = "--";
 731   	      $bio_id = $row["bio_id"];
 732		  $det_id = $row["det_id"];
 733		  $ynd = $row["consumed_ynd"];
 734		  if ($ynd == "Y") $ynd = "Consumed";
 735		  if ($ynd == "N") $ynd = "Received";
 736		  if ($ynd == "D") $ynd = "Destroyed";
 737		  $note = $row["note"];
 738		  if (strlen($note) < 1) $note = "--";
 739		  //$computer = $row["computer"];
 740		  echo "<td>$ynd</td><td>$lot_num</td><td>$exp_date</td>
 741		    <td>$r_name</td><td>$r_date</td><td>$r_time</td><td>$r_ip</td>
 742		    <td>$c_name</td><td>$c_date</td><td>$c_time</td>";
 743		  if ($c_ip == "--") {
 744			echo "<td>$c_ip</td>";
 745          } else {
 746			echo "<td>$c_ip</td>";
 747          }		  
 748		  echo "<td>$note</td>";
 749		  echo "</tr>\n";
 750        }
 751      	echo "</table></center><br><br>\n";
 752      } else {
 753        echo "<center><font size='+2'><br><font color=#ff0000>ERROR</font><br>There are no consumed $bio_name</font></center><br><br>";
 754      }
 755//	  echo "<br><br><center>Done by Full_Lister</center><br>";
 756} // end of Full_Lister
 757
 758function My_xls_dump($q)
 759{
 760	$r = mysql_query($q) or die(mysql_error());
 761	echo "<table>";
 762	echo "<tr><td>Vaccine</td><td>Man</td><td>Consumed Destroyed  or Received</td>
 763		  <td>Lot #</td><td>Exp Date</td>
 764		  <td>Recorded Reveived by</td><td>Date</td><td>Time</td><td>Computer</td>
 765		  <td>Recorded Consumed or Destroyed by</td><td>Date</td><td>Time</td><td>Computer</td>
 766		  <td>Notes</td></tr>";
 767	while ($row = mysql_fetch_array($r)) {
 768		$vac_name = $row["bio_name"];
 769		$man_name = $row["man_name"];
 770		$lot_num = $row["lot_num"];
 771		$exp_date = DosDate($row["exp_date"]);
 772		$r_name = $row["r_name"];
 773		$r_date = DosDate($row["r_date"]);
 774		$r_time = str_pad($row["r_time"],5,"0",STR_PAD_LEFT);
 775		$r_ip = $row["r_ip"];
 776		$c_name = $row["c_name"];
 777		if (strlen(trim($c_name)) < 1) $c_name = "--";
 778		$c_date = DosDate($row["c_date"]);
 779		if ($c_date == "00/00/0000") $c_date = "--";
 780		$c_time = str_pad($row["c_time"],5,"0",STR_PAD_LEFT);
 781		if ($c_time == "00000") $c_time = "--";
 782		$c_ip = $row["c_ip"];
 783		if (strlen(trim($c_ip)) < 1) $c_ip = "--";
 784		$bio_id = $row["bio_id"];
 785		$det_id = $row["det_id"];
 786		$ynd = $row["consumed_ynd"];
 787		if ($ynd == "Y") $ynd = "Consumed";
 788		if ($ynd == "N") $ynd = "Received";
 789		if ($ynd == "D") $ynd = "Destroyed";
 790		$note = $row["note"];
 791		if (strlen($note) < 1) $note = "--";
 792		//$computer = $row["computer"];
 793		echo "<td>$vac_name</td><td>$man_name</td><td>$ynd</td><td>$lot_num</td><td>$exp_date</td>
 794		<td>$r_name</td><td>$r_date</td><td>$r_time</td><td>$r_ip</td>
 795		<td>$c_name</td><td>$c_date</td><td>$c_time</td>";
 796		echo "<td>$c_ip</td>";
 797		echo "<td>$note</td>";
 798		echo "</tr>\n";
 799	}
 800	echo "</table>";
 801} // end of My_xls_dump
 802
 803function My_txt_dump($q)
 804{
 805	$crlf = chr(13) . chr(10);
 806	$d_quote = chr(34);
 807	$tab = chr(9);
 808	$r = mysql_query($q) or die(mysql_error());
 809	echo str_pad("Vaccine",32) . $tab;
 810	echo str_pad("Man",32) . $tab;
 811	echo str_pad("Consumed Destroyed  or Received",31) . $tab;
 812	echo str_pad("Lot #",80) . $tab;
 813	echo str_pad("Exp Date",10) . $tab;
 814	echo str_pad("Recorded Reveived by", 30) . $tab;
 815	echo str_pad("Date", 10) . $tab;
 816	echo str_pad("Time", 5) . $tab;
 817	echo str_pad("Computer IP", 15) . $tab;
 818	echo str_pad("Recorded Consumed or Destroyed by", 30) . $tab;
 819	echo str_pad("Date", 10) . $tab;
 820	echo str_pad("Time", 5) . $tab;
 821	echo str_pad("Computer IP", 15) . $tab;
 822	echo str_pad("Comment", 132) . $tab;
 823	echo $crlf;
 824	while ($row = mysql_fetch_array($r)) {
 825		$vac_name = $row["bio_name"];
 826		$man_name = $row["man_name"];
 827		$lot_num = $row["lot_num"];
 828		$exp_date = DosDate($row["exp_date"]);
 829		$r_name = $row["r_name"];
 830		$r_date = DosDate($row["r_date"]);
 831		$r_time = str_pad($row["r_time"],5,"0",STR_PAD_LEFT);
 832		$r_ip = $row["r_ip"];
 833		$c_name = $row["c_name"];
 834		if (strlen(trim($c_name)) < 1) $c_name = "--";
 835		$c_date = DosDate($row["c_date"]);
 836		if ($c_date == "00/00/0000") $c_date = "--";
 837		$c_time = str_pad($row["c_time"],5,"0",STR_PAD_LEFT);
 838		if ($c_time == "00000") $c_time = "--";
 839		$c_ip = $row["c_ip"];
 840		if (strlen(trim($c_ip)) < 1) $c_ip = "--";
 841		$bio_id = $row["bio_id"];
 842		$det_id = $row["det_id"];
 843		$ynd = $row["consumed_ynd"];
 844		if ($ynd == "Y") $ynd = "Consumed";
 845		if ($ynd == "N") $ynd = "Received";
 846		if ($ynd == "D") $ynd = "Destroyed";
 847		$note = $row["note"];
 848		if (strlen($note) < 1) $note = "--";
 849		//$computer = $row["computer"];
 850		echo str_pad($vac_name,32) . $tab;
 851		echo str_pad($man_name,32) . $tab;
 852		echo str_pad($ynd,31) . $tab;
 853		echo str_pad($lot_num,80) . $tab;
 854		echo str_pad($exp_date,10) . $tab;
 855		echo str_pad($r_name, 30) . $tab;
 856		echo str_pad($r_date, 10) . $tab;
 857		echo str_pad($r_time, 5) . $tab;
 858		echo str_pad($r_ip, 15) . $tab;
 859		echo str_pad($c_name, 30) . $tab;
 860		echo str_pad($c_date, 10) . $tab;
 861		echo str_pad($c_time, 5) . $tab;
 862		echo str_pad($c_ip, 15) . $tab;
 863		echo str_pad($note, 132) . $tab;
 864		echo $crlf;
 865	}
 866} // end of My_txt_dump
 867
 868
 869
 870
 871// ---------------- End of Functions
 872// ---------------
 873// ---------------
 874// ---------------- Start of Code
 875
 876$mydbf = "vaccine";
 877mysql_select_db("$mydbf") or die("unable to access database");    
 878$red = "<font color='#FF0000'>";
 879$pink = "<font color='#FF00FF'>";
 880$orange = "<font color='FF8040'>";
 881$yellow = "<font color='#FFFF00'>";
 882$black = "<font color='#000000'>";
 883$green = "<font color='#00FF00'>";
 884//$green = $pink;
 885$colorsafe = 60;
 886$colorwarn = 30;
 887
 888if ($act == "") {
 889//	echo "act was blank!!<br>";
 890	$act = "menu";
 891}	
 892//$act="menu";
 893if ($act == "Please Change Me") {
 894   print ("<center><b><font size='+2'>*** ERROR ***</font></b></center>");
 895  print ("<center><b><font size='+2'>This page <u>MUST</u> be called from a menu</font></b></center>");
 896  }
 897else
 898{
 899
 900  if ($act == "menu") $act = "mix";
 901  switch ($act) {
 902    case "menu":
 903      // Main menu
 904	  // force to mix
 905      mybanner("Main Menu", "none", $user_name);
 906      NavBar($cgi, $act, $usr_access);
 907    break;
 908
 909	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 910// MemoChange
 911//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 912    case "memo_change":
 913      // Edit/Show memo
 914      mybanner("Notes for Vaccine $name", "none", $user_name);
 915	  if ($usr_access > 50) {
 916		  $state_memo = FixMyString($mynotes);
 917		  $q = "update $bio_table set comm_memo = $d_quote$state_memo$d_quote where id = $d_quote$bio_id$d_quote";
 918		  $r = mysql_query($q) or die(mysql_error());
 919		  echo "<br><center>Memo has been changed</center><br><br>";
 920	  } else {
 921		echo "<br><br><center>You are not allowed access!</center>";
 922	  }
 923	  echo "<br><br>";
 924      NavBar($cgi, $act, $usr_access);
 925    break;
 926
 927//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 928// My Memo
 929//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 930    case "my_memo":
 931      // Edit/Show memo
 932	  mybanner("Notes for Vaccine $name", "none", $user_name);
 933	  if ($usr_access > 50) {
 934		  $q = "select * from $bio_table where id = $d_quote$bio_id$d_quote";
 935		  $r = mysql_query($q) or die(mysql_error());
 936		  $row = mysql_fetch_array($r);
 937		  $name = $row["name"];
 938		  $state_memo = $row["state_memo"];
 939		  $comm_memo = $row["comm_memo"];
 940		  echo "<br><center><font size='+2'>Edit Vaccine Memo for<br>$name</font></center><br>\n";
 941		  echo "<br><br>";
 942		  echo "<center><form action='$cgi' method='post'>\n";
 943		  echo "<input type='hidden' name='act' value='memo_change'>\n";
 944		  echo "<input type='hidden' name='bio_id' value='$bio_id'>\n";
 945		  echo "<textarea name='mynotes' rows='6' cols='75'>\n";
 946		  echo "$comm_memo";
 947		  echo "</textarea>\n";
 948		  echo "<br><br><center><input type='submit' value='Change'>\n";
 949		  echo "<input type='reset' value='Undo'></form></center>\n";
 950	  } else {
 951		echo "<br><br><center>You are not allowed access!</center>";
 952	  }
 953	  echo "<br><br>";
 954      NavBar($cgi, $act, $usr_access);
 955	
 956//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 957// mix * ok 
 958// Main Menu
 959//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 960    case "mix":
 961      // Select injectable
 962      mybanner("Vaccine Selection", "none", $user_name);
 963      echo "<br><center><font size='+2'>Select Vaccine to List</font></center><br>\n";
 964      // passed NADA
 965      $q = "select * from $bio_table order by name";
 966      $r = mysql_query($q) or die(mysql_error());
 967      if (mysql_num_rows($r) > 0) {
 968        echo "<center><table  width='75%' border='1' cellspacing='0' cellpadding='4'>\n";
 969        echo "<tr><td><center>Name</center></td>";
 970        echo "<td colspan = '3'><center>State<br>In Stock | Consumed | Destroyed</center></td>
 971		  <td colspan = '3'><center>Commercial<br>In Stock | Consumed | Destroyed</center></td>
 972		  </tr>\n";
 973      	$color = 0;
 974        while ($row = mysql_fetch_array($r)) {
 975	      $form_txt = "<form action='$cgi' method='post'>
 976		    <input type='hidden' name='act' value='%%var1%%'>
 977	        <input type='hidden' name='bio_id' value='%%bio_id%%'>
 978	        <input type='hidden' name='stock_type' value='%%stock_type%%'>
 979            <input type='submit' value=%%value%%>
 980	        </form>";
 981      	  $bio_id = $row["id"];
 982          $name = $row["name"];
 983		  
 984		  $state_memo = $row["state_memo"];
 985		  $comm_memo = $row["comm_memo"];
 986		  
 987	      $temp = $form_txt;
 988	      $temp = str_replace('%%name%%', $name, $temp);
 989	      $temp = str_replace('%%bio_id%%', $bio_id, $temp);
 990		  $form_txt = $temp;
 991		  $q_instock_public_commercial = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'N' and stock_type = 'P'";
 992		  $q_instock_state_owned = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'N' and stock_type = 'S'";
 993		  $q_consumed_public_commercial = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'Y' and stock_type = 'P'";
 994		  $q_consumed_state_owned = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'Y' and stock_type = 'S'";
 995		  $q_deleted_public_commercial = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'D' and stock_type = 'P'";
 996		  $q_deleted_state_owned = "select count(*) as mycount from $mytable where biological_id = '$bio_id' and consumed_ynd = 'D' and stock_type = 'S'";
 997
 998		  $r_instock_public_commercial = mysql_query($q_instock_public_commercial) or die(mysql_error());
 999		  $r_instock_state_owned = mysql_query($q_instock_state_owned) or die(mysql_error());
1000		  $r_consumed_public_commercial = mysql_query($q_consumed_public_commercial) or die(mysql_error());
1001		  $r_consumed_state_owned = mysql_query($q_consumed_state_owned) or die(mysql_error());
1002		  $r_deleted_public_commercial = mysql_query($q_deleted_public_commercial) or die(mysql_error());
1003		  $r_deleted_state_owned = mysql_query($q_deleted_state_owned) or die(mysql_error());
1004		  
1005		  $row_instock_public_commercial = mysql_fetch_array($r_instock_public_commercial);
1006		  $row_instock_state_owned = mysql_fetch_array($r_instock_state_owned);
1007		  $row_consumed_public_commercial = mysql_fetch_array($r_consumed_public_commercial);
1008		  $row_consumed_state_owned = mysql_fetch_array($r_consumed_state_owned);
1009		  $row_deleted_public_commercial = mysql_fetch_array($r_deleted_public_commercial);
1010		  $row_deleted_state_owned = mysql_fetch_array($r_deleted_state_owned);
1011		  
1012		  $mycount_instock_public_commercial = $row_instock_public_commercial["mycount"];
1013		  $mycount_instock_state_owned = $row_instock_state_owned["mycount"];
1014		  $mycount_consumed_public_commercial = $row_consumed_public_commercial["mycount"];
1015		  $mycount_consumed_state_owned = $row_consumed_state_owned["mycount"];
1016		  $mycount_deleted_public_commercial = $row_deleted_public_commercial["mycount"];
1017		  $mycount_deleted_state_owned = $row_deleted_state_owned["mycount"];
1018		  
1019      	  $color = MeColorTR($color, 1);
1020          //echo "<td><center><a href='$cgi?act=order&bio_id=$bio_id'>$name</a><center></td>";
1021		  echo "<td><center>";
1022		  if ($usr_access > 50) {
1023			  echo "<form action='$cgi' method='post'>";
1024			  echo "<input type='hidden' name='act' value='my_memo'>";
1025			  echo "<input type='hidden' name='bio_id' value='$bio_id'>";
1026
1027			  echo "<img src='info.gif' title=$d_quote$comm_memo$d_quote>&nbsp;";
1028
1029			  echo "<input type='submit' value='$name'>";
1030			  echo "</form>";
1031		  } else {
1032			echo "<img src='info.gif' title=$d_quote$comm_memo$d_quote>&nbsp;$name";
1033		  }
1034		  
1035		  echo "<center></td>";
1036// State -> In Stock | Consumed | Destroyed
1037// State -> In Stock
1038	      $temp = $form_txt; // reset form data
1039	      if ($mycount_instock_state_owned > 0) 
1040		  {
1041	        $temp = str_replace('%%var1%%', 'stock_list', $temp);
1042	        $temp = str_replace('%%value%%', $mycount_instock_state_owned, $temp);
1043	        $temp = str_replace('%%stock_type%%', 'S', $temp);
1044            echo "<td><center>$temp</center></td>";
1045		  } else {
1046		    echo "<td><center>0</center></td>";
1047		  }
1048
1049// State -> Consumed
1050	      $temp = $form_txt; // reset form data
1051	      if ($mycount_consumed_state_owned > 0) 
1052		  {
1053	        $temp = str_replace('%%var1%%', 'consumed_list', $temp);
1054	        $temp = str_replace('%%value%%', $mycount_consumed_state_owned, $temp);
1055	        $temp = str_replace('%%stock_type%%', 'S', $temp);
1056            echo "<td><center>$temp</center></td>";
1057		  } else {
1058		    echo "<td><center>0</center></td>";
1059		  }
1060
1061// State -> Destroyed
1062	      $temp = $form_txt; // reset form data
1063	      if ($mycount_deleted_state_owned > 0) 
1064		  {
1065	        $temp = str_replace('%%var1%%', 'destroyed_list', $temp);
1066	        $temp = str_replace('%%value%%', $mycount_deleted_state_owned, $temp);
1067	        $temp = str_replace('%%stock_type%%', 'S', $temp);
1068            echo "<td><center>$temp</center></td>";
1069		  } else {
1070			echo "<td><center>0</center></td>";
1071		  }
1072
1073// Commercial -> In Stock | Consumed | Destroyed
1074// Commercial -> In Stock
1075	      $temp = $form_txt; // reset form data
1076	      if ($mycount_instock_public_commercial > 0) 
1077		  {
1078	        $temp = str_replace('%%var1%%', 'stock_list', $temp);
1079	        $temp = str_replace('%%value%%', $mycount_instock_public_commercial, $temp);
1080	        $temp = str_replace('%%stock_type%%', 'P', $temp);
1081            echo "<td><center>$temp</center></td>";
1082		  } else {
1083		    echo "<td><center>0</center></td>";
1084		  }
1085
1086// Commercial -> Consumed
1087	      $temp = $form_txt; // reset form data
1088	      if ($mycount_consumed_public_commercial > 0) 
1089		  {
1090	        $temp = str_replace('%%var1%%', 'consumed_list', $temp);
1091	        $temp = str_replace('%%value%%', $mycount_consumed_public_commercial, $temp);
1092	        $temp = str_replace('%%stock_type%%', 'P', $temp);
1093            echo "<td><center>$temp</center></td>";
1094		  } else {
1095		    echo "<td><center>0</center></td>";
1096		  }
1097
1098// Commercial -> Destroyed
1099	      $temp = $form_txt; // reset form data
1100	      if ($mycount_deleted_public_commercial > 0) 
1101		  {
1102	        $temp = str_replace('%%var1%%', 'destroyed_list', $temp);
1103	        $temp = str_replace('%%value%%', $mycount_deleted_public_commercial, $temp);
1104	        $temp = str_replace('%%stock_type%%', 'P', $temp);
1105            echo "<td><center>$temp</center></td>";
1106		  } else {
1107			echo "<td><center>0</center></td>";
1108		  }
1109          echo "</tr>\n"; // End of Table Row
1110      	}
1111      	echo "</table></center><br><br>";
1112		
1113      } else {
1114        echo "<center><font size='+2'><br><font color=#ff0000>ERROR</font><br>Appears that there are no Vaccines in the Database<br>Press back and try again</font></center><br><br>";
1115      }
1116	  echo "<center><a href='$cgi?act=stock_add'>Add new Stock</a></center><br>";
1117      NavBar($cgi, $act, $usr_access);
1118    break;
1119	// end of mix
1120
1121	
1122
1123//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1124//stock & stock_list * ok but cargo not tested
1125// from Mix (Main Menu) selecting In Stock
1126//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1127
1128    case "stock_list":
1129      // bio_name, id, and stock_type is Passed
1130	  // if cargo = destroy or cargo = consume... need to mark that entry, then do the listing again
1131	  $stock_type_desc = "Commercial";
1132	  if ($stock_type == 'S') $stock_type_desc = "State Sponsored";
1133      mybanner("Listing of $stock_type_desc, <u>ON HAND</u> $bio_name", "none", $user_name);
1134      // Process the Mul check out as well as the single line 
1135      $q = "select a.exp_date as exp_date, a.lot_num as lot_num, a.r_name as r_name, 
1136	    a.r_date as r_date, a.r_time as r_time, a.r_ip as r_ip, 
1137		a.biological_id as bio_id, a.id as det_id, datediff( a.exp_date, now() ) as exp
1138	    from $mytable a
1139        where a.consumed_ynd = 'N' 
1140		and a.biological_id = $d_quote$bio_id$d_quote
1141		and stock_type = $d_quote$stock_type$d_quote
1142        order by a.exp_date, a.lot_num";
1143      //echo "<br>$q<br>";
1144      $r = mysql_query($q) or die(mysql_error());
1145      $max = mysql_num_rows($r);
1146      if ($max > 0) {
1147//	    echo "<hr width='45%' align=center>";
1148	    echo "<center><table  width='95%' border='1' cellspacing='0' cellpadding='4'>\n";
1149		echo "<tr bgcolor=#ffffff><td colspan=9><center>$max records found</center></td></tr>";
1150      	echo "<tr bgcolor=#ffffff><td>Lot #</td><td>Exp Date</td><td>Exp in</td>
1151		  <td>Recieved by</td><td>Date</td><td>Time</td><td>Computer</td>
1152		  <td colspan=2><center>Consume | Destroy</center></td></tr>";
1153      	$color = 0;
1154        while ($row = mysql_fetch_array($r)) {
1155          $color = MeColorTR($color, 1);
1156		  $lot_num = $row["lot_num"];
1157		  $exp_date = DosDate($row["exp_date"]);
1158		  $exp = $row["exp"];
1159		  $colorexp = "<font color='FFFF00'>"; // Yellow
1160		  if ($exp > $colorsafe) $colorexp = $black;
1161		  if ($exp < $colorwarn) {
1162		    $colorexp = $red;
1163			if ($exp > -1)  $colorexp = $green;
1164		  }	
1165		  $r_name = $row["r_name"];
1166		  $r_date = DosDate($row["r_date"]);
1167   	      $r_time = str_pad($row["r_time"],5,"0",STR_PAD_LEFT);
1168          $r_ip = $row["r_ip"];
1169   	      $bio_id = $row["bio_id"];
1170		  $det_id = $row["det_id"];
1171		  //$computer = $row["computer"];
1172          echo "<td>$lot_num</td><td>$exp_date</td>
1173		    <td>$colorexp$exp</font></td>
1174			<td>$r_name</td><td>$r_date</td><td>$r_time</td><td>$r_ip</td>";
1175   	      echo "<td><a href='$cgi?act=get_note&det_id=$det_id&bio_id=$bio_id&bio_name=$bio_name&cargo=consume'>Consume</a></td>
1176		    <td><a href='$cgi?act=get_note&det_id=$det_id&bio_id=$bio_id&bio_name=$bio_name&cargo=destroy'>Destroy</a></td>";
1177          echo "</tr>\n";
1178        }
1179      	echo "</table></center><br><br>\n";
1180		if ($usr_access > 50) {
1181		  echo "<center><table  width='60%' border='1' cellspacing='0' cellpadding='4'>\n";
1182		  echo "<tr>";
1183		  echo "<td><center><form action='$cgi' method='post'>\n";
1184		  echo "<input type='hidden' name='act' value='mul_dump'>\n";
1185		  echo "<input type='hidden' name='type' value='xls'>\n";
1186		  echo "<input type='hidden' name='bio_id' value='$bio_id'>\n";
1187		  echo "<input type='hidden' name='bio_name' value='$bio_name'>\n";
1188		  echo "<input type='hidden' name='consumed_ynd' value='instock'>\n";
1189		  echo "<br><input type='submit' value='Dump Selected to Spreadsheet'>\n";
1190		  echo "</form></center></td>\n";
1191		  echo "<td><center><form action='$cgi' method='post'>\n";
1192		  echo "<input type='hidden' name='act' value='mul_dump'>\n";
1193		  echo "<input type='hidden' name='type' value='txt'>\n";
1194		  echo "<input type='hidden' name='bio_id' value='$bio_id'>\n";
1195		  echo "<input type='hidden' name='bio_name' value='$bio_name'>\n";
1196		  echo "<input type='hidden' name='consumed_ynd' value='instock'>\n";
1197		  echo "<br><input type='submit' value='Dump Selected to Text'>\n";
1198		  echo "</form></center></td>\n";
1199		  echo "</tr></table></center><br><br>\n";
1200		}
1201	  } else {
1202        echo "<center><font size='+2'><br><font color=#ff0000>ERROR</font><br>There is no $bio_name vaccines on hand<br>Please Select a different Vaccine<br>ICN# $det_id</font></center><br><br>";
1203      }
1204      NavBar($cgi, $act, $usr_access);
1205    break;
1206	// end of stock_list
1207
1208//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1209//consumed_list * ok
1210// From Mix (Main Menu) selecting Consumed
1211//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1212
1213    case "consumed_list":
1214      // bio_name, id, $stock_type is Passed
1215	  $stock_type_desc = "Commercial";
1216	  if ($stock_type == 'S') $stock_type_desc = "State Sponsored";
1217      mybanner("Listing of $stock_type_desc, <u>CONSUMED</u> $bio_name", "none", $user_name);
1218      $q = "select a.exp_date as exp_date, a.lot_num as lot_num, a.c_name as c_name, 
1219	    a.c_date as c_date, a.c_time as c_time, a.c_ip as c_ip,
1220		a.biological_id as bio_id, a.id as det_id, a.note as note
1221	    from $mydbf.$mytable a
1222        where a.consumed_ynd = 'Y' 
1223		and a.biological_id = $d_quote$bio_id$d_quote
1224        order by a.c_date ASC, a.c_time ASC";
1225	  //echo "<br>$q<br>";
1226	  My_Lister($bio_name,

Large files files are truncated, but you can click here to view the full file