" /> ---- Garage Door Quoter ---- \n"; }; $regions = array("NSC" => "North Scotland", "SSC" => "South Scotland", "NWT" => "the North West", "NET" => "the North East", "YAL" => "Yorkshire and Lincolnshire", "NWL" => "North Wales", "SWL" => "South Wales", "MLD" => "the Midlands", "EAG" => "East Anglia", "SWT" => "the South West", "SET" => "the South East", "NIR" => "Northern Ireland"); /* Generate JavaScript to check that length, width and area are in range. The limits are passed as parameters to the PHP function, which then hard-codes them into the generated JS function. */ function mk_js_check($min_l, $max_l, $min_w, $max_w, $max_a) { echo "function check_sizes() {\n"; echo " n = window.document.theform.doors.value;\n"; echo " wt = '';\n"; echo " for (i = 0; i < n; ++i) {\n"; echo " r = i + 1;\n"; echo " l = parseFloat(document.getElementById(\"le\" + i).value);\n"; echo " w = parseFloat(document.getElementById(\"wi\" + i).value);\n"; echo " a = l * w;\n"; echo " if ((l < $min_l) || (l > $max_l) || isNaN(l)) {\n"; echo " wt += 'door ' + r + ': height must be between ", $min_l * 1, "m. and ", $max_l * 1, "m.!\\n';\n"; echo " };\n"; echo " if ((w < $min_w) || (w > $max_w) || isNaN(w)) {\n"; echo " wt += 'door ' + r + ': width must be between ", $min_w * 1, "m. and ", $max_w * 1, "m.!\\n';\n"; echo " };\n"; echo " if (a > $max_a) {\n"; echo " wt += 'door ' + r + ': area must be less than ", $max_a * 1, " sq.m.!\\n';\n"; echo " };\n"; echo " };\n"; echo " if (wt) {\n"; echo " alert(wt);\n"; echo " };\n"; echo " return (wt == '');\n"; echo "};\n"; }; function empty_td($width="", $height="", $extras="") { echo " "; }; function image($source, $width="", $height="") { echo ""; }; function start_form($form_name="", $action="", $extras="") { if (!$form_name) { $form_name = "theform"; }; if (!$action) { global $this_script; $action = $this_script; }; echo "
\n"; }; /* Functions to generate different kinds of form fields. */ /* $varname = variable name $value = value, default is to take from variable name */ function hidden_field($varname, $value=false) { if ($value === false) { $value=$GLOBALS[$varname]; }; echo ""; }; /* $varname = variable name $size = size $value = initial value, default nothing $extras = extra stuff to add, if any */ function text_field($varname, $size="", $value="", $extras="") { echo ""; }; /* $varname = variable name $rows = number of rows, default nothing {use stylesheet default} $cols = number of columns, default nothing {use stylesheet default} $value = initial value, default nothing */ function textarea_field($varname, $rows="", $cols="", $value="") { echo "\n"; }; /* $varname = variable name $text = text shown on button */ function submit_btn($varname, $text, $extras="") { echo ""; }; /* $varname = variable name $default = value {not index} of default selection $array = array of values to choose from $blank = placeholder for empty values, eg. "please select" */ function dropbox($varname, $default, $array, $blank, $extras="") { echo "\n"; }; /* $varname = variable name $ticked = whether or not it should be ticked, default false $extras = extra stuff to add, if any */ function tickbox($varname, $ticked=false, $extras="") { echo ""; }; /* $varname = variable name $value = value $ticked = whether or not it should be ticked, default false $extras = extra stuff to add, if any */ function radio_button($varname, $value, $ticked=false, $extras="") { echo ""; }; /* Special fields! There will always need to be a length and a width; so we might as well hard-code the field names right into the function that generates them, and as a bonus we can put the limits on as a tooltip */ function length_field($size="", $value="", $extras="") { global $min_l, $max_l; echo ""; }; function width_field($size="", $value="", $extras="") { global $min_w, $max_w; echo ""; }; function pass_through_post_vars($exceptions=array()) { $except1 = array(); if ($exceptions) { foreach ($exceptions as $i) { ++$except1[$i]; }; }; foreach ($_POST as $i => $j) { if ($except1[$i]) { comment("Not passing '$i'"); } else { hidden_field($i, $j); echo "\n"; }; }; }; function req_textbox_tablerow($prompt, $varname, $size, $maxlength) { echo "$prompt"; text_field($varname, $size, "", "maxlength=\"$maxlength\""); echo ""; empty_td(); echo "\n"; }; function submit_button($varname, $text, $extras="") { echo ""; }; /* Look up a post code */ function pclookup($postcode) { $post_url = PCSCRIPT . "?action=fullpc&postcode=" . urlencode($postcode); comment($post_url); if($pcdata = @file($post_url)) { echo "\n"; } else { comment("Postcode lookup for '$postcode' failed."); }; return $pcdata; }; function address_select($postcode, $house="") { $post_url = PCSCRIPT . "?action=fullpc&postcode=" . urlencode($postcode); $found_house = false; $address_array = false; $address_array = pclookup($postcode); if ($address_array) { echo "Please select your address from the list below:\n

"; echo "\n"; } else { echo "Please enter your address:\n
"; textarea_field("addrman", 5, 40, "\n$postcode"); }; }; // Display image for a map of user's region function regional_map($colour, $region) { $reg_map = strtolower("map_${colour}_${region}.jpg"); echo ""; }; /* Give a price within $error * $amount of $amount, as a whole number. e.g. blur_price(1000, .1) returns something between 900 and 1100 */ function blur_price($amount, $error) { $min = floor((1 - $error) * 1000); $max = ceil((1 + $error) * 1000); $answer = $amount * rand($min, $max) / 1000; return(sprintf("%d", $answer)); }; ############### BEGIN PRICE-ENGINE-SPECIFIC FUNCTION DEFINITIONS ############### function bqx_textbox_tablerow($prompt, $varname, $size, $maxlength) { echo "$prompt"; text_field($varname, $size, "", "maxlength=\"$maxlength\""); echo ""; empty_td(); echo "\n"; }; function req_radio_set($prompt, $varname, $array, $default="") { echo ""; echo "$prompt"; $not_the_first = 0; foreach ($array as $index=>$value) { if ($not_the_first++) { echo ""; }; echo ""; radio_button($varname, $value, (($value==$default) || ($index==$default))); echo is_numeric($index) ? ucfirst(strtolower($value)) : $index; echo "\n"; }; }; function req_tickbox_set($prompt, $array) { echo ""; echo "$prompt"; $not_the_first = 0; foreach ($array as $index=>$value) { if ($not_the_first++) { echo ""; }; echo ""; tickbox($value); echo is_numeric($index) ? ucfirst(strtolower($value)) : $index; echo "\n"; }; }; /* $varname = variable name $default = index {not value} of default selection $array = associative array of values to choose from $extras = stuff to add to "; foreach ($array as $i => $j) { echo "\n"; }; echo "\n"; }; function gdq_door_row($i) { echo ""; empty_td(0, 0, "rowspan=\"7\""); echo "Door no. ", $i + 1, ""; echo "\n"; $init_l = $_POST["length"][$i]; $init_w = $_POST["width"][$i]; $doortype = $_POST["doortype"][$i]; $material = $_POST["material"][$i]; $motor = $_POST["motor"][$i]; echo "Height"; echo ""; text_field("length[$i]", 10, $init_l, "id=\"le$i\""); echo " m. Width "; text_field("width[$i]", 10, $init_w, "id=\"wi$i\""); echo " m."; echo "\n"; echo "\n"; echo "Style of door"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n\n\n
One-pieceSide-hungSectionalRoller
\"One-piece\"\"Side-hung\"\"Sectional\"\"Roller\"
"; radio_button("doortype[$i]", 0, (($doortype < 1) || ($doortype > 3))); echo ""; radio_button("doortype[$i]", 1, ($doortype == 1)); echo ""; radio_button("doortype[$i]", 2, ($doortype == 2)); echo ""; radio_button("doortype[$i]", 3, ($doortype == 3)); echo "
\n"; echo "\n"; echo "Material"; echo ""; dropbox2("material[$i]", $material, array("steel" => "Steel", "grp" => "GRP", "timber" => "Timber")); echo ""; req_radio_set("Operation", "motor[$i]", array("Manual" => 0, "Remote" => 1), $motor); echo " \n"; }; function bottom_banner($cols=0) { echo ""; include "banner.inc.php"; echo "\n"; }; ?> "Steel", "grp" => "GRP", "timber" => "Timber"); $doortypes = array("One-piece door", "Side-hung doors", "Sectional door", "Roller door"); if ($_POST["cont3"]) { ########################### STAGE SIX - DISPLAY QUOTE ########################## $uid = $_SESSION["uid"]; $root = $_POST["root"]; $class = $_POST["class"]; $length = $_POST["length"]; // array $width = $_POST["width"]; // array $doortype = $_POST["doortype"]; // array $material = $_POST["material"]; // array $motor = $_POST["motor"]; // array $timescale = $_POST["time"]; $info = $_POST["info"]; $doors = $_POST["doors"]; $est_price = array(); mysql_select_db("raw_log", $dbh); /* Extend info field to include quote summary */ $info .= "\n"; for ($i = 0; $i < $doors; ++$i) { $info .= ucfirst($doortypes[$doortype[$i]]) . ", " . $length[$i] . "m. high by " . $width[$i] . "m. wide, " . "in " . ucfirst($materials[$material[$i]]) . "\n"; }; /* Update raw_log.logins with timescale and info */ $query = "UPDATE `logins` SET `timescale`=\"$timescale\", `info`=\"$info\" " . "WHERE `uid`=\"$uid\""; comment($query); mysql_query($query, $dbh); mysql_select_db("geet", $dbh); $est_total = 0; for ($i = 0; $i < $doors; ++$i) { $class = $material[$i] . $doortype[$i]; $l = $length[$i]; $w = $width[$i]; $query = "SELECT `aterm`, `pterm`, `cterm` FROM `suppliers` " . "WHERE `root`=\"$root\" AND `class`=\"$class\""; comment($query); $sth = mysql_query($query, $dbh); list($aterm, $pterm, $cterm) = mysql_fetch_array($sth, MYSQL_NUM); $ep = $aterm * ($w * $l) + $pterm * ($w + $l) + $cterm; comment($ep); $extras = ""; if ($motor[$i]) { $extras .= "RM|"; $ep += 700; }; $extras .= "T=" . $doortypes[$doortype[$i]] . "|"; $query = "INSERT INTO `requests` (`uid`, `root`, `class`, `length`, `width`, `extras`) " . "VALUES (\"$uid\", \"$root\", \"$class\", \"$l\", \"$w\", \"$extras\")"; comment($query); mysql_query($query, $dbh); comment($ep); $est_total += $ep; $est_price[$i] = sprintf("%.2f", $ep); }; $longreg = $regions[$reg = $_POST["reg"]]; if (!$longreg) { $longreg = "your area"; }; $est_total *= rand(850, 1150) / 1000; $bz_price = sprintf("%d", $est_total * .75); $ag_price = sprintf("%d", $est_total); $au_price = sprintf("%d", $est_total * 1.25); echo "\n"; echo ""; empty_td(50, 40); echo "\n"; echo ""; empty_td(0 ,0, "rowspan=\"5\""); empty_td(100); empty_td(); echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo ""; empty_td(); empty_td(); echo "\n"; echo ""; echo "\n"; echo "\n"; echo ""; $rowspan = 1 + $doors; empty_td(0, 0, "rowspan=\"$rowspan\""); echo "\n"; for ($i = 0; $i < $doors; ++$i) { echo ""; echo "\n"; echo ""; empty_td(); echo ""; #echo "\n"; bottom_banner(3); echo "
"; image($logo); echo "
Thank you for your enquiry.
"; # echo "Depending upon the exact requirements, which can be discussed at survey, "; # echo "you should expect to pay the following prices:\n

"; # echo ""; # echo ""; # echo ""; # echo ""; # echo "
"; # echo "BUDGET:
"; # echo "£$bz_price"; # echo "
"; # echo "STANDARD:
"; # echo "£$ag_price"; # echo "
"; # echo "DE LUXE:
"; # echo "£$au_price"; # echo "
"; echo "Depending upon your exact requirements, which can be discussed at survey, "; echo "you should expect to pay about £$ag_price."; echo "
"; echo "Our database includes suppliers in $longreg that match your requirements\n"; echo "and an authorised representative will contact you shortly to provide a more\n"; echo "detailed quotation.\n"; echo "
 
Summary of requirements
*"; echo ucfirst($doortypes[$doortype[$i]]), ", ", $length[$i], "m. high "; echo "by ", $width[$i], "m. wide.
"; echo ucfirst($materials[$material[$i]]), "; "; echo $motor[$i] ? "remote" : "manual"; echo " operation.\n"; }; echo "
 
Patent Pending, © 2000\n"; echo "Price Engines Ltd.
<php>
\n"; } elseif(($_POST["cont2a"]) || ($adddoor = $_POST["adddoor"]) || ($subtdoor = $_POST["subtdoor"])) { ##################### STAGE FIVE - GET DETAILS OF EACH DOOR #################### $reg = $_POST["reg"]; $root = "gdq"; $class = "door"; $doors = $_POST["doors"]; $timescale = $_POST["time"]; $info = $_POST["info"]; if ($adddoor) { ++$doors; } elseif(($subtdoor) && ($doors > 1)) { --$doors; }; mysql_select_db("geet", $dbh); $query = "SELECT * FROM `suppliers` WHERE `root`=\"$root\" AND `class`=\"$class\""; comment($query); $sth = mysql_query($query, $dbh); list($r1, $c1, $aterm, $pterm, $cterm, $min_l, $max_l, $min_w, $max_w, $max_a, $extras) = mysql_fetch_array($sth, MYSQL_NUM); echo "\n"; start_form(); $border = $debug ? 1 : 0; echo "\n"; echo "\n"; empty_td(53, 40); echo "\n"; echo ""; empty_td(); echo "\n"; echo ""; empty_td(53); empty_td(); # empty_td(190); # empty_td(290); empty_td(490); echo "\n"; for ($i = 0; $i < $doors; ++$i) { gdq_door_row($i); }; # echo ""; # empty_td(0,40, "rowspan=\"9\""); # echo "\n"; echo ""; empty_td(0,0,"rowspan=\"8\""); empty_td(); echo "\n"; echo ""; empty_td(); empty_td(); echo ""; req_radio_set("Time Scale", "time", array("Within 3 months" => "0-3", "3-6 months" => "3-6", "6-12 months" => "6-12", "Over 12 months" => "over 12"), $timescale); echo ""; echo "\n"; echo ""; empty_td(); echo ""; echo "\n"; echo ""; empty_td(0,25); empty_td(); echo ""; echo "\n"; #echo "\n"; bottom_banner(3); echo "
"; image($logo); echo "
Now we need to know about the\n"; echo "products you require. Please enter the following details.
Note: More complex\n"; # echo "door shapes should be treated as two or more separate doors."; # echo "
"; submit_btn("adddoor", "MORE DOORS"); if ($doors > 1) { submit_btn("subtdoor", "FEWER DOORS"); }; echo "
Additional Information"; textarea_field("info", 4, 40, $info); echo "
"; submit_btn("cont3", "Get Quote", "onClick = \"return check_reqts()\""); #echo "validate form\n"; echo "
Patent Pending, © 2000 Price Engines Ltd.
<php>
\n"; hidden_field("reg"); hidden_field("root"); hidden_field("class"); hidden_field("doors"); echo "\n"; } elseif($_POST["cont2"]) { ####################### STAGE FOUR - GET NUMBER OF DOORS ####################### $reg = $_POST["reg"]; $root = "gdq"; $class = "floor"; /* If no UID has been allocated yet, then allocate a new one now */ if (!$_SESSION["uid"]) { comment("Allocating new UID"); mysql_select_db("raw_log", $dbh); // retrieve the variables $user = $_POST["title"] . " " . $_POST["initial"] . " " . $_POST["new_user"]; $email = $_POST["email"]; $telephone = $_POST["telephone"]; if (($telephone2 = $_POST["telephone2"]) && ($telephone2 != $telephone)) { $telephone .= " or $telephone2"; }; $dataprotect = $_POST["dataprotect"]; if ($addrfrompc = $_POST["addrfrompc"]) { list($address, $town, $county, $postcode, $easting, $northing, $pafid) = preg_split("/\|/", $addrfrompc); } else { $postcode = $_POST["postcode"] . " " . $_POST["p2"]; $address = $_POST["addrman"]; $town = ""; $county = ""; $easting = 0; $northing = 0; }; $new_uid = ""; for ($i = 0; $i < 11; ++$i) { $new_uid .= rand(0,9); }; comment("Initial guess: $new_uid"); $uid_ok = false; while (!$uid_ok) { $query = "SELECT COUNT(*) FROM `logins` WHERE `uid`=\"$new_uid\""; comment($query); /* See if that UID exists in raw_log.logins */ $sth = mysql_query($query, $dbh) or die (mysql_error($dbh)); list($in_use) = mysql_fetch_array($sth, MYSQL_NUM); comment("In use: $in_use"); if ($in_use) { // change just one digit at random $new_uid = substr_replace($new_uid, rand(0,9), rand(0,strlen($new_uid)-1), 1); comment("Next try: $new_uid"); } else { // insert an entry $query = "INSERT INTO `logins`(`root`, `user`, `postcode`, `email`, " . "`address`, `town`, `county`, `date`, `uid`, `telephone`, " . "`dataprotect`, `pafid`) " . "VALUES(\"$root-$reg\", \"$user\", \"$postcode\", \"$email\", " . "\"$address\", \"$town\", \"$county\", NOW(), \"$new_uid\", " . "\"$telephone\", \"$dataprotect\", \"$pafid\")"; comment($query); /* This will fail if some other process has already caused an entry to be inserted with the same UID in the meantime. Then $uid_ok will return false and we will go around the loop again. */ $uid_ok = mysql_query($query, $dbh); }; }; $_SESSION["uid"] = $new_uid; /* Tracking stuff */ $ip_addr = $_SESSION["ip_addr"]; $s_eng = $_SESSION["s_eng"]; $proto_uid = $_SESSION["proto"]; $query = "INSERT INTO `finale` (`ipaddr`, `uid`, `qstring`, `date`, `proto`) " . "VALUES (\"$ip_addr\", \"$new_uid\", \"$s_eng\", NOW(), \"$proto_uid\")"; comment($query); mysql_query($query, $dbh); $query = "UPDATE `tracking` SET `realuid`=\"$new_uid\" " . "WHERE `uid`=\"$proto_uid\""; comment($query); mysql_query($query, $dbh); // Required to make demo work properly if ($_SESSION["demo_customer"]) { $query = "UPDATE demo SET uid=$new_uid WHERE proto=\"$proto_uid\""; comment($query); mysql_query($query, $dbh); }; /* NB, we haven't closed the MySQL connection; this is right, because we will need it later to look up product details. */ }; start_form(); $border = $debug ? 1 : 0; echo "\n"; echo "\n"; empty_td(53, 40); echo "\n"; echo ""; empty_td(0,0,"rowspan=\"2\""); echo "\n"; echo "\n"; echo ""; empty_td(53,0,"rowspan=\"3\""); empty_td(); empty_td(487); echo "\n"; echo ""; empty_td(); echo "\n"; echo "\n"; echo ""; empty_td(0,40); empty_td(); echo "\n"; echo ""; empty_td(0,25); empty_td(); echo ""; echo "\n"; #echo "\n"; bottom_banner(3); echo "
"; image($logo); echo "
How many doors do you require?
(Count a set of double doors as one\n"; echo "door.)
"; text_field("doors", 10, 1); echo "
 
"; submit_btn("cont2a", "Proceed"); echo "
Patent Pending, © 2000 Price Engines Ltd.
<php>
\n"; hidden_field("reg"); hidden_field("root"); hidden_field("class"); echo "\n"; } elseif($newreg = $_GET["reg"]) { ####################### STAGE 2+3 - GET NAME AND ADDRESS ####################### include "/usr/local/share/geet/stage2.inc.php"; } else { ########################### STAGE 1 - WELCOME SCREEN ########################### include "stage1.inc.php"; }; ############################ SESSION DEBUGGING STUFF ########################### mysql_close($dbh); if ($debug) { echo "
\$_SESSION = ";
        print_r($_SESSION);
        echo "
\n"; echo "
\$_POST = ";
        print_r($_POST);
        echo "This page is coming from: " . $_SERVER["SERVER_ADDR"] . ".\n";
        echo "
\n"; }; ?>