<?php 
session_set_cookie_params
(60); 
session_start(); ?>

<!--
    Brian Platz
    CS85 Section 1643
    Professor Geddes
    March 14, 2012
    Assignment: Final Project
    NOTE: This project is used for maintaining quality control data on 
        incorrect orders placed for surgical pathology specimens. It will
        keep track of case number, ordering physician, ordering nurse, 
        the date entered into the system, and the nature of the error
        (e.g. incorrect history, wrong order type, etc).
        
        Variable user levels:
                1. highest level allows all database functions.
                2. middle level allows creation of new elements in all tables
                    except 'users.'
                3. lowest level only allows creation of new 'events.'
        
        THIS FILE:  THE MAIN PHP CONTROL FILE
-->
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
    <link rel="stylesheet" type="text/css" href="pathmate_qa.css"/>
   </head>
   <body><title>PathMate&reg; QA</title> 
   
    <?php

    extract
($_REQUEST);                         // create form variables
    
error_reporting(E_ALL & ~E_NOTICE);         // get rid of runtime notices
         
    
include 'functions.php';                    // include functions used
    
include 'include.inc';                        // include all included files
    
    
if ( !isset( $_SESSION['flag'] ) ) {                                // first time through
        
$_SESSION['flag'] = 'start';                    
    }
    switch ( 
$_SESSION['flag'] )                                        
        {
        case 
'start':
            
$conn mysql_connect$localhost$localUser$localPassword );
            
$db_exists mysql_select_db($db$conn);
            if (!
$db_exists) {
                
header("Location: create_db.php"); 
            }    
            
printLoginForm();
            
$_SESSION['flag'] = 'login';
            break;
        case 
'login':                                                    // check if user/password combo is valid
            
if ( verifyUser$_REQUEST[usr], $_REQUEST[pwd] ) ) {            // if valid, enter working mode
                
printWorkForm();                                
                
$_SESSION['flag'] = 'verified';
            } else {                                                        
// else, retry login
                
print "<h2>Invalid login. Try again.</h2><br>";
                
printLoginForm();    
            }
            break;
        case 
'verified':                                                // functions for validated user/password combo
            
if ( $_REQUEST['btnSub'] ) {                                // event has been submitted
                                                                            // store event
                
storeEvent$_REQUEST['caseNum'], $_REQUEST['selLoc'], $_REQUEST['selMD'], $_REQUEST['selRN'], $_REQUEST['selErrs'] );    
                unset( 
$_REQUEST['btnSub'] );                                // clear button status
                
print "<br><h4>Event Recorded</h4>";                        // confirm
                
printWorkForm();                                            // reprint form
            
} else if ( $_REQUEST['btnLogout'] ) {                        // request to log out
                
$_REQUEST['btnLogout'] = null;                                // similar to above
//                session_unset();
                
print "<br><h4>You have been logged out</h4>";
                
printLoginForm();
                
$_SESSION['flag'] = 'login';
            } else if ( 
$_REQUEST['btnPrint'] ) {                        // request to print out current events
                
$_REQUEST['btnReport'] = null;                                // similar to above
                
printEvents();        
                
printWorkForm();                                            
            } else {
                
printWorkForm();    
            }
              break;
        default:
          print 
"In default of switch, and shouldn't be.\$_SESSION['flag'] = ".$_SESSION['flag'];
        } 
    
?>
<a href='../index.html#finalproject' >Main Page</a>  
   </body>
</html>