<?php
if (isset($_POST['show_add_order'])) {
+ set_last_selected("area_id", $_POST['area_id']);
$area_id = $_POST['area_id'];
show_new_order_form($area_id);
}
else if (isset($_POST['add_order'])) {
+ set_last_selected("area_id", $_POST['area_id']);
$id = add_order();
if ($id !== false) {
echo "<p>Order placed.</p>\n";
}
}
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_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_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($city_id = null, $area_id = null, $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;
if (isset($beneficiary_ids)) $q->filterByBeneficiaryId($beneficiary_ids);
# 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($city_id) || isset($area_id)) {
+ $q->joinWith('Order.Beneficiary');
+ $q->joinWith('Beneficiary.Address');
+ if (isset($area_id)) $q->where('Address.AreaId=?', $area_id);
+ if (isset($city_id)) {
+ $q->joinWith('Address.Area');
+ $q->where('Area.CityId=?', $city_id);
+ }
+ }
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 "<br>\n" . get_order_summary($order) . "<br>\n";
}
+ show_pagination($orders);
}
else echo " none";
}
- function show_city_orders($offset, $per_page, $city_name, $city_id = null, $state_mask = null) {
+ function show_city_orders($city_name, $city_id = null, $state_mask = null) {
if (isset($city_id)) $city = get_city_by_id($city_id);
else if ($city_name) $city = get_city_by_name($city_name);
if ($city) {
- $contacts = get_city_contacts($city->getId(), $GLOBALS['ROLE_BENEFICIARY']);
- $beneficiary_ids = array();
- foreach ($contacts as $contact) $beneficiary_ids[] = $contact->getId();
-
echo "<p>Orders in city " . $city->getLink(get_city_displayname($city)) . ":";
- return show_orders($offset, $per_page, null, $beneficiary_ids, $state_mask);
+ return show_orders($city->getId(), null, null, null, $state_mask);
}
else echo "<p>No such city!</p>\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 "<p>Orders from referrer " . $contact->getLink() . ":";
- return show_orders($offset, $per_page, $contact->getId(), null, $state_mask);
+ return show_orders(null, null, $contact->getId(), null, $state_mask);
}
else echo "<p>No such contact!</p>\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 "<p>Orders to beneficiary " . $contact->getLink() . ":";
- return show_orders($offset, $per_page, null, $contact->getId(), $state_mask);
+ return show_orders(null, null, null, $contact->getId(), $state_mask);
}
else echo "<p>No such contact!</p>\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) {
- $contacts = get_area_contacts($area->getId(), $GLOBALS['ROLE_BENEFICIARY']);
- $contact_ids = array();
- foreach ($contacts as $contact) $contact_ids[] = $contact->getId();
-
echo "<p>Orders in area " . $area->getLink() . ":";
- return show_orders($offset, $per_page, null, $contact_ids, $state_mask);
+ return show_orders(null, $area->getId(), null, null, $state_mask);
}
else echo "<p>No such area!</p>\n";
}
$area = $q->findOneById($area_id);
$city = get_area_city($area);
if ($city) $city_id = $city->getId();
- show_area_orders(0, 10, $parameters[2], $area_id, $state_mask);
+ show_area_orders($parameters[2], $area_id, $state_mask);
break;
case "city":
$_POST['city_id'] = $city_id;
$q = new CityQuery;
$city = $q->findOneById($city_id);
- show_city_orders(0, 10, $parameters[2], $city_id, $state_mask);
+ show_city_orders($parameters[2], $city_id, $state_mask);
break;
}
}
$contact_id = $parameters[3];
$q = new ContactQuery;
$contact = $q->findOneById($contact_id);
- show_requester_orders(0, 10, $parameters[2], $contact_id, $state_mask);
+ show_requester_orders($parameters[2], $contact_id, $state_mask);
break;
}
}
$contact_id = $parameters[3];
$q = new ContactQuery;
$hub = $q->findOneById($contact_id);
- show_beneficiary_orders(0, 10, $parameters[2], $contact_id, $state_mask);
+ show_beneficiary_orders($parameters[2], $contact_id, $state_mask);
break;
}
}
}
}
else if (isset($id)) show_order($id);
- else if ($state_mask) show_orders(0, 10, null, null, $state_mask);
+ else if ($state_mask) show_orders(null, null, null, null, $state_mask);
show_order_forms($city_id, $state_mask);
show_add_new_order_form($city_id);