From f44ed8d0e1de072ea341c013c967714cd0217fee Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Sat, 12 Apr 2014 15:41:12 -0400 Subject: [PATCH 01/16] Store session variables. Start a session so we can keep track of user preferences later. --- lib/footer.php | 1 + lib/session.php | 5 +++++ www/index.php | 1 + 3 files changed, 7 insertions(+) create mode 100644 lib/session.php diff --git a/lib/footer.php b/lib/footer.php index 3ccf4a8..da9130d 100644 --- a/lib/footer.php +++ b/lib/footer.php @@ -2,3 +2,4 @@ + diff --git a/lib/session.php b/lib/session.php new file mode 100644 index 0000000..9f415b8 --- /dev/null +++ b/lib/session.php @@ -0,0 +1,5 @@ + diff --git a/www/index.php b/www/index.php index 4468e05..ae8b5a1 100644 --- a/www/index.php +++ b/www/index.php @@ -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); -- 2.20.1 From 99c95916fa6901a10f864f25f9a05f95d792902e Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Sat, 12 Apr 2014 15:44:41 -0400 Subject: [PATCH 02/16] 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 "