require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
$userid = (int) $_GET['id'];
$valid_actions = array('add', 'delete');
$action = ( in_array($_GET['action'], $valid_actions) ? $_GET['action'] : '');
if (!$userid)
$userid = $CURUSER['id'];
if (!is_valid_id($userid))
stderr( _("Error"), _("Invalid ID"));
if ($userid != $CURUSER["id"])
stderr( _("Error"), _("Access denied."));
//$res = do_mysql_query("SELECT * FROM users WHERE id=$userid") or sqlerr(__FILE__, __LINE__);
//$user = mysql_fetch_assoc($res) or stderr( _("Error"), "No user with ID");
$user = $CURUSER;
// action: add -------------------------------------------------------------
if ($action == 'add')
{
$targetid = (int) $_GET['targetid'];
$type = $_GET['type'];
if (!is_valid_id($targetid))
stderr( _("Error"), _("Invalid ID"));
if ($type == 'friend')
{
$table_is = $frag = 'friends';
$field_is = 'friendid';
}
elseif ($type == 'block')
{
$table_is = $frag = 'blocks';
$field_is = 'blockid';
}
else
stderr( _("Error"), _("Unknown type"));
$r = do_mysql_query("SELECT id FROM $table_is WHERE userid=$userid AND $field_is=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($r) == 1)
stderr( _("Error"), "User ID $targetid is already in your $table_is list.");
do_mysql_query("INSERT INTO $table_is VALUES (0,$userid, $targetid)") or sqlerr(__FILE__, __LINE__);
header("Location: friends.php?id=$userid#$frag");
die;
}
// action: delete ----------------------------------------------------------
if ($action == 'delete')
{
$targetid = (int) $_GET['targetid'];
$sure = (int) $_GET['sure'];
$valid_types = array('friend', 'block');
$type = in_array($_GET['type'], $valid_types) ? $_GET['type'] : '';
if (!is_valid_id($targetid))
stderr( _("Error"), _("Invalid ID") );
if (!$sure)
stderr("Delete $type","Do you really want to delete a $type? Click\n" .
"here if you are sure.");
if ($type == 'friend')
{
do_mysql_query("DELETE FROM friends WHERE userid=$userid AND friendid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr( _("Error"), "No friend found with ID");
$frag = "friends";
}
elseif ($type == 'block')
{
do_mysql_query("DELETE FROM blocks WHERE userid=$userid AND blockid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr( _("Error"), "No block found with ID");
$frag = "blocks";
}
else
stderr( _("Error"), "Unknown type");
header("Location: friends.php?id=$userid#$frag");
die;
}
// main body -----------------------------------------------------------------
stdhead("Personal lists for " . $user['username']);
if ($user["donor"] == "yes") $donor = "
| ";
if ($user["warned"] == "yes") $warned = " | ";
print("\n");
print("".
" Personal lists for $user[username]$donor$warned$country |
\n");
print("");
print(" ");
print("\n");
print("");
$i = 0;
$res = do_mysql_query("SELECT f.friendid as id, u.username AS name, u.class, u.avatar, u.title, u.donor, u.warned, u.enabled, u.last_access, UNIX_TIMESTAMP(u.last_access) as utadded FROM friends AS f LEFT JOIN users as u ON f.friendid = u.id WHERE userid=$userid ORDER BY name") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
$friends = "Your friends list is empty.";
else
while ($friend = mysql_fetch_assoc($res))
{
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"]);
$body1 = "" . $friend['name'] . "" .
get_user_icons($friend) . " ($title)
last seen on " . $friend['last_access'] .
" (" . get_elapsed_time(($friend['utadded'])) . " ago)";
$body2 = " Remove" .
"
Send PM";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = $GLOBALS['pic_base_url']."/default_avatar.gif";
if ($i % 2 == 0)
print("");
else
print(" | ");
print("");
print("" .
($avatar ? "" : ""). " | \n");
print("");
print("$body1 | \n");
print("$body2 | \n");
print(" ");
print(" | ");
print(" \n");
if ($i % 2 == 1)
print(" | \n");
else
print(" | \n");
$i++;
}
if ($i % 2 == 1)
print(" | \n");
print($friends);
print(" |
\n");
/* Added you to friends list */
$i = 0;
$res = do_mysql_query("SELECT
f.userid as id,
u.username AS name,
u.class,
u.avatar,
u.title,
u.donor,
u.warned,
u.enabled,
u.last_access,
UNIX_TIMESTAMP(u.last_access) as utadded
FROM friends AS f
LEFT JOIN users as u
ON f.userid = u.id
WHERE f.friendid=$userid ORDER BY username") or sqlerr(__FILE__, __LINE__);
print("
");
print("\n");
print("");
if(mysql_num_rows($res) == 0)
$friends = "Nobody added you as a friend :(.";
else
while ($friend = mysql_fetch_assoc($res))
{
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"]);
$body1 = "" . $friend['name'] . "" .
get_user_icons($friend) . " ($title)
last seen on " . $friend['last_access'] .
" (" . get_elapsed_time($friend['utadded']) . " ago)";
$body2 = " Remove" .
"
Send PM";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = $GLOBALS['pic_base_url']."/default_avatar.gif";
if ($i % 2 == 0)
print("");
else
print(" | ");
print("");
print("" .
($avatar ? "" : ""). " | \n");
print("");
print("$body1 | \n");
print("$body2 | \n");
print(" ");
print(" | ");
print(" \n");
if ($i % 2 == 1)
print(" | \n");
else
print(" | \n");
$i++;
}
if ($i % 2 == 1)
print(" |
\n");
print($friends);
print("\n");
/* ============= */
$res = do_mysql_query("SELECT b.blockid as id, u.username AS name, u.donor, u.warned, u.enabled, u.last_access FROM blocks AS b LEFT JOIN users as u ON b.blockid = u.id WHERE userid=$userid ORDER BY name") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
$blocks = "Your blocked users list is empty.";
else
{
$i = 0;
$blocks = "";
while ($block = mysql_fetch_assoc($res))
{
if ($i % 6 == 0)
$blocks .= "";
$blocks .= "[D] " . $block['name'] . "" .
get_user_icons($block) . " | ";
if ($i % 6 == 5)
$blocks .= "
";
$i++;
}
print("
\n");
}
print("
");
print("");
print(" |
");
print("");
print("$blocks\n");
print(" |
\n");
print("\n");
print("Find User/Browse User List
");
stdfoot();
?>