$week = array("Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat");
/* Contact roles. */
- $roles = array("Staff", "Driver", "Referrer", "Beneficiary", "Donor");
+ $contact_roles = array("Staff", "Driver", "Referrer", "Beneficiary", "Donor");
$ROLE_STAFF = 1 << 0;
$ROLE_DRIVER = 1 << 1;
$ROLE_REQUESTER = 1 << 2;
$ROLE_BENEFICIARY = 1 << 3;
$ROLE_DONOR = 1 << 4;
+ /* Hub types. */
+ $hub_roles = array("Collection", "Distribution");
+ $ROLE_COLLECTION = 1 << 0;
+ $ROLE_DISTRIBUTION = 1 << 1;
+
/* Order states. */
$states = array("placed", "picked", "despatched", "undelivered", "delivered", "cancelled");
$all_states = (1 << count($states)) - 1;
}
function show_contact_role_form($role) {
- global $roles;
-
- for ($i = 0; $i < count($roles); $i++) {
- echo " <input type=\"checkbox\" name=\"role_$i\"";
- if ($role & (1 << $i)) echo " checked";
- echo ">$roles[$i]\n";
- }
+ return show_role_form($role, $GLOBALS['contact_roles']);
}
function show_contact_form($contact = null) {
- global $roles;
+ global $contact_roles;
if (! $contact) $contact = new Contact;
}
function update_contact(&$contact, $area_id, $new = false) {
- global $roles;
+ global $contact_roles;
$role = 0;
- for ($i = 0; $i < count($roles); $i++) {
+ for ($i = 0; $i < count($contact_roles); $i++) {
if ($_POST['role_' . $i] == "on") $role |= (1 << $i);
}
return get_city_contacts($city_id, $GLOBALS['ROLE_DRIVER']);
}
- function get_contact_role_string($contact) {
- global $roles;
-
- $role = $contact->getRole();
+ function get_role_string($object, $roles) {
+ $role = $object->getRole();
$selected = array();
return implode(", ", $selected);
}
+ function get_contact_role_string($contact) {
+ return get_role_string($contact, $GLOBALS['contact_roles']);
+ }
+
+ function get_hub_role_string($hub) {
+ return get_role_string($hub, $GLOBALS['hub_roles']);
+ }
+
+ function show_role_form($role, $roles) {
+ for ($i = 0; $i < count($roles); $i++) {
+ echo " <input type=\"checkbox\" name=\"role_$i\"";
+ if ($role & (1 << $i)) echo " checked";
+ echo ">$roles[$i]\n";
+ }
+ }
+
function get_area_hubs($area_id = null) {
$q = new HubQuery;
if (isset($area_id)) $q->useAddressQuery()->filterByAreaId($area_id)->endUse();
exit;
}
+ function show_hub_summary(&$hub, $editing = false) {
+ if ($editing) echo "<p>Hub: <span class=\"strong\">" . htmlspecialchars($hub->getName()) . "</span>";
+ else echo "<br>\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(" <a class=\"small\" href=\"/donation/to/hub/%s/%d\">Donations</a>", urlencode($hub->getName()), $hub->getId());
+ if ($role & $GLOBALS['ROLE_DISTRIBUTION']) printf(" <a class=\"small\" href=\"/order/to/hub/%s/%d\">Orders</a>", 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 "<br>\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";
}
$address_ids = array();
foreach ($addresses as $address) $address_ids[] = $address->getId();
- echo "<p>hubs in city " . $city->getLink(get_city_displayname($city)) . ":";
+ echo "<p>Hubs in city " . $city->getLink(get_city_displayname($city)) . ":";
return show_hubs($offset, $per_page, $address_ids);
}
else echo "<p>No such city!</p>\n";
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 "<tr>\n";
+ echo " <td>Role</td>\n";
+ echo " <td>"; show_hub_role_form($hub->getRole()); echo "</td>\n";
+ echo "</tr>\n";
+
/* Display name. */
echo "<tr>\n";
echo " <td>Hub name</td>\n";
}
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) {
$telephone2 = $_POST['telephone2'];
$email = $_POST['email'];
+ $hub->setRole($role);
$hub->setDisplayname($displayname);
$hub->setTelephone1($telephone1);
$hub->setTelephone2($telephone2);
if (! $hub) return;
echo "<form method=\"POST\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n";
- echo "<p>Hub: <span class=\"strong\">" . $hub->getDisplayname() . "</span>";
- 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</p>";