X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Forder.php;h=ac3cdfe01c125791f788b77d9cc80b7cd8d63dc2;hb=99c95916fa6901a10f864f25f9a05f95d792902e;hp=69026bfcde75668b5c0bc52ac4bdb1a9e5bf172b;hpb=48175505d7f95be28b778fbca3826e34ba505cde;p=readifood.git
diff --git a/lib/order.php b/lib/order.php
index 69026bf..ac3cdfe 100644
--- a/lib/order.php
+++ b/lib/order.php
@@ -1,10 +1,12 @@
Order placed.
\n";
@@ -26,15 +28,17 @@
}
}
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;
}
@@ -50,27 +54,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";
@@ -131,9 +115,9 @@
echo "Restrict to order states:\n";
for ($i = 0; $i < count($states); $i++) {
- echo " $states[$i]\n";
+ echo ">$states[$i] \n";
}
echo "
\n";
}
@@ -159,7 +143,7 @@
return $mask;
}
- function get_order_state_string($mask) {
+ function get_order_state_query_string($mask) {
global $states;
$selected = array();
@@ -171,13 +155,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 +171,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";
- foreach ($areas as $area) {
+ foreach ($candidates as $area) {
option("area_id", $area->getId(), get_area_displayname($area));
}
echo " \n";
@@ -205,9 +196,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";
- foreach ($cities as $city) {
+ foreach ($candidates as $city) {
option("city_id", $city->getId(), get_city_displayname($city), $city_id);
}
echo " \n";
@@ -215,19 +213,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 +232,6 @@
}
else $order = new Order;
-
/* Date. */
echo "\n";
echo " Delivery \n";
@@ -259,7 +255,10 @@
foreach ($contacts as $contact) {
option("requester_id", $contact->getId(), $contact->getDisplayname(), $order->getRequesterId());
}
- echo "\n";
+ echo "";
+ $contact = get_contact_by_id($order->getRequesterId(), false);
+ if ($contact) echo " " . get_small_link($contact->getDisplayname(), $contact->getURL());
+ echo "\n";
echo " \n";
/* Beneficiary. */
@@ -277,7 +276,10 @@
option("beneficiary_id", $contact->getId(), $contact->getDisplayname(), $order->getBeneficiaryId());
}
}
- echo "\n";
+ echo "";
+ $contact = get_contact_by_id($order->getBeneficiaryId(), false);
+ if ($contact) echo " " . get_small_link($contact->getDisplayname(), $contact->getURL());
+ echo "\n";
echo "\n";
/* Hub. */
@@ -289,7 +291,10 @@
foreach ($hubs as $hub) {
option("hub_id", $hub->getId(), $hub->getDisplayname(), $order->getHubId());
}
- echo "\n";
+ echo "";
+ $hub = get_hub_by_id($order->getHubId(), false);
+ if ($hub) echo " " . get_small_link($hub->getDisplayname(), $hub->getURL());
+ echo "\n";
echo "\n";
/* Parcel type. */
@@ -308,13 +313,19 @@
echo " Parcel contents \n";
echo " ";
for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
- echo " getParcel() & (1 << $i)) echo " checked";
- echo ">$parcel_contents[$i]\n";
+ echo ">$parcel_contents[$i] \n";
}
echo " \n";
echo "\n";
+ /* Notes. */
+ echo "\n";
+ echo " Notes \n";
+ echo " "; textarea("notes", $order->getNotes()); echo " \n";
+ echo " \n";
+
/* Driver. */
echo "\n";
echo " Driver \n";
@@ -325,7 +336,10 @@
foreach ($contacts as $contact) {
option("driver_id", $contact->getId(), $contact->getDisplayname(), $driver_id);
}
- echo "\n";
+ echo "";
+ $contact = get_contact_by_id($driver_id, false);
+ if ($contact) echo " " . get_small_link($contact->getDisplayname(), $contact->getURL());
+ echo "\n";
}
else echo " No drivers! \n";
echo " \n";
@@ -336,7 +350,7 @@
echo " State \n";
echo " \n";
for ($i = 0; $i < count($states); $i++) {
- option("state", $i << 1, ucfirst($states[$i]), $state);
+ option("state", 1 << $i, ucfirst($states[$i]), $state);
}
echo " \n";
echo "\n";
@@ -352,7 +366,7 @@
return;
}
- echo "\n";
+ end_form();
}
function show_contact_order_form($contact) {
@@ -377,7 +391,7 @@
$order = new Order;
$order->setBeneficiaryId($contact->getId());
- echo "\n";
+ end_form();
}
function show_add_new_order_form() {
@@ -406,7 +420,7 @@
return;
}
- echo "\n";
+ end_form();
}
function update_order(&$order, $new = false) {
@@ -433,6 +447,7 @@
for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
if ($_POST['parcel_' . $i] == "on") $parcel |= (1 << $i);
}
+ $notes = $_POST['notes'];
if ($date) {
list($y, $m, $d) = explode('-', $date);
@@ -477,6 +492,7 @@
$order->setBeneficiaryId($beneficiary_id);
$order->setHubId($hub_id);
$order->setParcel($parcel);
+ $order->setNotes($notes);
/* XXX: begin/commit */
try {
@@ -510,6 +526,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 "Confirm deletion \n";
+ 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 +566,7 @@
if (! count($order_states)) return;
echo "Order history \n";
+ echo "\n";
foreach ($order_states as $order_state) {
$date = $order_state->getUpdated();
@@ -551,26 +578,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. \n";
}
+ echo "\n";
}
function show_order(&$id = null) {
if (isset($id)) $order = get_order_by_id($id);
if (! $order) return;
- echo "\n";
+ end_form();
show_order_history($order->getId());
}
@@ -664,21 +683,19 @@
if (count($args)) {
switch ($args[0]) {
case "delete":
+ confirm_delete_order($id);
+ break;
+
+ case "confirmdelete":
delete_order($id);
break;
}
}
else if (isset($id)) show_order($id);
else if ($state_mask) show_orders(0, 10, null, null, $state_mask);
- else {
- /* XXX: Shown after adding. */
- show_order_forms($city_id, $state_mask);
- show_add_new_order_form($city_id);
- }
- if (count($parameters)) {
- show_order_forms($city_id, $state_mask);
- }
+ show_order_forms($city_id, $state_mask);
+ show_add_new_order_form($city_id);
?>