#!/usr/local/bin/perl -w

# popcorn.pl
# A CGI program, written using CGI.pm, to process 
#  the popcorn sales form
# Initialize total price and total number of purchased items

$total_price = 0;
$total_items = 0;

use CGI ":standard";

# First produce the header part of the HTML return value

print header();
print start_html("CGI-Perl Popcorn Sales Form, using CGI.pm");

# Set local variables to the parameter values

my($name, $street, $city, $payment) = 
        (param("name"), param("street"),
        param("city"), param("payment"));
my($unpop, $caramel, $caramelnut, $toffeynut) = 
        (param("unpop"), param("caramel"),
         param("caramelnut"), param("toffeynut"));

# Compute the number of items ordered and the total cost

if ($unpop > 0) {
    $cost = 3.0 * $unpop;
    $total_price += $cost;
    $total_items += $unpop;
} 

if ($caramel > 0) {
    $cost = 3.5 * $caramel;
    $total_price += $cost;
    $total_items += $caramel;
} 

if ($caramelnut > 0) {
    $cost = 4.5 * $caramelnut;
    $total_price += $cost;
    $total_items += $caramelnut;
} 

if ($toffeynut > 0) {
    $cost = 5.0 * $toffeynut;
    $total_price += $cost;
    $total_items += $toffeynut;
}

# Produce the result information to the browser and finish the page

print "<h3>Customer:</h3>\n",
      "$name <br/>\n", "$street <br/>\n", "$city <br/>\n",
      "Payment method: $payment <br/><br/>\n",
      "<h3>Items ordered:</h3> \n",
      "Unpopped popcorn: $unpop <br/> \n",
      "Caramel popcorn: $caramel <br/> \n",
      "Caramel nut popcorn: $caramelnut <br/> \n",
      "Toffey nut popcorn: $toffeynut <br/><br/> \n",
      "You ordered $total_items popcorn items <br/>\n",
      "Your total bill is: \$ $total_price <br> \n";
print end_html();




conelec.html
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- conelec.html 
     A document to present the user with a consumer electronics 
     purchasing survey form 
     -->

<html>
<head>
<title> Consumer Electronics Purchasing Survey </title>
</head>
<body>
<form 
    action = "http://www.cs.ucp.edu/cgi-bin/sebesta/conelec1.pl" 
    method = "post">
<h2> Welcome to the Consumer Electronics Purchasing Survey </h2>
<p />

<h4> Your Age Category: </h4>
<p>
<input type = "radio"  name = "age"  value = "b1025"  
       checked = "checked" /> 10-25 <br />
<input type = "radio"  name = "age"  value = "b2640" /> 
    26-40 <br />
<input type = "radio"  name = "age"  value = "b4160" /> 
    41-60 <br />
<input type = "radio"  name = "age"  value = "o60" /> 
    Over 60 <br /> <br />
</p>
<h4> Your Gender: </h4>
<p>
<input type = "radio"  name = "gender"  value = "female"  
       checked = "checked" /> Female <br />
<input type = "radio"  name = "gender"  value = "male" /> 
    Male <br /> <br />
</p>
<h4> Your Next Consumer Electronics Purchase will be: </h4>
<p>
<input type = "radio"  name = "vote"  value = "0" /> 
    Conventional TV <br />
<input type = "radio"  name = "vote"  value = "1" /> 
    HDTV <br />
<input type = "radio"  name = "vote"  value = "2" /> 
    VCR <br />
<input type = "radio"  name = "vote"  value = "3" /> 
    CD player <br />
<input type = "radio"  name = "vote"  value = "4" /> 
    Mini CD player/recorder <br />
<input type = "radio"  name = "vote"  value = "5" /> 
    DVD player <br />
<input type = "radio"  name = "vote"  value ="6"  
    checked = "checked" /> Other <br /> <br />

<input type = "submit"  value = "Submit Order" />
<input type = "reset"  value = "Clear Order Form" />
</p>
</form>

<hr />
<p>
To see the results of the survey so far, click 
<a href = 
    "http://www.cs.ucp.edu/cgi-bin/sebesta/conelec2.pl"> 
   here 
</a>
</p>
</body>
</html>

