<?
$page = "admin.php";
include "admin_header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "main"; }




if($task == "changelang") {
$lang = $_POST['lang'];
$custom = @$_POST['custom'];

if($lang == "custom") { $langfile = $custom; } else { $langfile = $lang; }

// MAKE SURE FILE EXISTS
if(!file_exists("../lang/$langfile") OR $langfile == "") {
echo $head;
echo "
<h2>Error</h2>
The language file you specified could not be found.
Please be sure that you have uploaded this file in ASCII mode to the /lang/ directory.
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
echo $foot;
exit();
} 

// SET LANGUAGE FILE
if($lang == "custom") {
mysql_query("UPDATE bhost_admin SET language='$langfile'");
} else {
mysql_query("UPDATE bhost_admin SET language='$langfile'");
}

echo $head;
echo "
<h2>$admin1</h2>
$admin2
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
echo $foot;

exit();
}





if($task == "updatehomepage") {
$homepage = $_POST['homepage'];


mysql_query("UPDATE bhost_admin SET homepage='$homepage'");

echo $head;
echo "
<h2>$admin49</h2>
$admin50
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
echo $foot;
exit();

}







if($task == "updatetips") {
$tips = $_POST['tips'];

mysql_query("UPDATE bhost_admin SET tips='$tips'");

if($tips == 1) { 
$message = "
<h2>$admin4</h2>
$admin5 
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
} elseif($tips == 0) {
$message = "
<h2>$admin6</h2>
$admin7
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
}

echo $head;
echo $message;
echo $foot;
exit();
}









if($task == "updatedebug") {
$debug = $_POST['debug'];

mysql_query("UPDATE bhost_admin SET debug='$debug'");

if($debug == 1) { 
$message = "
<h2>$admin8</h2>
$admin9
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
} elseif($debug == 0) {
$message = "
<h2>$admin10</h2>
$admin11
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin3'>
</form>
";
}

echo $head;
echo $message;
echo $foot;
exit();
}







