You are here

function theme_user_relationships_pending_requests_page in User Relationships 5

Same name and namespace in other branches
  1. 5.3 user_relationships_ui/user_relationships_ui.theme.inc \theme_user_relationships_pending_requests_page()
  2. 5.2 user_relationships_theme.inc \theme_user_relationships_pending_requests_page()

File

./user_relationships_theme.inc, line 79

Code

function theme_user_relationships_pending_requests_page($uid = NULL) {
  global $user;
  if (!$uid) {
    $account =& $user;
  }
  else {
    if (!(is_numeric($uid) && $uid > 0 && ($account = user_load(array(
      'uid' => $uid,
    ))))) {
      drupal_not_found();
      exit;
    }
  }
  drupal_set_title(t("%username's pending relationships", array(
    '%username' => $account->name,
  )));
  $output = '';
  $relationships_per_page = variable_get('user_relationships_relationships_per_page', 16);
  $args = array(
    $account->uid,
  );

  /**
   * Sent Requests
   */
  $sql = "SELECT u.*, r.*, rt.name as rname \n     FROM {user_relationships} r, {user_relationship_types} rt, {users} u\n     WHERE  r.requester_id = %d \n       AND r.approved = 0 \n       AND rt.rtid = r.rtid\n       AND r.requestee_id = u.uid";
  $requests = $relationships_per_page ? pager_query($sql, $relationships_per_page, SENT_PAGER, NULL, $args) : db_query($sql, $args);
  if (db_num_rows($requests)) {
    $rows[] = array(
      array(
        'data' => t('Sent Requests'),
        'header' => true,
        'colspan' => 2,
      ),
    );
    while ($relationship = db_fetch_object($requests)) {
      $links = theme('user_relationships_pending_request_cancel_link', $account->uid, $relationship->rid);
      $rows[] = array(
        theme('username', $relationship) . ' is a ' . $relationship->rname,
        $links,
      );
    }
    $output .= theme('table', array(), $rows);
    if ($relationships_per_page) {
      $output .= theme('pager', NULL, $relationships_per_page, SENT_PAGER);
    }
    unset($rows);
  }

  /**
   * Received Requests
   */
  $sql = "SELECT u.*, r.*, rt.name as rname \n     FROM {user_relationships} r, {user_relationship_types} rt, {users} u\n     WHERE  r.requestee_id = %d \n       AND r.approved = 0 \n       AND rt.rtid = r.rtid\n       AND r.requester_id = u.uid";
  $requests = $relationships_per_page ? pager_query($sql, $relationships_per_page, RECEIVED_PAGER, NULL, $args) : db_query($sql, $args);
  if (db_num_rows($requests)) {
    $rows[] = array(
      array(
        'data' => t('Received Requests'),
        'header' => true,
        'colspan' => 2,
      ),
    );
    while ($relationship = db_fetch_object($requests)) {
      $links = theme('user_relationships_pending_request_approve_link', $uid, $relationship->rid) . ' | ' . theme('user_relationships_pending_request_disapprove_link', $uid, $relationship->rid);
      $rows[] = array(
        theme('username', $relationship) . ' is a ' . $relationship->rname,
        $links,
      );
    }
    $output .= theme('table', array(), $rows);
    if ($relationships_per_page) {
      $output .= theme('pager', NULL, $relationships_per_page, RECEIVED_PAGER);
    }
    unset($rows);
  }
  if ($output == '') {
    $output = t('No pending relationships found');
  }
  return $output;
}