changeset 165:5b1b275e8b6b misc

Modularize, clean up indentation, add more options.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 30 Dec 2010 02:05:06 +0000
parents 61327dee8e8c
children 63c932c1f037
files prices.php
diffstat 1 files changed, 145 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/prices.php	Thu Dec 30 01:43:41 2010 +0000
+++ b/prices.php	Thu Dec 30 02:05:06 2010 +0000
@@ -8,6 +8,7 @@
 $pageIndex = "prices.php";
 $pageTitle = "Ggr's Merchant Pricelist";
 $pageCharset = "ISO-8859-1";
+//$pageCSS = "foobar.css";  // uncomment and change this, if you want to use your own CSS stylesheet file
 
 
 // Enabled service and product sections
@@ -20,6 +21,28 @@
   "potions"    => false,
 );
 
+
+// Global additional desc, added to start of the page
+$global_desc = '
+<div style="border: 1px solid #0f0; padding: 15px; color: #ff0; text-align: center; font-size: 8pt;">
+<span style="font-size: 20pt;">I do NOT make alchemist potions or rings*, or any SHIP stuff.</span><br />
+<br />
+(*) Well, actually I do make rings, but only for personal amusement. I do
+not wish to spend time trying to come up with some specific ring type.)
+</div>
+';
+
+
+// Generic services section settings
+$services = array(
+  "name"     => "services",
+  "title"    => "Generic services",
+  "discount" => true,	// enable discounts for this section
+
+  "desc"     => "As one might expect, <b>I have most of the relevant
+skills/spells/masteries at 100%</b>.",
+);
+
 // Service prices with discount thresholds
 $services1_prices = array(
   "fw" => array(
@@ -87,6 +110,15 @@
 
 
 // Mage reagents
+$services = array(
+  "name"     => "reagents",
+  "title"    => "Power reagents",
+  "discount" => true,	// enable discounts for this section
+
+  "desc"     => "Bulk orders may require time to complete, inquire.
+I keep some stock on reagents, though.",
+);
+
 $reagent_prices = array(
   "Blast reagents" => array(
     "acid1" => array("acid", "Acid Blast",           "handful of olivine powder",    125),
@@ -256,6 +288,31 @@
 }
 
 
+function printSectionHeader($sec)
+{
+  echo "<h2>".$sec["title"]."</h2>\n";
+
+  if (isset($sec["desc"]))
+    echo "<p>".$sec["desc"]."</p>\n";
+
+  echo "<table class=\"pritab\">\n";
+}
+
+function printSectionFooter($sec)
+{
+  echo "</table>\n<p>\n";
+  
+  if ($sec["discount"]) {
+    echo "<p>".$sec["title"]." total discount %: ".
+    getField($sec["name"]."_discount")."<br />\n".
+    "";
+  }
+
+  echo "<input type=\"submit\" value=\" Calculate \" class=\"isubmit\" />\n".
+  "</p>\n\n";
+}
+
+
 echo "<?xml version=\"1.0\" encoding=\"".$pageCharset."\"?>";
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -263,6 +320,11 @@
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=<? echo $pageCharset; ?>" />
  <title><? echo $pageTitle; ?></title>
+<?
+if (isset($pageCSS)) {
+ echo "<link rel=\"stylesheet\" title=\"Default\" href=\"".$pageCSS."\" type=\"text/css\" />\n";
+} else {
+?>
  <style type="text/css">
  <!--
  body { background: black; color: white; font-family: Arial, Verdana, sans-serif; font-size: 10pt; }
@@ -284,6 +346,7 @@
  .elec { color: #08f; }
  -->
  </style>
+<? } ?>
 </head>
 <body>
 <?
@@ -291,136 +354,111 @@
 // Data input mode
 //============================================================================
 if (!isset($_POST["ok"])) {
-?>
-<h1><? echo $pageTitle; ?></h1>
+
+echo "<h1>".$pageTitle."</h1>\n";
 
-<div style="border: 1px solid #0f0; padding: 15px; color: #ff0; text-align: center; font-size: 8pt;">
-<span style="font-size: 20pt;">I do NOT make alchemist potions or rings*, or any SHIP stuff.</span><br />
-<br />
-(*) Well, actually I do make rings, but only for personal amusement. I do
-not wish to spend time trying to come up with some specific ring type.)
-</div>
+if (isset($global_desc))
+  echo $global_desc;
 
-<form action="<? echo $pageIndex; ?>" method="post" autocomplete="off">
+echo "\n<form action=\"".$pageIndex."\" method=\"post\" autocomplete=\"off\">\n";
 
-<?
 if ($sections["services1"] || $sections["services2"]) {
-?>
-<h2>Generic services</h2>
-<p>
-As one might expect, <b>I have most of the relevant skills/spells/masteries at 100%</b>.
-</p>
-<table class="pritab">
-<?
-if ($sections["services1"]) {
-foreach ($services1_prices as $key => $item) {
-  $s = isset($item["extra"]) ? $item["extra"] : "";
-  echo
-  " <tr>\n".
-  "  <th>".$item["name"]."</th>\n".
-  "  <th>Cost</th>\n".
-  "  <th>#</th>\n".
-  " </tr>\n".
-  " <tr><td>1-".($item["tresh"]-1)." ".$item["subj"]."s</td><td>".convPrice($item["price1"])." / ".$item["subj"].$s."</td><td>-</td></tr>\n".
-  " <tr><td>".$item["tresh"]."+ ".$item["subj"]."s</td><td>";
+
+  printSectionHeader($services);
 
-  if (isset($item["base"])) {
-    echo convPrice($item["base"])." initial fee + ".convPrice($item["price2"])." / ".$item["subj"].$s;
-  } else {
-    echo convPrice($item["price2"])." / ".$item["subj"].$s;
-  }
+  if ($sections["services1"]) {
+    foreach ($services1_prices as $key => $item) {
+      $s = isset($item["extra"]) ? $item["extra"] : "";
+      echo
+      " <tr>\n".
+      "  <th>".$item["name"]."</th>\n".
+      "  <th>Cost</th>\n".
+      "  <th>#</th>\n".
+      " </tr>\n".
+      " <tr><td>1-".($item["tresh"]-1)." ".$item["subj"]."s</td>".
+      "<td>".convPrice($item["price1"])." / ".$item["subj"].$s."</td>".
+      "<td>-</td></tr>\n".
+      " <tr><td>".$item["tresh"]."+ ".$item["subj"]."s</td><td>";
 
-  echo "</td><td>".getField($key)."</td>";
+      if (isset($item["base"])) {
+        echo convPrice($item["base"])." initial fee + ".convPrice($item["price2"])." / ".$item["subj"].$s;
+      } else {
+        echo convPrice($item["price2"])." / ".$item["subj"].$s;
+      }
+
+      echo "</td><td>".getField($key)."</td>";
   
-  if (isset($item["extra"])) {
-    echo "<td>+ ".getField($key."_extra")."</td>";
-  }
+      if (isset($item["extra"])) {
+        echo "<td>+ ".getField($key."_extra")."</td>";
+      }
   
-  echo "</tr>\n";
-}
-} // services1 enabled
+      echo "</tr>\n";
+    }
+  } // services1 enabled
 
 
-if ($sections["services2"]) {
-?>
- <tr>
-  <th>Service</th>
-  <th>Cost</th>
-  <th>#</th>
- </tr>
-<?
-foreach ($services2_prices as $key => $item) {
-  echo " <tr><td>".$item["name"]."</td><td>".convPrice($item["price"])." / ".$item["subj"]."</td>".
-  "<td>".getField($key)."</td>";
+  if ($sections["services2"]) {
+    echo
+    " <tr>\n".
+    "  <th>Service</th>\n".
+    "  <th>Cost</th>\n".
+    "  <th>#</th>\n".
+    " </tr>\n";
+    
+    foreach ($services2_prices as $key => $item) {
+      echo 
+      " <tr><td>".$item["name"]."</td>".
+      "<td>".convPrice($item["price"])." / ".$item["subj"]."</td>".
+      "<td>".getField($key)."</td>";
 
-  if (isset($item["extra"])) {
-    echo "<td>+ ".getField($key."_extra")."</td>";
-  }
+      if (isset($item["extra"])) {
+        echo "<td>+ ".getField($key."_extra")."</td>";
+      }
   
-  echo "</tr>\n";
-}
-}
-?>
-</table>
-<p>
-Services total discount %: <? echo getField("services_discount"); ?>
-<br />
-<input type="submit" value=" Calculate " class="isubmit" />
-</p>
-<?
+      echo "</tr>\n";
+    }
+  } // services2 enabled
+
+  printSectionFooter($services);
+
 } // services1 || services2 enabled
-?>
 
-<h2>Power Reagents</h2>
-<p>
-Bulk orders may require time to complete, inquire. I keep some stock on reagents, though.
-</p>
-<table class="pritab">
-<?
-foreach ($reagent_prices as $fkey => $flist) {
-  echo "<tr><th colspan=\"5\">".$fkey."</th></tr>\n".
-  " <tr>\n".
-  "  <th>Type</th>\n".
-  "  <th>Spell</th>\n".
-  "  <th>Reagent</th>\n".
-  "  <th>Price</th>\n".
-  "  <th>#</th>\n".
-  " </tr>";
+
+if ($sections["reagents"]) {
+  printSectionHeader($reagents);
+  foreach ($reagent_prices as $fkey => $flist) {
+    echo "<tr><th colspan=\"5\">".$fkey."</th></tr>\n".
+    " <tr>\n".
+    "  <th>Type</th>\n".
+    "  <th>Spell</th>\n".
+    "  <th>Reagent</th>\n".
+    "  <th>Price</th>\n".
+    "  <th>#</th>\n".
+    " </tr>";
   
-  $row = 1;
-  foreach ($flist as $key => $item) {
-    $s = ($row % 2 == 1) ? "a" : "b";
-    echo " <tr class=\"".$s."\"><td class=\"".$item[0]."\">".$item[0].
-    "</td><td>".$item[1]."</td><td>".$item[2]."</td><td>".$item[3]."</td>".
-    "<td>".getField($key)."</td></tr>\n";
-    $row++;
+    $row = 1;
+    foreach ($flist as $key => $item) {
+      $s = ($row % 2 == 1) ? "a" : "b";
+      echo " <tr class=\"".$s."\"><td class=\"".$item[0]."\">".$item[0].
+      "</td><td>".$item[1]."</td><td>".$item[2]."</td><td>".$item[3]."</td>".
+      "<td>".getField($key)."</td></tr>\n";
+      $row++;
+    }
   }
-}
-?>
-</table>
-<p>
-Reagent total discount %: <? echo getField("reagent_discount"); ?>
-<br />
-<input type="submit" value=" Calculate " class="isubmit" />
-</p>
+  printSectionFooter($reagents);
+} // reagents enabled
 
-<?
+
 function printSection($sec)
 {
-  $name = $sec["name"];
+  printSectionHeader($sec);
   
-  echo "<h2>".$sec["title"]."</h2>\n";
-
-  if (isset($sec["desc"]))
-    echo "<p>".$sec["desc"]."</p>\n";
-  
-  echo "<table class=\"pritab\">\n".
-  " <tr>\n";
+  echo " <tr>\n";
   foreach ($sec["i_titles"] as $title)
     echo "  <th>".$title."</th>\n";
   echo " </tr>\n";
 
-
+  $name = $sec["name"];
   $base = isset($sec["base"]) ? $sec["base"] : 0;
   $row = 1;
   foreach ($sec["prices"] as $key => $item) {
@@ -438,16 +476,7 @@
     $row++;
   }
 
-  echo "</table>\n<p>\n";
-  
-  if ($sec["discount"]) {
-    echo "<p>".$sec["title"]." total discount %: ".
-    getField($name."_discount")."<br />\n".
-    "";
-  }
-
-  echo "<input type=\"submit\" value=\" Calculate \" class=\"isubmit\" />\n".
-  "</p>\n\n";
+  printSectionFooter($sec);
 }