From 6bd4ad3daf2cc870d96a3fed9ea9caf6798d2b78 Mon Sep 17 00:00:00 2001
From: Iain Patterson
Date: Mon, 13 May 2013 04:33:23 -0400
Subject: [PATCH] Tidy up forms.
Use form() and end_form() where appropriate.
Use standout and noprint classes to emphasise forms and to hide those
which don't show any information.
Ensure that all appropriate forms are shown once. Not never; not twice.
---
lib/area.php | 12 +++++------
lib/city.php | 10 +++++-----
lib/contact.php | 32 ++++++++++-------------------
lib/donation.php | 29 ++++++++++-----------------
lib/hub.php | 30 ++++++++++------------------
lib/order.php | 52 ++++++++++++------------------------------------
6 files changed, 54 insertions(+), 111 deletions(-)
diff --git a/lib/area.php b/lib/area.php
index b2ac8c8..51f57d3 100644
--- a/lib/area.php
+++ b/lib/area.php
@@ -53,7 +53,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_new_area_form($city_id = null) {
@@ -74,7 +74,7 @@
return;
}
- echo "\n";
+ end_form();
}
function add_area($name, $city_id) {
@@ -211,7 +211,7 @@
$area = get_area_by_name($name);
if (! $area) return;
- echo "\n";
+ end_form();
}
/* /area/in/Cambridge/1 */
diff --git a/lib/city.php b/lib/city.php
index 1294176..47cfc24 100644
--- a/lib/city.php
+++ b/lib/city.php
@@ -36,7 +36,7 @@
function show_new_city_form() {
if (! check_admin(1)) return;
- echo "\n";
}
function show_contact_cities_form($city_id = null) {
@@ -149,7 +147,6 @@
return;
}
- echo "\n";
}
function show_contact_search_form() {
- echo "\n";
}
function show_contact_forms($city_id) {
+ form("noprint standout");
show_contact_areas_form($city_id);
show_contact_cities_form($city_id);
show_contact_search_form();
+ end_form();
}
function show_contact_role_form($role) {
@@ -325,7 +321,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_add_new_contact_form() {
@@ -348,7 +344,7 @@
return;
}
- echo "\n";
+ end_form();
}
function update_contact(&$contact, $area_id, $new = false) {
@@ -496,7 +492,7 @@
else $contact = get_contact_by_name($name);
if (! $contact) return;
- echo "
";
@@ -513,7 +509,7 @@
}
echo "\n";
- echo "\n";
+ end_form();
}
/* /contact/in/area/Cambridge/1 */
@@ -538,8 +534,6 @@
show_city_contacts(0, 10, $parameters[2], $city_id);
break;
}
-
- show_add_new_contact_form($city_id);
}
else if ($parameters[0] == "search") {
search_contacts(0, 10, $parameters[1]);
@@ -555,14 +549,8 @@
}
}
else if (isset($name)) show_contact($name, $id);
- else {
- /* XXX: Shown after adding. */
- show_contact_forms($city_id);
- show_add_new_contact_form($city_id);
- }
- if (count($parameters)) {
- show_contact_forms($city_id);
- }
+ show_contact_forms($city_id);
+ show_add_new_contact_form($city_id);
?>
diff --git a/lib/donation.php b/lib/donation.php
index 16b0197..e9c75da 100644
--- a/lib/donation.php
+++ b/lib/donation.php
@@ -127,7 +127,6 @@
return;
}
- echo "\n";
}
function show_donation_cities_form($city_id = null) {
@@ -147,7 +145,6 @@
return;
}
- echo "\n";
}
function show_donation_forms($city_id) {
+ form("noprint standout");
show_donation_areas_form($city_id);
show_donation_cities_form($city_id);
+ end_form();
}
function show_donation_form($donation = null, $area_id = null) {
@@ -210,7 +208,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_add_new_donation_form() {
@@ -233,7 +231,7 @@
return;
}
- echo "\n";
+ end_form();
}
function update_donation(&$donation, $new = false) {
@@ -318,7 +316,7 @@
if (isset($id)) $donation = get_donation_by_id($id);
if (! $donation) return;
- echo "\n";
+ end_form();
}
if (count($parameters)) {
@@ -397,15 +395,8 @@
}
}
else if (isset($id)) show_donation($id);
- else {
- /* XXX: Shown after adding. */
- show_donation_forms($city_id);
- show_add_new_donation_form($city_id);
- }
-
- if (count($parameters)) {
- show_donation_forms($city_id);
- }
+ show_donation_forms($city_id);
+ show_add_new_donation_form($city_id);
?>
diff --git a/lib/hub.php b/lib/hub.php
index a3a1121..79051f8 100644
--- a/lib/hub.php
+++ b/lib/hub.php
@@ -108,7 +108,6 @@
return;
}
- echo "\n";
}
function show_hub_cities_form($city_id = null) {
@@ -128,7 +126,6 @@
return;
}
- echo "\n";
}
function show_hub_forms($city_id) {
+ form("noprint standout");
show_hub_areas_form($city_id);
show_hub_cities_form($city_id);
+ end_form();
}
function show_hub_role_form($role) {
@@ -215,7 +213,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_add_new_hub_form() {
@@ -238,7 +236,7 @@
return;
}
- echo "\n";
+ end_form();
}
function update_hub(&$hub, $area_id, $new = false) {
@@ -357,7 +355,7 @@
else $hub = get_hub_by_name($name);
if (! $hub) return;
- echo "\n";
+ end_form();
}
/* /hub/in/area/Cambridge/1 */
@@ -399,8 +397,6 @@
show_city_hubs(0, 10, $parameters[2], $city_id);
break;
}
-
- show_new_hub_form($city_id);
}
}
list($name, $id, $args) = parse_parameters($parameters);
@@ -413,14 +409,8 @@
}
}
else if (isset($name)) show_hub($name, $id);
- else {
- /* XXX: Shown after adding. */
- show_hub_forms($city_id);
- show_add_new_hub_form($city_id);
- }
- if (count($parameters)) {
- show_hub_forms($city_id);
- }
+ show_hub_forms($city_id);
+ show_add_new_hub_form($city_id);
?>
diff --git a/lib/order.php b/lib/order.php
index 69026bf..38a235a 100644
--- a/lib/order.php
+++ b/lib/order.php
@@ -50,27 +50,7 @@
$orders = $q->orderByDate()->find();
if (count($orders)) {
foreach ($orders as $order) {
- echo "
\nOrder " . $order->getStrongLink($order->getId()) . ": " . get_order_displayname($order);
- if (check_admin(1)) {
- echo " " . $order->getDeleteLink();
- }
-
- /* XXX: Should pull from query. */
- $q = new ContactQuery;
- $contact = $q->findOneById($order->getBeneficiaryId());
- if ($contact) {
- echo " for " . $contact->getLink();
- $area = get_contact_area($contact);
- if ($area) echo " in " . $area->getLink();
- }
-
- if ($order->getHubId()) {
- $q = new HubQuery;
- $hub = $q->findOneById($order->getHubId());
- if ($hub) echo " to hub " . $hub->getLink();
- $area = get_hub_area($hub);
- if ($area) echo " in " . $area->getLink();
- }
+ echo "
\n" . get_order_summary($order) . "
\n";
}
}
else echo " none";
@@ -215,11 +195,11 @@
}
function show_order_forms($city_id, $state_mask) {
- echo "\n";
+ end_form();
}
function show_order_form($order = null, $area_id = null) {
@@ -352,7 +332,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_contact_order_form($contact) {
@@ -377,7 +357,7 @@
$order = new Order;
$order->setBeneficiaryId($contact->getId());
- echo "\n";
+ end_form();
}
function show_add_new_order_form() {
@@ -406,7 +386,7 @@
return;
}
- echo "\n";
+ end_form();
}
function update_order(&$order, $new = false) {
@@ -570,7 +550,7 @@
if (isset($id)) $order = get_order_by_id($id);
if (! $order) return;
- echo "\n";
+ end_form();
show_order_history($order->getId());
}
@@ -670,15 +650,9 @@
}
else if (isset($id)) show_order($id);
else if ($state_mask) show_orders(0, 10, null, null, $state_mask);
- else {
- /* XXX: Shown after adding. */
- show_order_forms($city_id, $state_mask);
- show_add_new_order_form($city_id);
- }
- if (count($parameters)) {
- show_order_forms($city_id, $state_mask);
- }
+ show_order_forms($city_id, $state_mask);
+ show_add_new_order_form($city_id);
?>
--
2.20.1