X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Forder.php;h=3e3556f926170d7a4cf058c7f203556539521d0e;hb=f01f7f07701d082995cd4919d51449a2db2ed9bc;hp=69026bfcde75668b5c0bc52ac4bdb1a9e5bf172b;hpb=48175505d7f95be28b778fbca3826e34ba505cde;p=readifood.git diff --git a/lib/order.php b/lib/order.php index 69026bf..3e3556f 100644 --- a/lib/order.php +++ b/lib/order.php @@ -1,10 +1,12 @@ Order placed.
\n"; @@ -26,19 +28,22 @@ } } else if ($_POST['show_in_area']) { + set_last_selected("area_id", $_POST['area_id']); $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']) { + set_last_selected("city_id", $_POST['city_id']); $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) { + function show_orders($requester_ids = null, $beneficiary_ids = null, $state_mask = null) { + list($first_page, $per_page) = pagination(); /* XXX: Use Propel methods. */ if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask); $q = new OrderQuery; @@ -47,36 +52,17 @@ # XXX: Doesn't work. #if (isset($state_mask)) $q->useOrderStateQuery()->addSelectQuery($latest_state, 'latestState')->where("order_id=latestState.order_id")->where("state & $state_mask")->endUse(); if (isset($state_mask)) $q->filterById($order_ids); - $orders = $q->orderByDate()->find(); + $orders = $q->orderByDate('desc')->orderById('desc')->paginate($first_page, $per_page); if (count($orders)) { foreach ($orders as $order) { - echo "Orders in city " . $city->getLink(get_city_displayname($city)) . ":"; - return show_orders($offset, $per_page, null, $beneficiary_ids, $state_mask); + return show_orders(null, $beneficiary_ids, $state_mask); } else echo "
No such city!
\n"; } - function show_requester_orders($offset, $per_page, $contact_name, $contact_id = null, $state_mask = null) { + function show_requester_orders($contact_name, $contact_id = null, $state_mask = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "Orders from referrer " . $contact->getLink() . ":"; - return show_orders($offset, $per_page, $contact->getId(), null, $state_mask); + return show_orders($contact->getId(), null, $state_mask); } else echo "
No such contact!
\n"; } - function show_beneficiary_orders($offset, $per_page, $contact_name, $contact_id = null, $state_mask = null) { + function show_beneficiary_orders($contact_name, $contact_id = null, $state_mask = null) { if (isset($contact_id)) $contact = get_contact_by_id($contact_id); else if ($contact_name) $contact = get_contact_by_name($contact_name); if ($contact) { echo "Orders to beneficiary " . $contact->getLink() . ":"; - return show_orders($offset, $per_page, null, $contact->getId(), $state_mask); + return show_orders(null, $contact->getId(), $state_mask); } else echo "
No such contact!
\n"; } - function show_area_orders($offset, $per_page, $area_name, $area_id = null, $state_mask = null) { + function show_area_orders($area_name, $area_id = null, $state_mask = null) { if (isset($area_id)) $area = get_area_by_id($area_id); else if ($area_name) $area = get_area_by_name($area_name); if ($area) { @@ -119,7 +105,7 @@ foreach ($contacts as $contact) $contact_ids[] = $contact->getId(); echo "Orders in area " . $area->getLink() . ":"; - return show_orders($offset, $per_page, null, $contact_ids, $state_mask); + return show_orders(null, $contact_ids, $state_mask); } else echo "
No such area!
\n"; } @@ -131,9 +117,9 @@ echo "Restrict to order states:\n"; for ($i = 0; $i < count($states); $i++) { - echo " $states[$i]\n"; + echo ">\n"; } echo "
\n"; } @@ -159,7 +145,7 @@ return $mask; } - function get_order_state_string($mask) { + function get_order_state_query_string($mask) { global $states; $selected = array(); @@ -171,13 +157,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) { @@ -187,9 +173,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"; @@ -205,9 +198,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"; @@ -215,19 +215,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(); @@ -235,7 +234,6 @@ } else $order = new Order; - /* Date. */ 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; @@ -540,6 +568,7 @@ if (! count($order_states)) return; echo "\n"; foreach ($order_states as $order_state) { $date = $order_state->getUpdated(); @@ -551,26 +580,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.