changeset 195:c75ca644f2df misc

Sync; Fix HTML validation errors, add functionality for fetching current reagent stock data from a file (undocumented, however, other users will just have to figure it out themselves.)
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Feb 2011 16:30:51 +0200
parents 1b5fdb431582
children de3bb01d602d
files prices.php
diffstat 1 files changed, 49 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/prices.php	Sat Feb 05 21:18:32 2011 +0200
+++ b/prices.php	Sun Feb 13 16:30:51 2011 +0200
@@ -24,7 +24,7 @@
 // General settings
 $pageIndex = "prices.php";
 $pageTitle = "Ggr's Merchant Pricelist";
-$pageCharset = "ISO-8859-1";
+$pageCharset = "UTF-8";
 //$pageCSS = "foobar.css";  // Uncomment and change this, if you want to use your own CSS stylesheet file
 
 
@@ -131,9 +131,10 @@
   "name"     => "reagents",
   "title"    => "Power reagents",
   "discount" => true,	// enable discounts for this section
+  "datafile" => "reagents.txt",
 
   "desc"     => "Bulk orders may require time to complete, inquire.
-I keep some stock on reagents, though.",
+<b>Notice! Availability presented below may or may not reflect the current stock situation.</b>",
 );
 
 $reagent_prices = array(
@@ -214,7 +215,7 @@
 <b>Salve orders will take some time to complete, I don't keep much stock on these currently.</b>
 ",
 
-  "base" => 4000,
+  "base" => 6000,
   "discount" => false,
 
   "i_fields" => 1,
@@ -239,7 +240,7 @@
 potions sooner rather than later, ask someone else!
 ",
 
-  "base" => 5000,
+  "base" => 5500,
   "discount" => false,
 
   "i_fields" => 1,
@@ -324,7 +325,7 @@
   echo "</table>\n<p>\n";
   
   if ($sec["discount"]) {
-    echo "<p>".$sec["title"]." total discount %: ".
+    echo $sec["title"]." total discount %: ".
     getField($sec["name"]."_discount")."<br />\n".
     "";
   }
@@ -335,10 +336,16 @@
 
 //============================================================================
 
-echo "<?xml version=\"1.0\" encoding=\"".$pageCharset."\"?>\n";
+if (1) {
+  echo "<?xml version=\"1.0\" encoding=\"".$pageCharset."\"?>\n".
+  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n".
+//  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
+  "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n";
+} else {
+  echo "<!DOCTYPE HTML>\n".
+  "<html>\n";
+}
 ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=<? echo $pageCharset; ?>" />
  <title><? echo $pageTitle; ?></title>
@@ -359,6 +366,8 @@
  
  h1,h2,h3,h4  { color: #f00; border-bottom: 1px solid #c00; }
 
+ .hide { display: none; }
+
  .phys { color: #ddd; }
  .fire { color: #f00; }
  .cold { color: #00f; }
@@ -382,7 +391,8 @@
 if (isset($global_desc))
   echo $global_desc;
 
-echo "\n<form action=\"".$pageIndex."\" method=\"post\" autocomplete=\"off\">\n";
+echo "\n<form action=\"".$pageIndex."\" method=\"post\" autocomplete=\"off\">\n".
+"<p><input type=\"hidden\" name=\"ok\" value=\"ok\" /></p>\n";
 
 if ($sections["services1"] || $sections["services2"]) {
 
@@ -396,10 +406,11 @@
       "  <th>".$item["name"]."</th>\n".
       "  <th>Cost</th>\n".
       "  <th>#</th>\n".
+      "  <th class=\"hide\"></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".
+      "<td>-</td><td class=\"hide\"></td></tr>\n".
       " <tr><td>".$item["tresh"]."+ ".$item["subj"]."s</td><td>";
 
       if (isset($item["base"])) {
@@ -409,9 +420,11 @@
       }
 
       echo "</td><td>".getField($key)."</td>";
-  
+
       if (isset($item["extra"])) {
         echo "<td>+ ".getField($key."_extra")."</td>";
+      } else {
+        echo "<td class=\"hide\"></td>";
       }
   
       echo "</tr>\n";
@@ -425,6 +438,7 @@
     "  <th>Service</th>\n".
     "  <th>Cost</th>\n".
     "  <th>#</th>\n".
+    "  <th class=\"hide\"></th>\n".
     " </tr>\n";
     
     foreach ($services2_prices as $key => $item) {
@@ -435,6 +449,8 @@
 
       if (isset($item["extra"])) {
         echo "<td>+ ".getField($key."_extra")."</td>";
+      } else {
+        echo "<td></td>\n";
       }
   
       echo "</tr>\n";
@@ -447,15 +463,30 @@
 
 
 if ($sections["reagents"]) {
+  $showSupply = FALSE;
+  if (file_exists($reagents["datafile"])) {
+    $data = @file_get_contents($reagents["datafile"]);
+    if ($data !== FALSE) {	
+      $supply = array();
+      $lines = explode("\n", strtolower($data));
+      foreach ($lines as $line) {
+        $tmp = explode("|", $line);
+        $supply[$tmp[1]] = $tmp[0];
+      }
+      $showSupply = TRUE;
+    }
+  }
+
   printSectionHeader($reagents);
   foreach ($reagent_prices as $fkey => $flist) {
-    echo "<tr><th colspan=\"5\">".$fkey."</th></tr>\n".
+    echo "<tr><th colspan=\"".($showSupply ? 6 : 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".
+    ($showSupply ? "  <th>Avail</th>\n" : "").
     " </tr>";
   
     $row = 1;
@@ -463,7 +494,11 @@
       $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";
+      "<td>".getField($key)."</td>";
+      $spell = strtolower($item[1]);
+      if ($showSupply && isset($supply[$spell]))
+        echo "<td>".$supply[$spell]."</td>";
+      echo "</tr>\n";
       $row++;
     }
   }
@@ -506,10 +541,7 @@
 if ($sections["potions"]) printSection($potions);
 if ($sections["salves"]) printSection($salves);
 
-?>
-<input type="hidden" name="ok" value="ok" />
-</form>
-<?
+echo "</form>\n";
 
 } else {