Show outstanding orders in contact view.
[readifood.git] / lib / contact.php
index 8ba1fcd..a5bceee 100644 (file)
     global $contact_roles, $parcel_sizes, $parcel_contents;
 
     if (! $contact) $contact = new Contact;
+    else if ($contact->getRole() & $GLOBALS['ROLE_BENEFICIARY']) {
+      $state_mask = $GLOBALS['STATE_ANY'];
+      $state_mask &= ~$GLOBALS['STATE_DELIVERED'];
+      $state_mask &= ~$GLOBALS['STATE_CANCELLED'];
+
+      $orders = get_contact_orders($contact, $state_mask);
+
+      if (count($orders)) {
+        echo "<tr>\n";
+        echo "  <td colspan=2><strong>Outstanding orders:</strong></td>\n";
+        echo "</tr>\n";
+
+        echo "<tr>\n";
+        echo "  <td colspan=2>\n";
+        foreach ($orders as $order) {
+          echo "    Order " . $order->getStrongLink($order->getId()) . ": " . get_order_displayname($order) . "<br>\n";
+        }
+        echo "  </td>\n";
+        echo "</tr>\n";
+      }
+    }
 
     /* Role. */
     echo "<tr>\n";
     echo "<tr>\n";
     echo "  <td>Family unit</td>\n";
     echo "  <td><select name=\"parcel_size\">\n";
-    $mask = 1 << (count($parcel_sizes) + 1);
+    $mask = 1 << count($parcel_sizes);
     for ($i = 0; $i < count($parcel_sizes); $i++) {
-      option("parcel_size", $i << 1, $parcel_sizes[$i], $contact->getParcel() % $mask);
+      option("parcel_size", 1 << $i, $parcel_sizes[$i], $contact->getParcel() % $mask);
     }
     echo "</select></td>\n";
     echo "</tr>\n";
     }
 
     /* Get address. */
+    $area_id = $_POST['area_id'];
     $line = $_POST['address'];
     $postcode = $_POST['postcode'];
     $q = new AddressQuery;