<?

require_once("include/header.php");

dbconn(false);

loggedinorreturn();
$res = mysql_query("SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER["id"] . " AND location IN ('in', 'both')") or print(mysql_error());
$arr = mysql_fetch_row($res);
$messages = $arr[0];
$res = mysql_query("SELECT COUNT(*) FROM messages WHERE receiver=" . $CURUSER["id"] . " AND location IN ('in', 'both') AND unread='yes'") or print(mysql_error());
$arr = mysql_fetch_row($res);
$unread = $arr[0];
$res = mysql_query("SELECT COUNT(*) FROM messages WHERE sender=" . $CURUSER["id"] . " AND location IN ('out', 'both')") or print(mysql_error());
$arr = mysql_fetch_row($res);
$outmessages = $arr[0];


stdhead($CURUSER["username"] . "$lang[Private_Page]", false);

if ($_GET["edited"]) {
	$gheader = "$lang[Profile_Updated]";
}
elseif ($_GET["emailch"])
	$gheader = "Email address changed!";
else
	$gheader = "Welcome, <a href=userdetails.php?id=$CURUSER[id]>$CURUSER[username]</a>!";

begin_frame("$gheader");
?>
<table border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td class=thumbnails align="center" width="33%"><a href=logout.php><b>Logout</b></a></td>
<td class=thumbnails align="center" width="33%"><a href=friends.php><b>My users lists</b></a></td>
</tr>
<tr>
<td colspan="3">
<form method="post" action="takeprofedit.php">

<?
begin_frame2_100("Profile");
/***********************

$res = mysql_query("SELECT COUNT(*) FROM ratings WHERE user=" . $CURUSER["id"]);
$row = mysql_fetch_array($res);
tr("Ratings submitted", $row[0]);

$res = mysql_query("SELECT COUNT(*) FROM comments WHERE user=" . $CURUSER["id"]);
$row = mysql_fetch_array($res);
tr("Written comments", $row[0]);

****************/



$countries = "<option value=0>---- None selected ----</option>\n";
$ct_r = mysql_query("SELECT id,name,flagpic FROM countries ORDER BY name") or die;
while ($ct_a = mysql_fetch_array($ct_r))
  $countries .= "<option value=$ct_a[id]" . ($CURUSER["country"] == $ct_a['id'] ? " selected" : "") . ">$ct_a[name]</option>\n";

function format_tz($a)
{
	$h = floor($a);
	$m = ($a - floor($a)) * 60;
	return ($a >= 0?"+":"-") . (strlen(abs($h)) > 1?"":"0") . abs($h) .
		":" . ($m==0?"00":$m);
}

tr("Accept PMs",
"<input type=radio class=input name=acceptpms" . ($CURUSER["acceptpms"] == "yes" ? " checked" : "") . " value=yes>All (except blocks)
<input type=radio class=input name=acceptpms" .  ($CURUSER["acceptpms"] == "friends" ? " checked" : "") . " value=friends>Friends only
<input type=radio class=input name=acceptpms" .  ($CURUSER["acceptpms"] == "no" ? " checked" : "") . " value=no>Staff only"
,1);



tr("Delete PMs", "<input type=checkbox class=input name=deletepms" . ($CURUSER["deletepms"] == "yes" ? " checked" : "") . "> (Default value for \"Delete PM on reply\")",1);
tr("Save PMs", "<input type=checkbox class=input name=savepms" . ($CURUSER["savepms"] == "yes" ? " checked" : "") . "> (Default value for \"Save PM to Sentbox\")",1);

tr("Email notification", "<input type=checkbox class=input name=pmnotif" . (strpos($CURUSER['notifs'], "[pm]") !== false ? " checked" : "") . " value=yes> Notify me when I have received a PM<br>\n" .
	 "<input type=checkbox class=input name=emailnotif" . (strpos($CURUSER['notifs'], "[email]") !== false ? " checked" : "") . " value=yes> Notify me when a torrent is uploaded in one of <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my default browsing categories.\n"
   , 1);

tr("Country", "<select name=country class=input>\n$countries\n</select>",1);

tr("Avatar URL", "<input name=avatar class=input size=50 value=\"" . htmlspecialchars($CURUSER["avatar"]) .
  "\"><br>\nWidth should be 150 pixels (will be resized if necessary)\n<br>If you need a host for the picture, try the <a href=bitbucket-upload.php>bitbucket</a>.",1);
tr("Topics per page", "<input type=text size=10 class=input name=topicsperpage value=$CURUSER[topicsperpage]> (0=use default setting)",1);
tr("Posts per page", "<input type=text size=10 class=input name=postsperpage value=$CURUSER[postsperpage]> (0=use default setting)",1);
tr("View avatars", "<input type=checkbox class=input name=avatars" . ($CURUSER["avatars"] == "yes" ? " checked" : "") . "> (Low bandwidth users might want to turn this off)",1);
tr("Info", "<textarea name=info class=input cols=50 rows=4>" . $CURUSER["info"] . "</textarea><br>Displayed on your public page. May contain <a href=tags.php target=_new>BB codes</a>.", 1);
tr("Email address", "<input type=\"text\" class=input name=\"email\" size=50 value=\"" . htmlspecialchars($CURUSER["email"]) . "\" />", 1);
print("<tr><td colspan=\"2\" align=left><b>Note:</b> In order to change your email address, you will receive another<br>confirmation email to your new address.</td></tr>\n");
tr("Change password", "<input type=\"password\" class=input name=\"chpassword\" size=\"50\" />", 1);
tr("Type password again", "<input type=\"password\" class=input name=\"passagain\" size=\"50\" />", 1);

function priv($name, $descr) {
	global $CURUSER;
	if ($CURUSER["privacy"] == $name)
		return "<input type=\"radio\" name=\"privacy\" class=input value=\"$name\" checked=\"checked\" /> $descr";
	return "<input type=\"radio\" name=\"privacy\" class=input value=\"$name\" /> $descr";
}

/* tr("Privacy level",  priv("normal", "Normal") . " " . priv("low", "Low (email address will be shown)") . " " . priv("strong", "Strong (no info will be made available)"), 1); */

?>
<tr><td colspan="2" align="center"><input type="submit" class="input" value="Submit changes!"> <input type="reset" class="input" value="Revert changes!"></td></tr>
</table>
</form>

<?
end_frame();

if ($messages){
  print("<center>You have $messages message" . ($messages != 1 ? "s" : "") . " ($unread new) in your <a href=inbox.php><b>inbox</b></a>,<br>\n");
	if ($outmessages)
		print("and $outmessages message" . ($outmessages != 1 ? "s" : "") . " in your <a href=inbox.php?out=1><b>sentbox</b></a>.\n</center>");
	else
		print("and your <a href=inbox.php?out=1>sentbox</a> is empty.</center>");
}
else
{
  print("<center>Your <a href=inbox.php>inbox</a> is empty, <br>\n");
	if ($outmessages)
		print("and you have $outmessages message" . ($outmessages != 1 ? "s" : "") . " in your <a href=inbox.php?out=1><b>sentbox</b></a>.\n</p>");
	else
		print("and so is your <a href=inbox.php?out=1>sentbox</a>.</center>");
}

print("<center><a href=users.php><b>Find User/Browse User List</b></a></center>");
end_frame();
stdfoot();

?>