}
function show_order_form($order = null, $area_id = null) {
- global $states;
+ global $states, $parcel_sizes, $parcel_contents;
if ($order) {
$q = new OrderStateQuery;
echo " <td>Beneficiary</td>\n";
echo " <td><select name=\"beneficiary_id\">\n";
option("beneficiary_id", null, "");
- $contacts = get_area_beneficiaries($area_id);
- foreach ($contacts as $contact) {
- option("beneficiary_id", $contact->getId(), $contact->getDisplayname(), $order->getBeneficiaryId());
+ if (! $order->getId() && $order->getBeneficiaryId()) {
+ $contact = get_contact_by_id($order->getBeneficiaryId());
+ if ($contact) option("beneficiary_id", $order->getBeneficiaryId(), $contact->getDisplayname(), $order->getBeneficiaryId());
+ }
+ else {
+ $contacts = get_area_beneficiaries($area_id);
+ foreach ($contacts as $contact) {
+ option("beneficiary_id", $contact->getId(), $contact->getDisplayname(), $order->getBeneficiaryId());
+ }
}
echo "</select></td>\n";
echo "</tr>\n";
echo "</select></td>\n";
echo "</tr>\n";
- /* Quantity. */
+ /* Parcel type. */
echo "<tr>\n";
- echo " <td>Quantity (kg)</td>\n";
- echo " <td>"; input("quantity", sprintf("%0.2f", $order->getQuantity() / 1000)); echo "</td>\n";
+ echo " <td>Parcel size</td>\n";
+ echo " <td><select name=\"parcel_size\">\n";
+ $mask = 1 << (count($parcel_sizes) + 1);
+ for ($i = 0; $i < count($parcel_sizes); $i++) {
+ option("parcel_size", $i << 1, $parcel_sizes[$i], $order->getParcel() % $mask);
+ }
+ echo "</select></td>\n";
+ echo "</tr>\n";
+
+ /* Parcel contents. */
+ echo "<tr>\n";
+ echo " <td>Parcel contents</td>\n";
+ echo " <td>";
+ for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
+ echo " <input type=\"checkbox\" name=\"parcel_$i\"";
+ if ($order->getParcel() & (1 << $i)) echo " checked";
+ echo ">$parcel_contents[$i]\n";
+ }
+ echo "</td>\n";
echo "</tr>\n";
/* Driver. */
echo "</form>\n";
}
+ function show_contact_order_form($contact) {
+ if (! check_admin(1)) return;
+
+ $area = get_contact_area($contact);
+ if (! $area) {
+ echo "<p>No valid <a href=\"/area\">area</a> for contact!</p>\n";
+ return;
+ }
+
+ $order = new Order;
+ $order->setBeneficiaryId($contact->getId());
+
+ echo "<form method=\"POST\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n";
+ echo "<p>Placing order for " . $contact->getStrongLink() . ".";
+ $parcel = $contact->getParcel();
+ if ($parcel) {
+ echo " Suggested parcel type is <span class=\"strong\">" . get_contact_parcel_string($contact) . "</span>";
+ $order->setParcel($parcel);
+ }
+ echo "</p>\n";
+
+ echo "<table>\n";
+ show_order_form($order, $area_id);
+
+ echo "<tr>\n";
+ echo " <td colspan=2>"; submit("add_order", "Order"); echo "</td></tr>\n";
+ echo "</tr>\n";
+ echo "</table>\n";
+ echo "</form>\n";
+ }
+
function show_add_new_order_form() {
if (! check_admin(1)) return;
}
function update_order(&$order, $new = false) {
- global $user_id;
+ global $user_id, $parcel_sizes, $parcel_contents;
#$date = ymd_to_iso8601("date");
$date = $_POST['date'];
if (! $driver_id) $driver_id = null;
$state = $_POST['state'];
if (! $state) $state = $GLOBALS['STATE_PLACED'];
+ $parcel = $_POST['parcel_size'];
+ for ($i = count($parcel_sizes); $i < count($parcel_contents); $i++) {
+ if ($_POST['parcel_' . $i] == "on") $parcel |= (1 << $i);
+ }
if ($date) {
list($y, $m, $d) = explode('-', $date);
$order->setRequesterId($requester_id);
$order->setBeneficiaryId($beneficiary_id);
$order->setHubId($hub_id);
- $order->setQuantity($quantity * 1000);
+ $order->setParcel($parcel);
/* XXX: begin/commit */
try {
break;
}
}
+ else if ($parameters[0] == "place") {
+ if ($parameters[1] == "for") {
+ if ($parameters[2] == "beneficiary") {
+ if ($parameters[4]) $contact = get_contact_by_id($parameters[4]);
+ if (! $contact) $contact = get_contact_by_name(urldecode($parameters[3]));
+ if ($contact) show_contact_order_form($contact);
+ }
+ }
+ }
}
list($ignored, $id, $args) = parse_parameters($parameters);
//echo "<p>$name($id) " . print_r($args, true) . "</p>\n";