<!--
    Brian Platz
    CS85 Section 1643
    Professor Geddes
    March 12, 2012
    Assignment: Write a script that lets the user specify how many sides a die has and prints a 
                    random roll with the appropriate maximum values. 
                (Don't worry about using images to display the dice.)
    -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="brianplatz.com" xml:lang="en">
   <head>
      <title>Unit 3 Dice Roller</title>
      <style type="text/css">
         body {background-color:#90EE90}
         h1 {color:black; font-family:Ariel; font-size:14pt; font-weight:bold}
         h2 {color:black; font-family:Ariel; font-size:14pt; font-weight:normal}
         h3 {color:black; font-family:Ariel; font-size:24pt; font-weight:normal}
      </style>    
   </head>
   <body> 
      <?php
      
      printGreeting
();
      
printForm();
      
      function 
printGreeting() {
          global 
$sides;
        
$sides filter_input(INPUT_POST"sides");
        if ( !
filter_has_var(INPUT_POST"sides") ) {        // first time through (ask for # of sides)
            
print "<h1>How many sides would you like on the die?</h1>";
        } else {                                            
// roll die with stated # of sides
            
if ($sides == || $sides == 1) {
                print 
"<h1>That is an Escherian die! Please try again.</h1>";
            } else {
                
$roll rand(1$sides);
                print 
"<h1>You rolled a <span style='color:red'>$roll</span> on a die with $sides sides.</h1>";
            }
        }
      }

      function 
printForm() {
          global 
$sides;
          print <<<HERE
              <form name='rollEmm' action='' method='post'>
              <fieldset>
                <h2>Sides: <input type='text' name='sides' size='3' maxlength='3' value='' /></h2>
                <input type='submit' value='submit'>
            </fieldset>
            </form>
        <br/><br/><a href='../index.html' >Return to Index</a>
HERE;
      }

      
?>
   </body>
</html>