<?php 
session_start
() ?>

<!--
    Brian Platz
    CS85 Section 1643
    Professor Geddes
    March 23, 2012
    Assignment: Test 1, problem 3
            1    Display a form that asks the user for the following information:
                    name
                    employee ID
                    office room number
                    operating system on the office computer
            2    Send the form data to a server-side script that echoes the form data 
                back to the user in the following way:
                    Hi ____, 
                       Your employee ID is ____, your office is room ____, and your OS is ____.

                    If this is correct, click Yes. Otherwise, click No.
            3    Provide buttons or links for the Yes and No choices mentioned in requirement #2.
            4    If the user clicks Yes, respond with "Thank you for verifying your information."
            5    If the user clicks No, display the form described in requirement #1.

--> 
<!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>
      <title>Test 1, Problem 3</title>
      <style type="text/css">
         body {background-color:#90EE90}
         h1 {color:black; font-family:Ariel; font-size:14pt; 
                 font-weight:bold; text-align: center}
         h2 {color:red; font-family:Ariel; font-size:14pt; font-weight:bold}
         h3 {color:black; font-family:Ariel; font-size:24pt; font-weight:normal}
         .center {margin-left: auto;
                    margin-right: auto;
                    width: 6em;}
      </style>    
   </head>
   <body> 
      <?php
      extract
($_REQUEST); //kg: create form variables
      
error_reporting(E_ALL & ~E_NOTICE); //kg: get rid of run-time notices
      
$username $_REQUEST['username'];
      
$verify $_REQUEST['verify'];
      
$id $_REQUEST['id'];
      
$room $_REQUEST['room'];
      
$os $_REQUEST['os'];
      
      if ( !isset(
$_REQUEST['username']) && !isset($_REQUEST['verify']) ){
                                                      
// no username or verification -- first time through
              
createForm();                                // create initial form
              
}
        else if ( isset(
$_REQUEST["username"]) && !isset($_REQUEST["verify"]) ) {
                                                      
// form submitted, but not verified -- need to verify
                                                          // print verification page
            
confirmInput();
              } 
      else {                                        
// verification submitted, check verification
              
if ($verify == 'Yes' ) {                    // info confirmed
                  
echo "<h1>Thank you for verifying your information.</h1>";
                  } else {                                
// info incorrect...repeat process
                
session_unset();                            // clear session vars, keep session
                  
createForm();                                // display form
                  
}
              }
         
          function 
createForm() {                        // prints out initial form
              
echo <<<MAINFORM
                  <h1>Please submit the following information:<br/>
                  <form name='myForm' method='' action='' > 
                      Username: <input type="text" name="username" size="25" maxlength="25"/> <br/>
                      Employee ID#: <input type="text" name="id" size="10" maxlength="10"/> <br/>
                      Office Room #: <input type="text" name="room" size="5" maxlength="5"/> <br/>
                      Computer OS: 
                          <select name="os" size="1" >
                          <optgroup label="Macintosh">
                            <option value="OSX 10.7">OSX (10.7.x)</option>
                            <option value="OSX 10.6">OSX (10.6.x)</option>
                            <option value="OSX 10.5">OSX (10.5.x)</option>
                            <option value="OSX 10.4">OSX (10.4.x)</option>
                            <option value="Early Mac OS">OSX (earlier version)</option>
                          </optgroup>
                          <optgroup label="Windows">
                            <option value="Windows 7">Windows 7</option>
                            <option value="Windows Vista">Vista</option>
                            <option value="Windows XP">XP</option>
                          </optgroup>
                        </select> <br/>
                        <button type='submit' value='Submit'>Submit</button> 
                        </form>
MAINFORM;
            }
            
        function 
confirmInput() {
            global 
$username;
            global 
$id;
            global 
$room;
            global 
$os;
            echo <<<VERIFY
                  <h1>Hi $username,<br/>
                  Your empolyee ID is 
$id, your office is room $room, and your OS is $os.<br/>
                  <br/>
                  if this is correct, click 'Yes.' Otherwise, click 'No.'<br/><br/>
                  <form name='myForm2' method='' action=''>
                    <button type='submit' name=verify value=Yes>Yes</button><br/>
                    <button type='submit' name=verify value=No >No</button><br/>
                  </form>
VERIFY;
            }
      
?>
   </body>
</html>