From 99c95916fa6901a10f864f25f9a05f95d792902e Mon Sep 17 00:00:00 2001
From: Iain Patterson
Date: Sat, 12 Apr 2014 15:44:41 -0400
Subject: [PATCH] Track last selected area or city.
Unless a form was just submitted, no default option is set in a select
box, so the first option in alphabetical order is used. That can be
annoying, for instance, for users who mainly process data in one city
and find another city selected by default in all dropdowns.
On form submission we now track the selected city or area in a session
variable, and retrieve it when showing a form with no default option.
---
lib/area.php | 9 ++++++---
lib/contact.php | 4 ++++
lib/donation.php | 4 ++++
lib/forms.php | 1 +
lib/hub.php | 4 ++++
lib/order.php | 4 ++++
lib/session.php | 17 +++++++++++++++++
7 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/lib/area.php b/lib/area.php
index 9b0d5e1..77272f7 100644
--- a/lib/area.php
+++ b/lib/area.php
@@ -1,6 +1,7 @@
Added area.
\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 "Show areas in\n";
echo "\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 " \n";
echo " \n";
diff --git a/lib/contact.php b/lib/contact.php
index f376406..8013989 100644
--- a/lib/contact.php
+++ b/lib/contact.php
@@ -1,10 +1,12 @@
Added contact.
\n";
@@ -32,12 +34,14 @@
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']));
diff --git a/lib/donation.php b/lib/donation.php
index 20193fb..4fc7a8d 100644
--- a/lib/donation.php
+++ b/lib/donation.php
@@ -1,10 +1,12 @@
Donation recorded.\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']));
diff --git a/lib/forms.php b/lib/forms.php
index c71c11f..5751f78 100644
--- a/lib/forms.php
+++ b/lib/forms.php
@@ -43,6 +43,7 @@
function option($select, $value, $text, $selected = null) {
echo " $text\n";
}
diff --git a/lib/hub.php b/lib/hub.php
index 3d8e8d5..56caa57 100644
--- a/lib/hub.php
+++ b/lib/hub.php
@@ -1,10 +1,12 @@
Added hub.\n";
@@ -28,12 +30,14 @@
}
}
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']));
diff --git a/lib/order.php b/lib/order.php
index 6c75211..ac3cdfe 100644
--- a/lib/order.php
+++ b/lib/order.php
@@ -1,10 +1,12 @@
Order placed.\n";
@@ -26,12 +28,14 @@
}
}
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
index 9f415b8..da4e986 100644
--- a/lib/session.php
+++ b/lib/session.php
@@ -1,5 +1,22 @@
--
2.7.4