You are here

function merci_template_recent_reservations_options in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6

Get form API options for recent reservations

1 call to merci_template_recent_reservations_options()
merci_template_form_alter in modules/merci_template/merci_template.module
Implementation of hook_form_alter().

File

modules/merci_template/merci_template.module, line 50
merci_template functions

Code

function merci_template_recent_reservations_options() {
  global $user;
  $options = array();
  if (user_access('administer MERCI')) {
    $reservations = db_query_range("SELECT n.title , n.nid FROM {content_type_merci_reservation} ctmr JOIN {merci_reservation_detail} mrd ON ctmr.nid = mrd.nid JOIN {merci_reservation} mr ON ctmr.nid = mr.nid JOIN {node} n ON n.nid = ctmr.nid ORDER BY n.changed DESC", 0, 20);
  }
  else {
    $reservations = db_query_range("SELECT n.title , n.nid FROM {content_type_merci_reservation} ctmr JOIN {merci_reservation_detail} mrd ON ctmr.nid = mrd.nid JOIN {merci_reservation} mr ON ctmr.nid = mr.nid JOIN {node} n ON n.nid = ctmr.nid WHERE n.uid = %d ORDER BY n.created DESC", $user->uid, 0, 20);
  }

  // else
  while ($reservation = db_fetch_object($reservations)) {
    $items = array();
    $placeholders = db_query("SELECT n.type , mrd.item_nid , mnt.type_setting FROM {merci_reservation_detail} mrd JOIN {node} n ON n.nid = mrd.placeholder_nid JOIN {merci_node_type} mnt ON mnt.type = n.type WHERE mrd.nid = %d", $reservation->nid);
    while ($placeholder = db_fetch_object($placeholders)) {
      if ($placeholder->type_setting == 'bucket') {
        $items[] = $placeholder->type;
      }
      else {
        $items[] = $placeholder->item_nid;
      }

      // else
    }

    // while
    $options[implode(',', $items)] = $reservation->title . ' (#' . $reservation->nid . ')';
  }

  // while
  return $options;
}