$title\n"; $this_script = "http://" . ($http_host = $_SERVER['HTTP_HOST']) . $_SERVER["PHP_SELF"]; function comment($cmt) { echo "\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 " l = document.theform.length.value;\n"; echo " w = document.theform.width.value;\n"; echo " a = l * w;\n"; echo " wt = '';\n"; echo " if ((l < $min_l) || (l > $max_l)) {\n"; echo " wt += '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)) {\n"; echo " wt += '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 += 'Area must be less than ", $max_a * 1, " sq.m.!\\n';\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"; }; }; }; // Display image for a map of user's region function regional_map($colour, $region) { $reg_map = strtolower("map_${colour}_${region}.jpg"); echo ""; }; ############### 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) { echo ""; echo "$prompt"; $not_the_first = 0; foreach ($array as $index=>$value) { if ($not_the_first++) { echo ""; }; echo ""; radio_button($varname, $value); 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"; }; }; /* Generate a group of radio buttons, of which one must be ticked. $prompt = prompt text $varname = variable name $array = associative array "label" => "value" $error_msg = error message if nothing ticked. Returns a JavaScript fragment to validate the selection. */ function validated_radio_set($prompt, $varname, $array, $error_msg) { echo ""; echo "$prompt"; $not_the_first = 0; foreach ($array as $index=>$value) { if ($not_the_first++) { echo ""; }; echo ""; radio_button($varname, $value); echo is_numeric($index) ? ucfirst(strtolower($value)) : $index; echo "\n"; }; $js = " if (!check_sthg_ticked(f.$varname)) {\n" . " wt += \"${error_msg}\\n\";\n" . " };\n"; comment("Javascript:\n$js"); return $js; }; /* Generate a group of tickboxes, of which at least one must be ticked. $prompt = prompt text $array = associative array "tickbox_varname" => "label" $error_msg = error message if nothing ticked. Returns a JavaScript fragment to validate the selection. */ function validated_tickbox_set($prompt, $array, $error_msg) { $js = ""; echo ""; echo "$prompt"; $not_the_first = 0; $js .= " if ("; foreach ($array as $index=>$value) { if ($not_the_first++) { $js .= " && "; echo ""; }; $js .= "(!f.$index.checked)"; echo ""; tickbox($index); echo $value; echo "\n"; }; $js .= ") {\n" . " wt += \"${error_msg}\\n\";\n" . " };\n"; comment("Javascript:\n$js"); return $js; }; /* Generate a dropbox, which must be set to something other than the supplied placeholder value.. $prompt = prompt text $varname = variable name $array = associative array "label" => "value" $default = placeholder for default value $error_msg = error message if nothing selected. Returns a JavaScript fragment to validate the selection. */ function validated_dropbox($prompt, $varname, $array, $default, $error_msg) { echo ""; echo "$prompt"; echo "\n"; $js = " if (!f.$varname.selectedIndex) {\n" . " wt += \"${error_msg}\\n\"\n" . " };\n"; comment("Javascript:\n$js"); return $js; }; /* Generate a pair of radio buttons, "yes" (value = 1) and "no" (value = 0). The variable thus created can be treated as a boolean. $prompt = prompt text $varname = variable name $disposition = false means horizontal, true means vertical $error_msg = error message if nothing ticked. Returns a JavaScript fragment to validate the selection. */ function validated_yn_set($prompt, $varname, $disposition, $error_msg) { echo "$prompt"; radio_button($varname, 1); echo " Yes "; if($disposition) { echo "\n"; }; radio_button($varname, 0); echo " No"; echo "\n"; $js = " if (!check_sthg_ticked(f.$varname)) {\n" . " wt += \"${error_msg}\\n\";\n" . " };\n"; comment("Javascript:\n$js"); return $js; }; /* Generate a colour chooser, with a dropbox and a "state here if other" box, and the JavaScript to deal with the "other" logic. NB, varnames will always be "colour" for the dropbox and "altcolour" for the "state here if other" box. $prompt = prompt text $default = default value {not index} $array = array $blank = placeholder for empty values $error_msg = error message if nothing ticked. Returns a JavaScript section to validate the selection. */ function validated_colour($prompt, $default, $array, $blank, $error_msg) { /* AJS' amazing code to deal with a "(state here if other)" option Note, we dump *this* out here and now ..... but we also send some *more* JavaScript in the return value. */ echo "\n"; echo ""; echo "$prompt"; echo ""; dropbox("colour", $default, $array, $blank, "onchange=\"set_alt()\""); echo "\n"; echo ""; text_field("altcolour", 20, "(state here if other)", "onclick=\"clear_alt()\""); echo "\n"; $js = " if (!f.colour.selectedIndex) {\n" . " wt += \"${error_msg}\\n\"\n" . " };\n"; comment("JavaScript:\n$js"); return $js; }; /* This version of a yes/no set does not need to be validated, because one of the options will always be ticked. */ function forced_yn_set($prompt, $varname, $disposition, $yes=false) { echo "$prompt"; radio_button($varname, 1, $yes); echo " Yes "; if($disposition) { echo "\n"; }; radio_button($varname, 0, !$yes); echo " No"; echo "\n"; }; function forced_dropbox($prompt, $varname, $array) { echo ""; echo "$prompt"; echo "\n"; }; function append_extra($name, $value) { return ("$name=" . preg_replace("/\|/", "", $value) . "|"); }; function bottom_banner($cols=0) { echo "If you would like to talk to us in person please call\n"; echo "01283 707060\n"; echo "This site and the Quoter system are owned by and copyright of\n"; echo ""; echo "Price Engines Ltd
2001-2002\n"; echo "privacy policy -\n"; echo ""; echo "terms & conditions\n"; }; ?> $j) { if (preg_match("/[A-Z]{2}/", $i) && $j) { $query = "SELECT `description`, `aterm`, `pterm`, `cterm` FROM `extras` " . "WHERE `root`=\"$root\" AND `class`=\"$class\" AND `code`=\"$i\""; comment($query); $sth = mysql_query($query, $dbh); list($desc, $e_aterm, $e_pterm, $e_cterm) = mysql_fetch_array($sth, MYSQL_NUM); $est_price += $e_aterm * ($width * $length) + $e_pterm * ($width + $length) + $e_cterm; $extras .= $i . "|"; $stuff[$i] = $desc; }; }; $query = "INSERT INTO `requests` (`uid`, `root`, `class`, `length`, `width`, `extras`) " . "VALUES (\"$uid\", \"$root\", \"$doortype\", \"$length\", \"$width\", \"$extras\")"; comment($query); mysql_query($query, $dbh); mysql_select_db("raw_log", $dbh); /* Update raw_log.logins with timescale and info */ $info .= $doortype ."width: ".$width . " height: ".$length. " ".$class ." ".$extras . " ".$est_price; $query = "UPDATE `logins` SET `timescale`=\"$timescale\", `info`=\"$info\" " . "WHERE `uid`=\"$uid\""; comment($query); mysql_query($query, $dbh); $longreg = $regions[$reg = $_POST["reg"]]; if (!$longreg) { $longreg = "your area"; }; $est_price = sprintf("%.2f", $est_price); comment($est_price); $bz_price = sprintf("%d", $est_price * .85); $ag_price = sprintf("%d", $est_price); $au_price = sprintf("%d", $est_price * 1.15); $min_amt = $est_price * (rand(850, 950) / 1000); $min_amt = sprintf("%d", $min_amt); $max_amt = $est_price * (rand(1050, 1150) / 1000); $max_amt = sprintf("%d", $max_amt); 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"; if ($express) { echo ""; echo "\n"; } else { echo ""; echo "\n"; }; echo ""; empty_td(); empty_td(); echo "\n"; echo ""; echo "\n"; echo "\n"; echo ""; $rowspan = count($stuff) + 3; empty_td(0, 0, "rowspan=\"$rowspan\""); echo "\n"; $rowspan = count($stuff) + 2; echo ""; empty_td(0, 0, "rowspan=\"$rowspan\""); echo "\n"; echo ""; echo "\n"; if ($stuff) { foreach($stuff as $i => $j) { echo ""; echo "\n"; }; }; echo "\n"; echo ""; empty_td(); echo ""; bottom_banner(3); echo "
"; image("gfx/logosm.gif"); echo "
Thank you for your enquiry.
"; echo "Based on your requirements we calculate that you can expect to pay\n"; echo "between £${min_amt} and £${max_amt}.\n"; echo "
"; 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 "
"; 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($doortype), " door."; echo "
"; echo "* ${length}m. high by ${width} m. wide."; echo "
"; echo "* $j"; echo ".
 
