X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;ds=inline;f=lib%2Forder.php;h=6c752117214d2405ae53c5c531b887e00a645e2b;hb=refs%2Ftags%2Flive-2013-12-12;hp=f1911c587521c57883c76591fcf792e23ec328eb;hpb=a2e796d4502f96c1ec0e85dd22c7eccf7d1d9ac3;p=readifood.git
diff --git a/lib/order.php b/lib/order.php
index f1911c5..6c75211 100644
--- a/lib/order.php
+++ b/lib/order.php
@@ -28,26 +28,19 @@
else if ($_POST['show_in_area']) {
$q = new AreaQuery;
$area = $q->findOneById($_POST['area_id']);
- header(sprintf("Location: http%s://%s/%s/in/area/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id'], get_order_state_uri(get_order_state_mask())));
+ header(sprintf("Location: http%s://%s/%s/in/area/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($area->getName()), $_POST['area_id'], get_order_state_query_uri(get_order_state_mask())));
exit;
}
else if ($_POST['show_in_city']) {
$q = new CityQuery;
$city = $q->findOneById($_POST['city_id']);
- header(sprintf("Location: http%s://%s/%s/in/city/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id'], get_order_state_uri(get_order_state_mask())));
+ header(sprintf("Location: http%s://%s/%s/in/city/%s/%d%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, urlencode($city->getName()), $_POST['city_id'], get_order_state_query_uri(get_order_state_mask())));
exit;
}
function show_orders($offset, $per_page, $requester_ids = null, $beneficiary_ids = null, $state_mask = null) {
/* XXX: Use Propel methods. */
- if (isset($state_mask)) {
- $order_ids = array();
- $dbh = Propel::getConnection();
- $sth = $dbh->prepare("select * from OrderState o where updated=(select max(updated) from OrderState where order_id=o.order_id) and state & $state_mask");
- $sth->execute();
- $order_states = OrderStatePeer::populateObjects($sth);
- foreach ($order_states as $order_state) $order_ids[] = $order_state->getOrderId();
- }
+ if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask);
$q = new OrderQuery;
if (isset($requester_ids)) $q->filterByRequesterId($requester_ids);
if (isset($beneficiary_ids)) $q->filterByBeneficiaryId($beneficiary_ids);
@@ -57,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";
@@ -138,9 +111,9 @@
echo "
Restrict to order states:\n"; for ($i = 0; $i < count($states); $i++) { - echo " $states[$i]\n"; + echo ">\n"; } echo "
\n"; } @@ -166,7 +139,7 @@ return $mask; } - function get_order_state_string($mask) { + function get_order_state_query_string($mask) { global $states; $selected = array(); @@ -178,13 +151,13 @@ return implode("+", $selected); } - function get_order_state_uri($mask) { + function get_order_state_query_uri($mask) { global $all_states; if (is_null($mask)) return ""; if ($mask == $all_states) return ""; - return "/state/" . get_order_state_string($mask); + return "/state/" . get_order_state_query_string($mask); } function show_order_areas_form($city_id = null) { @@ -194,9 +167,16 @@ return; } + $candidates = array(); + foreach ($areas as $area) { + if (! count(get_area_contacts($area->getId()))) continue; + $candidates[] = $area; + } + if (! count($candidates)) return; + echo "Show orders in area\n"; echo "\n"; @@ -212,9 +192,16 @@ return; } + $candidates = array(); + foreach ($cities as $city) { + if (! count(get_city_contacts($city->getId()))) continue; + $candidates[] = $city; + } + if (! count($candidates)) return; + echo "
Show orders in city\n"; echo "\n"; @@ -222,19 +209,18 @@ } function show_order_forms($city_id, $state_mask) { - echo "
\n"; + end_form(); } function show_order_form($order = null, $area_id = null) { global $states, $parcel_sizes, $parcel_contents; if ($order) { - $q = new OrderStateQuery; - $order_state = $q->filterByOrderId($order->getId())->orderByUpdated('desc')->limit(1)->findOne(); + $order_state = get_order_state($order); if ($order_state) { $state = $order_state->getState(); $driver_id = $order_state->getDriverId(); @@ -242,7 +228,6 @@ } else $order = new Order; - /* Date. */ echo "Invalid quantity!
\n"; - return false; - } - if ($new && isset($_POST['recurrence'])) $recurrence = $_POST['recurrence']; if (! $recurrence) $recurrence = 0; @@ -490,6 +488,7 @@ $order->setBeneficiaryId($beneficiary_id); $order->setHubId($hub_id); $order->setParcel($parcel); + $order->setNotes($notes); /* XXX: begin/commit */ try { @@ -523,6 +522,16 @@ return $order->getId(); } + function confirm_delete_order($id = null) { + if (! check_admin(1, "delete an order")) return; + + if (isset($id)) $order = get_order_by_id($id); + if (! $order) return false; + + echo "You must confirm deletion of order $id: " . $order->getDeleteLink(true) . "
\n"; + } + function delete_order($id = null) { if (! check_admin(1, "delete an order")) return; @@ -553,6 +562,7 @@ if (! count($order_states)) return; echo "\n"; foreach ($order_states as $order_state) { $date = $order_state->getUpdated(); @@ -564,26 +574,18 @@ if ($driver_id) $driver = get_contact_by_id($driver_id); else $driver = null; - /* XXX */ - $state = $order_state->getState(); - for ($i = 0; $i < count($states); $i++) { - if ((1 << $i) == $state) { - $state = $states[$i]; - break; - } - } - #$state = $states[$order_state->getState()]; - echo "
$username changed order to state $state"; + echo "$username changed order to state " . get_order_state_string($order_state) . ""; if ($driver) echo " for driver " . $driver->getDisplayname(); - echo " on $date.
\n"; + echo " on $date.