<?php
global $user;
$rtid = 1; //Relationship type ID.
$max = 1; //The amount of users to show on the block.
$user_rel = db_query("
SELECT u.uid
FROM {users} u
LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
WHERE (ur.requester_id = %d OR ur.requestee_id = %d)
AND ur.approved = 1
AND ur.rtid = %d
AND u.status <> 0
GROUP BY u.uid
ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
", $user->uid, $user->uid, $rtid);
$user_rel_com = array();
while ($value = db_fetch_array($user_rel)) {
$user_rel_com[] = $value;
}
//Exit if no users found.
if (empty($user_rel_com)) {
return;
}
foreach ($user_rel_com as $row) {
$req_req_id_list .= " OR ur.requester_id = " . $row['uid'] . " OR ur.requestee_id = " . $row['uid'];
$no_include_friends .= " AND u.uid <> ". $row['uid'];
}
//Trim the first " OR ".
$req_req_id_list = drupal_substr($req_req_id_list, 4);
//Get all of the current user's friends' friends and order by how many times they show up in the list.
$user_rel_rel = db_query("
SELECT u.uid
FROM {users} u
LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
WHERE (%s)
AND ur.approved = 1
AND ur.rtid = %d
AND u.uid <> %d
%s
AND u.status <> 0
GROUP BY u.uid
ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
", $req_req_id_list, $rtid, $user->uid, $no_include_friends);
$user_rel_rel_com = array();
while ($value = db_fetch_array($user_rel_rel)) {
$user_rel_rel_com[] = $value['uid'];
}
//Scrambles the users non-randomly. Does not scramble the user at the bottom of the list.
$z = $user_rel_rel_com;
$i = 0;
foreach ($user_rel_rel_com as $v) {
$r = rand(0, 1);
if ($r === 1 && $user_rel_rel_com[$i + 1]) {
$z[$i] = $user_rel_rel_com[$i + 1];
$z[$i + 1] = $v;
}
$i++;
}
if(count($user_rel_rel_com) < $max) {
$max = count($user_rel_rel_com);
}
$header = array();
$header = array(array('data' => 'Name'), array('data'=> 'Age'), array('data' => 'Relationship Status'), array('data' => 'City'));
$rows = array();
for ($i = 0; $i < $max; $i++) {
if ($z[$i] != $user->uid) {
$row = array();
$account = user_load(array('uid' => $z[$i]));
$row[] = array('data' => theme('username', $account) , 'class' => 'nice-cell');
$row[] = array('data' => $account->profile_age, 'class' => 'nice-cell');
$row[] = array('data' => $account->profile_Relationship_Status, 'class' => 'nice-cell');
$row[] = array('data' => $account->profile_City, 'class' => 'nice-cell');
$row[] = array('data' => theme('user_picture', $account) , 'class' => 'nice-cell');
$rows[] = $row;
}
}
//Theme with CSS as appropriate. "More" link is optional.
echo '<span class="uymn">'. theme('item_list', $list) .'</span>';
print theme ('table', $header, $rows);
?>