<?php
include('include/bittorrent.php');
dbconn(false);
loggedinorreturn();
if (get_user_class() < UC_SYSOP)
	stderr("Error", "Permission denied.");

stdhead("Countrys");
print("<h2>Countrys</h2>\n");
print("</br>");
print("<table width=100% border=1 cellspacing=0 cellpadding=2><tr><td align=center>\n");

///////////////////// D E L E T E C A T E G O R Y \\\\\\\\\\\\\\\\\\\\\\\\\\\\

$sure = $_GET['sure'];
if($sure == "yes") {
$delid = $_GET['delid'];
$query = "DELETE FROM countries WHERE id=" .sqlesc($delid) . " LIMIT 1";
$sql = sql_query($query);
echo("Country successfuly removed![ <a href='country.php'>back</a> ]");
end_frame();
stdfoot();
die();
}
$delid = $_GET['delid'];
$name = $_GET['country'];
if($delid > 0) {
echo("Do you really wish to remove this group? ($name) ( <strong><a href='". $_SERVER['SCRIPT_NAME'] . "?delid=$delid&country=$name&sure=yes'>Yeah!</a></strong> / <strong><a href='". $_SERVER['SCRIPT_NAME'] . "'>Nah</a></strong> )");
end_frame();
stdfoot();
die();

}

///////////////////// E D I T A C A T E G O R Y \\\\\\\\\\\\\\\\\\\\\\\\\\\\
$edited = $_GET['edited'];
if($edited == 1) {
$id = $_GET['id'];
$country_name = $_GET['country_name'];
$country_flag = $_GET['country_flagpic'];
$query = "UPDATE countries SET
name = '$country_name',
flagpic = '$country_flagpic' WHERE id=".sqlesc($id);
$sql = sql_query($query);
if($sql) {
echo("<table class=main cellspacing=0 cellpadding=5 width=100%>");
echo("<tr><td><div align='center'><strong>Successfuly</strong>edited[ <a href='country.php'>back</a> ]</div></tr>");
echo("</table>");
end_frame();
stdfoot();
die();
}
}

$editid = $_GET['editid'];
$name = $_GET['name'];
$flagpic = $_GET['flagpic'];
if($editid > 0) {
echo("<form name='form1' method='get' action='" . $_SERVER['SCRIPT_NAME'] . "'>");
echo("<table class=main cellspacing=0 cellpadding=5 width=100%>");
echo("<div align='center'><input type='hidden' name='edited' value='1'>Now you are editing country <strong>\"$name\"</strong></div>");
echo("<br>");
echo("<input type='hidden' name='id' value='$editid'<table class=main cellspacing=0 cellpadding=5 width=100%>");
echo("<tr><td>Country Name: </td><td align='left'><input type='text' id=specialboxn size=50 name='country_name' value='$name'></td></tr>");
echo("<tr><td>Country Flag: </td><td align='left'><input type='text' id=specialboxn size=50 name='country_flagpic' value='$flagpic'> <input type='Submit' class='btn' value='save'></td></tr>");
echo("</table></form>");
end_frame();
stdfoot();
die();
}

///////////////////// A D D A N E W C A T E G O R Y \\\\\\\\\\\\\\\\\\\\\\\\\\\\
$add = $_GET['add'];
if($add == 'true') {
$country_name = $_GET['country_name'];
$country_flagpic = $_GET['country_flagpic'];
$query = "INSERT INTO countries SET
name = '$country_name',
flagpic = '$country_flagpic'";
$sql = sql_query($query);
if($sql) {
$success = TRUE;
} else {
$success = FALSE;
}
}
print("<strong>Add new Country:</strong>");
print("<br />");
print("<br />");
echo("<form name='form1' method='get' action='" . $_SERVER['SCRIPT_NAME'] . "'>");
echo("<table class=main cellspacing=0 cellpadding=5 width=100%>");
echo("<tr><td>Country Name: </td><td align='left'><input type='text' size=50 id=specialboxn name='country_name'></td></tr>");
echo("<tr><td>Country Flag: </td><td align='left'><input type='text' size=50 id=specialboxn name='country_flagpic'><input type='hidden' name='add' value='true'> <input type='Submit' class='btn' value='save'></td></tr>");
echo("</table>");
if($success == TRUE) {
print("<strong>Success!</strong>");
}
echo("<br>");
echo("</form>");

///////////////////// E X I S T I N G C A T E G O R I E S \\\\\\\\\\\\\\\\\\\\\\\\\\\\

print("<strong>Existing Countrys:</strong>");
print("<br />");
print("<br />");
echo("<table class=main cellspacing=0 cellpadding=5 width=100%>");
echo("<td align=center class=colhead><b>ID</b></td><td class=colhead><b>Name</b></td><td align=center class=colhead><b>Picture</b></td><td  align=center class=colhead><b>Edit</b></td><td align=center class=colhead><b>Delete</b></td>");
$query = "SELECT * FROM countries WHERE 1=1";
$sql = sql_query($query);
while ($row = mysql_fetch_array($sql)) {
$id = $row['id'];
$name = $row['name'];
$flagpic = $row['flagpic'];
echo("<tr><td  align=center><strong>$id</strong> </td> <td><strong>$name</strong></td> <td  align=center><img src='".$rootpath.$pic_base_url."flag/' border='0' /></td> <td><a href='" . $PHP_SELF['SCRIPT_NAME'] . "country.php?editid=$id&name=$name&flagpic=$flagpic'><div align='center'><img src='".$rootpath.$pic_base_url."multipage.gif' border='0' class=special /></a></div></td> <td><div align='center'><a href='country.php?delid=$id&country=$name'><img src='".$rootpath.$pic_base_url."warned2.gif' border='0' class=special align='center' /></a></div></td></tr>");
}

end_frame();
end_frame();
stdfoot();
?>