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"; + form("noprint standout"); echo "

Show areas in\n"; echo "\n"; echo "\n"; - echo "

\n"; + end_form(); } function show_new_area_form($city_id = null) { @@ -74,7 +74,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Add a new area \n"; echo "in \n"; echo "\n"; - 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"; + form(); echo "

Area: " . $area->getName() . ""; $n = $area->getName(); $i = $area->getId(); @@ -234,7 +234,7 @@ echo "\n"; } echo "

\n"; - 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"; + form("noprint standout"); echo "

Add a new city \n"; echo "with postcode prefix \n"; echo "

\n"; @@ -138,10 +138,10 @@ } } else if (isset($name)) show_city($name, $id); - else { - show_cities(0, 10); - show_new_city_form(); - } + else show_cities(0, 10); + + if (count($parameters)) echo "

Show all cities

\n"; + show_new_city_form(); # XXX: Format URL in branch case... if (count($parameters)) diff --git a/lib/contact.php b/lib/contact.php index c561023..2dd65ab 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -129,7 +129,6 @@ return; } - echo "\n"; echo "

Show contacts in area\n"; echo "\n"; echo "\n"; - echo "

\n"; } function show_contact_cities_form($city_id = null) { @@ -149,7 +147,6 @@ return; } - echo "
\n"; echo "

Show contacts in city\n"; echo "\n"; echo "\n"; - echo "

\n"; } function show_contact_search_form() { - echo "
\n"; echo "

Search for contacts:"; input("search_contact"); echo "\n"; - 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"; + form("noprint"); echo "

Add a new contact:

\n"; echo "\n"; @@ -335,7 +331,7 @@ echo " \n"; echo "\n"; echo "
"; submit("add_contact", "Add"); echo "
\n"; - echo "
\n"; + end_form(); } function show_add_new_contact_form() { @@ -348,7 +344,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Add a new contact in "; submit("show_add_contact", "Proceed"); echo "

\n"; - 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 "
\n"; + form(); show_contact_summary($contact, true); echo ": "; echo "\n

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

Show donations in area\n"; echo "\n"; echo "\n"; - echo "

\n"; } function show_donation_cities_form($city_id = null) { @@ -147,7 +145,6 @@ return; } - echo "
\n"; echo "

Show donations in city\n"; echo "\n"; echo "\n"; - 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"; + form(); echo "

Record a donation:

\n"; echo "\n"; @@ -220,7 +218,7 @@ echo " \n"; echo "\n"; echo "
"; submit("add_donation", "Record"); echo "
\n"; - echo "
\n"; + end_form(); } function show_add_new_donation_form() { @@ -233,7 +231,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Record a donation in "; submit("show_add_donation", "Proceed"); echo "

\n"; - 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"; + form(); echo "

Donation " . $donation->getId() . ""; if (check_admin(1)) { echo " " . $donation->getDeleteLink(); @@ -338,7 +336,7 @@ } echo "\n"; - 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"; echo "

Show hubs in area\n"; echo "\n"; echo "\n"; - echo "

\n"; } function show_hub_cities_form($city_id = null) { @@ -128,7 +126,6 @@ return; } - echo "
\n"; echo "

Show hubs in city\n"; echo "\n"; echo "\n"; - 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"; + form("noprint"); echo "

Add a new hub:

\n"; echo "\n"; @@ -225,7 +223,7 @@ echo " \n"; echo "\n"; echo "
"; submit("add_hub", "Add"); echo "
\n"; - echo "
\n"; + end_form(); } function show_add_new_hub_form() { @@ -238,7 +236,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Add a new hub in "; submit("show_add_hub", "Proceed"); echo "

\n"; - 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"; + form(); show_hub_summary($hub, true); echo ": "; echo "\n

"; @@ -374,7 +372,7 @@ } echo "\n"; - 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"; + form("noprint standout"); show_order_state_form($state_mask); show_order_areas_form($city_id); show_order_cities_form($city_id); - echo "
\n"; + end_form(); } function show_order_form($order = null, $area_id = null) { @@ -352,7 +332,7 @@ return; } - echo "
\n"; + form("noprint"); echo "

Place an order:

\n"; echo "\n"; @@ -362,7 +342,7 @@ echo " \n"; echo "\n"; echo "
"; submit("add_order", "Order"); echo "
\n"; - echo "
\n"; + end_form(); } function show_contact_order_form($contact) { @@ -377,7 +357,7 @@ $order = new Order; $order->setBeneficiaryId($contact->getId()); - echo "
\n"; + form("standout"); echo "

Placing order for " . $contact->getStrongLink() . "."; $parcel = $contact->getParcel(); if ($parcel) { @@ -393,7 +373,7 @@ echo " "; submit("add_order", "Order"); echo "\n"; echo "\n"; echo "\n"; - echo "

\n"; + end_form(); } function show_add_new_order_form() { @@ -406,7 +386,7 @@ return; } - echo "
\n"; + form("noprint standout"); echo "

Place an order in "; submit("show_add_order", "Proceed"); echo "

\n"; - 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"; + form(); echo "

Order: " . $order->getId() . ""; if (check_admin(1)) { echo " " . $order->getDeleteLink(); @@ -590,7 +570,7 @@ } echo "\n"; - 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