X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Fhub.php;fp=lib%2Fhub.php;h=a3a1121e810f637ebb1a113cb9cea0972f999149;hb=8549c1776033e924ea50328bd2434529d85b5669;hp=48b45ae992ff64808ef3b55691abfcd275869a61;hpb=b0b9828b27e140f88fb0b7867388376b329959cc;p=readifood.git diff --git a/lib/hub.php b/lib/hub.php index 48b45ae..a3a1121 100644 --- a/lib/hub.php +++ b/lib/hub.php @@ -40,18 +40,28 @@ exit; } + function show_hub_summary(&$hub, $editing = false) { + if ($editing) echo "

Hub: " . htmlspecialchars($hub->getName()) . ""; + else echo "
\nHub " . $hub->getStrongLink(); + $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()); + if (check_admin(1)) { + echo " " . $hub->getDeleteLink(); + } + $area = get_hub_area($hub); + if ($area) echo " in " . $area->getLink(); + $city = get_hub_city($hub); + if ($city) echo ", " . $city->getLink(get_city_displayname($city)); + } + function show_hubs($offset, $per_page, $address_ids) { $q = new HubQuery; $hubs = $q->filterByAddressId($address_ids)->find(); if (count($hubs)) { - foreach ($hubs as $hub) { - echo "
\nhub " . $hub->getLink(); - if (check_admin(1)) { - echo " " . $hub->getDeleteLink(); - } - $area = get_hub_area($hub); - echo " in " . $area->getLink(); - } + foreach ($hubs as $hub) show_hub_summary($hub); } else echo " none"; } @@ -70,7 +80,7 @@ $address_ids = array(); foreach ($addresses as $address) $address_ids[] = $address->getId(); - echo "

hubs in city " . $city->getLink(get_city_displayname($city)) . ":"; + echo "

Hubs in city " . $city->getLink(get_city_displayname($city)) . ":"; return show_hubs($offset, $per_page, $address_ids); } else echo "

No such city!

\n"; @@ -134,9 +144,19 @@ show_hub_cities_form($city_id); } + function show_hub_role_form($role) { + return show_role_form($role, $GLOBALS['hub_roles']); + } + function show_hub_form($hub = null, $area_id = null) { if (! $hub) $hub = new Hub; + /* Role. */ + echo "\n"; + echo " Role\n"; + echo " "; show_hub_role_form($hub->getRole()); echo "\n"; + echo "\n"; + /* Display name. */ echo "\n"; echo " Hub name\n"; @@ -230,6 +250,13 @@ } function update_hub(&$hub, $area_id, $new = false) { + global $hub_roles; + + $role = 0; + for ($i = 0; $i < count($hub_roles); $i++) { + if ($_POST['role_' . $i] == "on") $role |= (1 << $i); + } + $displayname = $_POST['displayname']; if (! $displayname) { @@ -264,6 +291,7 @@ $telephone2 = $_POST['telephone2']; $email = $_POST['email']; + $hub->setRole($role); $hub->setDisplayname($displayname); $hub->setTelephone1($telephone1); $hub->setTelephone2($telephone2); @@ -330,12 +358,7 @@ if (! $hub) return; echo "
\n"; - echo "

Hub: " . $hub->getDisplayname() . ""; - if (check_admin(1)) { - echo " " . $hub->getDeleteLink(); - } - $city = get_hub_city($hub); - if ($city) echo " in " . $city->getLink(get_city_displayname($city)); + show_hub_summary($hub, true); echo ": "; echo "\n

";