if($task == "main") {
echo $head;
$totalweblogs = mysql_num_rows(mysql_query("SELECT w_id FROM bhost_weblogs"));
$totalusers = mysql_num_rows(mysql_query("SELECT u_id FROM bhost_users"));
$totalentries = mysql_num_rows(mysql_query("SELECT e_id FROM bhost_entries"));
$totaltemplates = mysql_num_rows(mysql_query("SELECT t_id FROM bhost_templates"));
$totalcomments = mysql_num_rows(mysql_query("SELECT c_id FROM bhost_comments"));
$totaltrackbacks = mysql_num_rows(mysql_query("SELECT tb_id FROM bhost_trackbacks"));

$lastlogin = mysql_fetch_assoc(mysql_query("SELECT username, last_login FROM bhost_users ORDER BY last_login DESC LIMIT 1")); 
if($lastlogin[last_login] == 0) {
 $lastlogindate = "$admin12";
} else {
 $lastlogindate = cdate("n/j/y g:i A", $lastlogin[last_login])." $admin13 <a target='_blank' href='".url("profile", "", "$lastlogin[username]")."'>$lastlogin[username]</a>";
}

if(mysql_num_rows(mysql_query("SELECT u_id FROM bhost_users")) == 0) {
 $lastsignupdate = "$admin12";
} else {
 $lastsignup = mysql_fetch_assoc(mysql_query("SELECT username, signup_date FROM bhost_users ORDER BY signup_date DESC LIMIT 1"));
 $lastsignupdate = cdate("n/j/y g:i A", $lastsignup[signup_date])." $admin13 <a target='blank' href='".url("profile", "", "$lastsignup[username]")."'>$lastsignup[username]</a>";
}

$files = mysql_query("SELECT * FROM bhost_uploads");
$totalfiles = mysql_num_rows($files);
$totalsize = mysql_fetch_assoc(mysql_query("SELECT SUM(filesize) AS filesize FROM bhost_uploads"));
$totalsize = $totalsize[filesize];
$totalsize = ($totalsize / 1024) / 1024;
$totalsize = round($totalsize, 2);
$totalsize .= " MB";
$filestext = "$totalfiles $admin44 ($totalsize)";

$totallogins = mysql_num_rows(mysql_query("SELECT l_id FROM bhost_log WHERE result='1'"));

echo "
<h2>$admin14 $admin_info[fname]!</h2>
$admin15
<br><br>

<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='4' class='header'>$admin16</td></tr>
<tr>
<td class='stats1' NOWRAP><b>$admin17</b></td>
<td class='stats2' NOWRAP>$totalusers $admin18 &nbsp;</td>
<td class='stats2' NOWRAP><b>$admin51</b></td>
<td class='stats2' NOWRAP>$totalweblogs $admin53 &nbsp;</td>
</tr>
<tr>
<td class='stats1' NOWRAP><b>$admin43</b></td>
<td class='stats2' NOWRAP>$filestext &nbsp;</td>
<td class='stats2' NOWRAP><b>$admin19</b></td>
<td class='stats2' NOWRAP>$totalentries $admin20 &nbsp;</td>
</tr>
<tr>
<td class='stats1' NOWRAP><b>$admin21</b></td>
<td class='stats2' NOWRAP>$totalcomments $admin22 &nbsp;</td>
<td class='stats2' NOWRAP><b>$admin52</b></td>
<td class='stats2' NOWRAP>$totaltrackbacks $admin54 &nbsp;</td>
</tr>
<tr>
<td class='stats1' NOWRAP><b>$admin23</b></td>
<td class='stats2' NOWRAP>$totaltemplates $admin24 &nbsp;</td>
<td class='stats2' NOWRAP><b>$admin25</b></td>
<td class='stats2' NOWRAP>$lastsignupdate &nbsp;</td>
</tr>
<tr>
<td class='stats1' NOWRAP><b>$admin45</b></td>
<td class='stats2' NOWRAP>$totallogins $admin46 &nbsp;</td>
<td class='stats2' NOWRAP><b>$admin26</b></td>
<td class='stats2' NOWRAP>$lastlogindate &nbsp;</td>
</tr>
<tr>
<td class='stats1' NOWRAP><b>$admin27</b></td>
<td class='stats2' NOWRAP>v$bh_version &nbsp
<td class='stats2' NOWRAP><b>$admin42</b></td>
<td class='stats2' NOWRAP>$admin_info[license] &nbsp;</td>
</tr>
</table>

<br>

<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td class='header'>$admin28</td></tr>
<tr>
<td class='box'>
$admin29
</td>
</tr>
</table>

<br>

<script language='JavaScript'>
<!--
function changelang() {
if(window.document.lang.lang.value == \"custom\") {
window.document.lang.custom.style.visibility = \"visible\";
window.document.lang.custom.focus();
} else {
window.document.lang.custom.style.visibility = \"hidden\";
window.document.lang.custom.value = \"\";
}
}
// -->
</script>

";

if($admin_info[language] != "lang_english.php" AND $admin_info[language] != "lang_french.php") {
$customlang = "yes";
}

echo "
<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<form name='lang' action='admin.php' method='POST'>
<tr><td class='header'>$admin30</td></tr>
<tr>
<td class='box'>
$admin31
<br><br>
<select name='lang' onChange='changelang();'>
<option value='lang_english.php'"; if($admin_info[language] == "lang_english.php") { echo " SELECTED"; } echo ">lang_english.php</option>
<option value='custom'"; if($customlang == "yes") { echo " SELECTED"; } echo ">$admin32</option>
</select>
<input type='text' name='custom'"; if($customlang == "yes") { echo "value='$admin_info[language]' style='visibility: visible;'"; } else { echo "style='visibility: hidden;'"; } echo ">
<br><br>
<input type='submit' class='button' value='$admin33'>
</td>
</tr>
<input type='hidden' name='task' value='changelang'>
</form>
</table>

<br>

<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<form action='admin.php' method='POST'>
<tr><td class='header'>$admin47</td></tr>
<tr>
<td class='box'>
$admin48<br>
<input type='text' class='text' size='50' maxlength='200' name='homepage' value='$admin_info[homepage]'>
<br><br>
<input type='submit' class='button' value='$admin33'>
<input type='hidden' name='task' value='updatehomepage'>
</td>
</tr>
</form>
</table>

<br>

<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<form action='admin.php' method='POST'>
<tr><td class='header'>$admin34</td></tr>
<tr>
<td class='box'>
$admin35
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td width='200'>
<table cellpadding='0' cellspacing='0'>
<tr><td><input type='radio' name='tips' id='tips1' value='1'"; if($admin_info[tips] == 1) { echo " CHECKED"; } echo "></td><td><label for='tips1'>$admin36</label></td></tr>
<tr><td><input type='radio' name='tips' id='tips0' value='0'"; if($admin_info[tips] == 0) { echo " CHECKED"; } echo "></td><td><label for='tips0'>$admin37</label></td></tr>
</table>
</td>
</tr>
</table>
<br>

<input type='submit' class='button' value='$admin33'>
<input type='hidden' name='task' value='updatetips'>
</td>
</tr>
</form>
</table>

<br>

<table width='100%' cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<form action='admin.php' method='POST'>
<tr><td class='header'>$admin38</td></tr>
<tr>
<td class='box'>
$admin39
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td width='200'>
<table cellpadding='0' cellspacing='0'>
<tr><td><input type='radio' name='debug' id='debug0' value='0'"; if($admin_info[debug] == 0) { echo " CHECKED"; } echo "></td><td><label for='debug0'>$admin40</label></td></tr>
<tr><td><input type='radio' name='debug' id='debug1' value='1'"; if($admin_info[debug] == 1) { echo " CHECKED"; } echo "></td><td><label for='debug1'>$admin41</label></td></tr>
</table>
</td>
</tr>
</table>
<br>

<input type='submit' class='button' value='$admin33'>
<input type='hidden' name='task' value='updatedebug'>

</td>
</tr>
</form>
</table>

";
echo $foot;
}
?>