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"; 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 "