if ($role_string) echo " $role_string";
if ($role & $GLOBALS['ROLE_DONOR']) printf(" <a class=\"small\" href=\"/donation/from/contact/%s/%d\">Donations</a>", urlencode($contact->getDisplayname()), $contact->getId());
if ($role & $GLOBALS['ROLE_REQUESTER']) printf(" <a class=\"small\" href=\"/order/from/referrer/%s/%d\">Referred</a>", urlencode($contact->getDisplayname()), $contact->getId());
- if ($role & $GLOBALS['ROLE_BENEFICIARY']) printf(" <a class=\"small\" href=\"/order/to/beneficiary/%s/%d\">Orders</a>", urlencode($contact->getDisplayname()), $contact->getId());
+ if ($role & $GLOBALS['ROLE_BENEFICIARY']) {
+ printf(" <a class=\"small\" href=\"/order/to/beneficiary/%s/%d\">Orders</a>", urlencode($contact->getDisplayname()), $contact->getId());
+ if (get_contact_area($contact)) printf(" <a class=\"small\" href=\"/order/place/for/beneficiary/%s/%d\">Place</a>", urlencode($contact->getDisplayname()), $contact->getId());
+ }
if (check_admin(1)) {
echo " " . $contact->getDeleteLink();
}
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 "</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>Place an order:</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;
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";