Patent Pending, © 2000\n"; echo "Price Engines Ltd.
\n"; echo " "; } elseif($_POST["cont2"]) { ####################### STAGE FOUR - GET PRODUCT DETAILS ####################### $reg = $_POST["reg"]; $root = "bq"; $class = "bifold"; /* 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"]; $addrfrompc = $_POST["addrfrompc"]; list($address, $town, $county, $postcode, $easting, $northing, $pafid) = preg_split("/\|/", $addrfrompc); $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. */ }; /* This is where it gets interesting! So far we have mostly been indifferent to the product ..... Now we must throw abstraction to the four winds and ride the metal. */ /* Look up pricing coefficients, size limits and extras for this product */ 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); ################################## BEGIN FORM ################################## start_form("", "", "onSubmit = \"return check_request()\""); $js = ""; echo "\n"; echo "\n"; empty_td(53, 40); echo "\n"; echo ""; empty_td(); echo "\n"; echo ""; empty_td(53,0,"rowspan=\"13\""); empty_td(); empty_td(487); echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $js .= " if (!check_sthg_ticked(f.doortype)) {\n" . " wt += \"You need to select a door type!\\n\";\n" . " };\n"; $js .= validated_yn_set("Do you require a custom paint colour (aluminium only)?", "GU", false, "You have not selected whether you require custom paint!"); $js .= validated_yn_set("Do you require a metallic finish?", "FS", false, "You have not selected whether you require metallic finish!"); echo ""; empty_td(); empty_td(); echo "\n"; $js .= validated_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"), "You have not selected a time scale!"); echo "\n"; echo "\n"; echo ""; empty_td(0,40); echo "\n"; echo ""; empty_td(0,25); echo ""; echo "\n"; #echo "\n"; bottom_banner(3); echo "
"; image("gfx/logosm.gif"); echo "
Now we need to know about the\n"; echo "products you require. Please enter the following details.
Dimensions of opening
Height (m.) "; length_field(10); echo " Width (m.) "; width_field(10); echo "
 
