Merge branch 'master' into uat uat-2014-04-12
authorIain Patterson <me@iain.cx>
Sat, 12 Apr 2014 19:58:54 +0000 (15:58 -0400)
committerIain Patterson <me@iain.cx>
Sat, 12 Apr 2014 19:58:54 +0000 (15:58 -0400)
lib/area.php
lib/contact.php
lib/donation.php
lib/footer.php
lib/forms.php
lib/hub.php
lib/order.php
lib/session.php [new file with mode: 0644]
www/index.php

index 9b0d5e1..77272f7 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
   if ($_POST['area_name']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $id = add_area($_POST['area_name'], $_POST['city_id']);
     if ($id !== false) {
       echo "<p>Added area.</p>\n";
@@ -8,8 +9,10 @@
     }
   }
   else if ($_POST['city_id']) {
-    /* XXX: city_id is actually a string $city_name/$city_id */
-    header(sprintf("Location: http%s://%s/%s/in/city/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['city_id']));
+    set_last_selected("city_id", $_POST['city_id']);
+    $city_id = $_POST['city_id'];
+    $city = get_city_by_id($city_id);
+    header(sprintf("Location: http%s://%s/%s/in/city/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $city->getName(), $city_id));
     exit;
   }
   else if ($_POST['update_area']) {
@@ -64,7 +67,7 @@
     echo "<p>Show areas in\n";
     echo "<select name=\"city_id\">\n";
     foreach ($candidates as $city) {
-      option("city_id", sprintf("%s/%s", $city->getName(), $city->getId()), get_city_displayname($city));
+      option("city_id", $city->getId(), get_city_displayname($city));
     }
     echo "</select>\n";
     echo "<input type=\"submit\" value=\"Show\">\n";
index f376406..8013989 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 
   if (isset($_POST['show_add_contact'])) {
+    set_last_selected("city_id", $_POST['city_id']);
     $city_id = $_POST['city_id'];
     show_new_contact_form($city_id);
   }
   else if (isset($_POST['add_contact'])) {
+    set_last_selected("area_id", $area_id);
     $id = add_contact($displayname);
     if ($id !== false) {
       echo "<p>Added contact.</p>\n";
     exit;
   }
   else if ($_POST['show_in_area']) {
+    set_last_selected("area_id", $_POST['area_id']);
     $q = new AreaQuery;
     $area = $q->findOneById($_POST['area_id']);
     header(sprintf("Location: http%s://%s/%s/in/area/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id']));
     exit;
   }
   else if ($_POST['show_in_city']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $q = new CityQuery;
     $city = $q->findOneById($_POST['city_id']);
     header(sprintf("Location: http%s://%s/%s/in/city/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id']));
index 20193fb..4fc7a8d 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 
   if (isset($_POST['show_add_donation'])) {
+    set_last_selected("area_id", $_POST['area_id']);
     $area_id = $_POST['area_id'];
     show_new_donation_form($area_id);
   }
   else if (isset($_POST['add_donation'])) {
+    set_last_selected("area_id", $_POST['area_id']);
     $id = add_donation();
     if ($id !== false) {
       echo "<p>Donation recorded.</p>\n";
@@ -26,6 +28,7 @@
     }
   }
   else if ($_POST['show_in_area']) {
+    set_last_selected("area_id", $_POST['area_id']);
     $q = new AreaQuery;
     $area = $q->findOneById($_POST['area_id']);
     /* XXX: Function to build URL because we need to set a class in links. */
@@ -33,6 +36,7 @@
     exit;
   }
   else if ($_POST['show_in_city']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $q = new CityQuery;
     $city = $q->findOneById($_POST['city_id']);
     header(sprintf("Location: http%s://%s/%s/in/city/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id']));
index 3ccf4a8..da9130d 100644 (file)
@@ -2,3 +2,4 @@
 <div id="popup"></div>
 </body>
 </html>
+<?php session_write_close(); ?>
index c71c11f..5751f78 100644 (file)
@@ -43,6 +43,7 @@
   function option($select, $value, $text, $selected = null) {
     echo "  <option value=\"$value\"";
     if (! isset($selected)) $selected = $_POST[$select];
+    if (! isset($selected)) $selected = get_last_selected($select);
     if ($value == $selected) echo " selected";
     echo ">$text\n";
   }
index 3d8e8d5..56caa57 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 
   if (isset($_POST['show_add_hub'])) {
+    set_last_selected("city_id", $_POST['city_id']);
     $city_id = $_POST['city_id'];
     show_new_hub_form($city_id);
   }
   else if (isset($_POST['add_hub'])) {
+    set_last_selected("area_id", $_POST['area_id']);
     $id = add_hub($displayname);
     if ($id !== false) {
       echo "<p>Added hub.</p>\n";
     }
   }
   else if ($_POST['show_in_area']) {
+    set_last_selected("area_id", $_POST['area_id']);
     $q = new AreaQuery;
     $area = $q->findOneById($_POST['area_id']);
     header(sprintf("Location: http%s://%s/%s/in/area/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id']));
     exit;
   }
   else if ($_POST['show_in_city']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $q = new CityQuery;
     $city = $q->findOneById($_POST['city_id']);
     header(sprintf("Location: http%s://%s/%s/in/city/%s/%d", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id']));
index 6c75211..ac3cdfe 100644 (file)
@@ -1,10 +1,12 @@
 <?php
 
   if (isset($_POST['show_add_order'])) {
+    set_last_selected("area_id", $_POST['area_id']);
     $area_id = $_POST['area_id'];
     show_new_order_form($area_id);
   }
   else if (isset($_POST['add_order'])) {
+    set_last_selected("area_id", $_POST['area_id']);
     $id = add_order();
     if ($id !== false) {
       echo "<p>Order placed.</p>\n";
     }
   }
   else if ($_POST['show_in_area']) {
+    set_last_selected("area_id", $_POST['area_id']);
     $q = new AreaQuery;
     $area = $q->findOneById($_POST['area_id']);
     header(sprintf("Location: http%s://%s/%s/in/area/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id'], get_order_state_query_uri(get_order_state_mask())));
     exit;
   }
   else if ($_POST['show_in_city']) {
+    set_last_selected("city_id", $_POST['city_id']);
     $q = new CityQuery;
     $city = $q->findOneById($_POST['city_id']);
     header(sprintf("Location: http%s://%s/%s/in/city/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id'], get_order_state_query_uri(get_order_state_mask())));
diff --git a/lib/session.php b/lib/session.php
new file mode 100644 (file)
index 0000000..da4e986
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+  /* Retrieve the last selected choice in a select field. */
+  function get_last_selected($name) {
+    $key = "last_$name";
+    $ret = $_SESSION[$key];
+    error_log("last selected $name is $ret");
+    return $_SESSION[$key];
+  }
+
+  /* Remember the last selected choice in a select field. */
+  function set_last_selected($name, $value) {
+    if (isset($value)) error_log("setting last selected $name to $value");
+    else error_log("not setting last selected $name null");
+    if (! isset($value)) return;
+    $key = "last_$name";
+    $_SESSION[$key] = $value;
+  }
+
+  session_start();
+
+?>
index 4468e05..ae8b5a1 100644 (file)
@@ -32,6 +32,7 @@
   $username = $_SERVER['REMOTE_USER'];
   include_once("$lib_root/constants.php");
   include_once("$lib_root/functions.php");
+  include_once("$lib_root/session.php");
   include_once("$lib_root/header.php");
   $q = new UserQuery;
   $user = $q->findOneByUsername($username);