From f7127ce189cb772fc0623bff047e063c66c81ee1 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Thu, 12 Mar 2015 12:36:01 -0400 Subject: [PATCH] Record donation directly from hub list. Show a new "Record" link next to Collection hubs, opening the donation form with the hub preselected. --- lib/donation.php | 34 ++++++++++++++++++++++++++++++++++ lib/hub.php | 9 +++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/donation.php b/lib/donation.php index 4fc7a8d..b1aba40 100644 --- a/lib/donation.php +++ b/lib/donation.php @@ -240,6 +240,31 @@ end_form(); } + function show_hub_donation_form($hub) { + if (! check_admin(1)) return; + + $area = get_hub_area($hub); + if (! $area) { + echo "

No such area!

\n"; + return; + } + + $donation = new Donation; + $donation->setHubId($hub->getId()); + + form(); + echo "

Record a donation:

\n"; + + echo "\n"; + show_donation_form($donation, $area->getId()); + + echo "\n"; + echo " \n"; + echo "\n"; + echo "
"; submit("add_donation", "Record"); echo "
\n"; + end_form(); + } + function show_add_new_donation_form() { if (! check_admin(1)) return; @@ -412,6 +437,15 @@ break; } } + else if ($parameters[0] == "record") { + if ($parameters[1] == "to") { + if ($parameters[2] == "hub") { + if ($parameters[4]) $hub = get_hub_by_id($parameters[4]); + if (! $hub) $hub = get_hub_by_name(urldecode($parameters[3])); + if ($hub) show_hub_donation_form($hub); + } + } + } } list($ignored, $id, $args) = parse_parameters($parameters); //echo "

$name($id) " . print_r($args, true) . "

\n"; diff --git a/lib/hub.php b/lib/hub.php index 56caa57..176903d 100644 --- a/lib/hub.php +++ b/lib/hub.php @@ -50,8 +50,13 @@ $role = $hub->getRole(); $role_string = get_hub_role_string($hub); if ($role_string) echo " $role_string"; - if ($role & $GLOBALS['ROLE_COLLECTION']) printf(" Donations", urlencode($hub->getName()), $hub->getId()); - if ($role & $GLOBALS['ROLE_DISTRIBUTION']) printf(" Orders", urlencode($hub->getName()), $hub->getId()); + $d = urlencode($hub->getName()); + $i = $hub->getId(); + if ($role & $GLOBALS['ROLE_COLLECTION']) { + printf(" Donations", $d, $i); + echo " " . get_small_link("Record", "/donation/record/to/hub/%s/%d", $d, $i); + } + if ($role & $GLOBALS['ROLE_DISTRIBUTION']) printf(" Orders", $d, $i); if (check_admin(1)) { echo " " . $hub->getDeleteLink(); } -- 2.20.1