Construction\n"; echo "\n"; echo ""; echo "
"; echo "PVCuAluminiumWood
"; image("gfx/pvcubutton.gif"); echo ""; image("gfx/aluminiumbutton.gif"); echo ""; image("gfx/woodbutton.gif"); echo "
"; radio_button("doortype", "PVCu"); echo ""; radio_button("doortype", "alu"); echo ""; radio_button("doortype", "wood"); echo "
Additional Information"; textarea_field("info", 4, 40); echo "
"; submit_btn("cont3", "Get Quote"); 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 ####################### echo "\n"; // a valid email start_form("", "", "onSubmit = \"return check_login()\""); echo "\n"; echo ""; empty_td(50); echo "\n"; empty_td(); echo "\n"; echo ""; empty_td(); echo "\n"; echo "\n"; echo ""; empty_td(0,0,"rowspan=\"11\""); empty_td(0,0,"colspan=\"2\""); empty_td(); echo "\n"; echo ""; empty_td(150); empty_td(300); empty_td(); echo "\n"; echo ""; echo ""; echo "\n"; echo "\n"; bqx_textbox_tablerow("Initial", "initial", 4, 1); bqx_textbox_tablerow("Surname", "new_user", 33, 32); bqx_textbox_tablerow("House number", "houseno", 9, 8); echo ""; #echo ""; echo ""; /* td with an iFrame for address selector */ echo "\n"; /* back to table */ echo "\n"; echo ""; #"; echo ""; echo "\n"; empty_td(); echo "\n"; bqx_textbox_tablerow("Telephone number", "telephone", 20, 20); bqx_textbox_tablerow("Alternative Tel. No.", "telephone2", 20, 20); bqx_textbox_tablerow("e-mail", "email", 35, 40); echo ""; empty_td(50); empty_td(150); empty_td(300); empty_td(196); echo "\n"; echo ""; empty_td(); echo ""; echo ""; empty_td(); echo "\n"; echo ""; empty_td(); echo ""; echo ""; empty_td(); echo "\n"; echo ""; empty_td(); empty_td(); echo ""; empty_td(); echo "\n"; echo ""; empty_td(); empty_td(); echo ""; empty_td(); echo "\n"; #echo "\n"; bottom_banner(4); echo "
"; image("gfx/logosm.gif"); echo "
"; echo "

Registration

"; echo "

"; $longreg = $regions[$newreg]; if (!$longreg) { $longreg = "your area"; }; echo "Please provide the following information to compare companies and prices in $longreg.
\n"; echo "Your details will not be passed to any company without your permission.

Title"; dropbox("title", "", array("", "Mr.", "Mrs.", "Miss", "Ms.", "Dr."), "--"); echo str_repeat(" ", 6); echo "why do we ask your details?\n"; echo "

Address"; echo "\n"; echo "

Post Code"; text_field("postcode", 4, "", "maxlength=\"4\""); echo "\n"; text_field("p2", 4, "", "maxlength=\"4\""); echo "\n"; echo ""; echo "
Data Protection:We may contact you about other offers, or pass your\n"; echo "details to other reputable companies whose products and services may be\n"; echo "of interest to you.
"; tickbox("dataprotect", true); echo "Please tick this box if you do not wish to\n"; echo "receive such offers.
"; submit_btn("cont2", "Login"); hidden_field("addrfrompc",""); echo "
Patent Pending, © 2000 Price Engines Ltd.
<php>
\n"; hidden_field("mid", "dod1"); hidden_field("reg", "$newreg"); echo "\n"; } else { ########################### STAGE 1 - WELCOME SCREEN ########################### include "stage1.inc.php"; }; ############################ SESSION DEBUGGING STUFF ########################### 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"; }; mysql_close($dbh); ?>