<?php

/*
// +--------------------------------------------------------------------------+
// | Project:    NVTracker - NetVision BitTorrent Tracker                     |
// +--------------------------------------------------------------------------+
// | This file is part of NVTracker. NVTracker is based on BTSource,          |
// | originally by RedBeard of TorrentBits, extensively modified by           |
// | Gartenzwerg.                                                             |
// |                                                                          |
// | NVTracker is free software; you can redistribute it and/or modify        |
// | it under the terms of the GNU General Public License as published by     |
// | the Free Software Foundation; either version 2 of the License, or        |
// | (at your option) any later version.                                      |
// |                                                                          |
// | NVTracker is distributed in the hope that it will be useful,             |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            |
// | GNU General Public License for more details.                             |
// |                                                                          |
// | You should have received a copy of the GNU General Public License        |
// | along with NVTracker; if not, write to the Free Software Foundation,     |
// | Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            |
// +--------------------------------------------------------------------------+
// | Obige Zeilen dürfen nicht entfernt werden!    Do not remove above lines! |
// +--------------------------------------------------------------------------+
 */

require "include/bittorrent.php";
dbconn();
loggedinorreturn();

$act = $_GET["act"];
$id = $_GET["id"];
// DELETE FORUM ACTION
if ($_GET['action'] == "del") {

if (get_user_class() < UC_MODERATOR)
stderr("Error", "<b><p>Aber Hallo Kollege, wat willst du denn hier?</p></b>");

if (!$id) {
header("Location: $PHP_SELF?act=forum&" . SID);
die();
} 

$result = mysql_query ("SELECT * FROM topics where forumid = '" . intval($_GET['id']) . "'"); 
if ($row = mysql_fetch_array($result)) {
do {
mysql_query ("DELETE FROM posts where topicid = '" . $row["id"] . "'") or sqlerr(__FILE__, __LINE__);
}

while ($row = mysql_fetch_array($result));
} 
mysql_query ("DELETE FROM topics where forumid = '" . $_GET['id'] . "'") or sqlerr(__FILE__, __LINE__);
mysql_query ("DELETE FROM forums where id = '" . $_GET['id'] . "'") or sqlerr(__FILE__, __LINE__);

header("Location: $PHP_SELF?act=forum&" . SID);
die();
} 


// EDIT FORUM ACTION
if ($_POST['action'] == "editforum") {

if (get_user_class() < UC_MODERATOR)
stderr("Error", "<b><p>Aber Hallo Kollege, wat willst du denn hier?</p></b>");

if (!$name && !$desc && !$id) {
header("Location: $PHP_SELF?act=forum&" . SID);
die();
} 

mysql_query("UPDATE forums SET sort = '" . $_POST['sort'] . "', name = " . sqlesc($_POST['name']) . ", description = " . sqlesc($_POST['desc']) . ", minclassread = '" . $_POST['readclass'] . "', minclasswrite = '" . $_POST['writeclass'] . "', minclasscreate = '" . $_POST['createclass'] . "' where id = '" . $_POST['id'] . "'") or sqlerr(__FILE__, __LINE__);
header("Location: $PHP_SELF?act=forum&" . SID);
die();
} 


// ADD FORUM ACTION
if ($_POST['action'] == "addforum") {

if (get_user_class() < UC_MODERATOR)
stderr("Error", "<b><p>Aber Hallo Kollege, wat willst du denn hier?</p></b>");

$name = $_POST["name"];
if (!$name)
stderr("Forum erstellen","<b></p>Der Forenname darf nicht leer sein!</p></b>");

$description = $_POST["desc"];
if (!$description)
stderr("Forum erstellen","<b><p>Die Forenbeschreibung darf nicht leer sein!</p></b>");

if (!$name && !$desc) {
header("Location: $PHP_SELF?act=forum&" . SID);
die();
}

$minclassread = $_POST["readclass"];
$minclasswrite = $_POST["writeclass"];
$minclasscreate = $_POST["createclass"];
$sort = $_POST["sort"];

mysql_query("INSERT INTO forums (sort, name,  description,  minclassread,  minclasswrite, minclasscreate) VALUES (" . $_POST['sort'] . ", " . sqlesc($_POST['name']) . ", " . sqlesc($_POST['desc']) . ", " . $_POST['readclass'] . ", " . $_POST['writeclass'] . ", " . $_POST['createclass'] . ")") or sqlerr(__FILE__, __LINE__);

header("Location: $PHP_SELF?act=forum&" . SID);
die();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////// FORUM bearbeiten Anfang /////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stdhead("Forenverwaltung");

if (get_user_class() < UC_MODERATOR) {
stderr("Error", "<b><p>Aber Hallo Kollege, wat willst du denn hier?</p></b>");

} else {
begin_frame("<span class=normalfont><b>Forenverwaltung</b></span>");

?>
<script language="JavaScript">
<!--
function confirm_delete(id) {
if(confirm('Bist du dir sicher das du das Forum löschen willst?')) {
self.location.href='<?php $PHP_SELF?> ?action=del&id='+id;
 }
}
//-->
</script>

<?php
print("<br><table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"790\"><tr>
<td align=\"left\"><img src=\"".$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]."/obenlinks.gif\"></td>
<td align=\"center\" width=\"100%\" class=\"obenmitte\"></td>
<td align=\"right\"><img src=\"".$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]."/obenrechts.gif\"></td>
</tr></table>");

print("<table align=\"center\" cellpadding=\"4\" cellspacing=\"1\"  border=\"0\" width=\"790\" class=\"tableinborder\">");
print("<tr><td class=\"tabletitle\"><b>Name</b></td><td align=\"center\" class=\"tabletitle\"><b>Topics</b></td><td align=\"center\" class=\"tabletitle\"><b>Posts</b></td><td align=\"center\" class=\"tabletitle\"><b>Lesen</b></td><td align=\"center\" class=\"tabletitle\"><b>Schreiben</b></td><td align=\"center\" class=\"tabletitle\"><b>Erstellen</b></td><td align=\"center\" class=\"tabletitle\"><b>Editieren</b></td></tr>");

$result = mysql_query ("SELECT  * FROM forums ORDER BY sort ASC");

if ($row = mysql_fetch_array($result)) {
do {
print("<tr><td class=\"tablea\"><a href=\"forums.php?action=viewforum&forumid=".$row["id"]."\"><b>".$row["name"]."</b></a><br>".$row["description"]."</td>");
print("<td align=\"center\" class=\"tablea\">".$row["topiccount"]."</td><td align=\"center\" class=\"tablea\">".$row["postcount"]."</td><td class=\"tablea\">Min. ".get_user_class_name($row["minclassread"])."</td><td class=\"tablea\">Min. ".get_user_class_name($row["minclasswrite"])."</td><td class=\"tablea\">Min. ".get_user_class_name($row["minclasscreate"])."</td><td align=\"center\" class=\"tablea\"><a href=\"".$PHP_SELF . "?act=editforum&id=".$row["id"]."\"><img src=\"$BASEURL/pic/edit.png\" alt=\"Bearbeiten\" title=\"Bearbeiten\" border=\"0\" align=\"middle\"></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:confirm_delete('" . $row["id"] . "');\"><img src=\"$BASEURL/pic/editdelete.png\" alt=\"Löschen\" title=\"Löschen\" border=\"0\" align=\"middle\"></a></b></td></tr>");
}

while ($row = mysql_fetch_array($result));
} else {
print "<tr><td colspan=\"7\" class=\"tablea\">Es wurden keine Foren gefunden!</td></tr>";
} 
print("</table>");

print("<table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"790\"><tr>
<td align=\"left\"><img src=\"".$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]."/untenlinks.gif\"></td>
<td align=\"center\" width=\"100%\" class=\"untenmitte\"></td>
<td align=\"right\"><img src=\"".$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]."/untenrechts.gif\"></td>
</tr></table><br>");

print("<center><p><a href=\"forummanager.php?act=addforum\"><input type=\"submit\" value=\"Forum hinzufügen\" class=\"btn\"></a></p></center>");

if ($act == "addforum") {

?>
<br><table align="center" cellspacing="0" cellpadding="0" border="0" width="600"><tr>
<td align="left"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/obenlinks.gif"></td>
<td align="center" width="100%" class="obenmitte"></td>
<td align="right"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/obenrechts.gif"></td>
</tr></table>

<form method="post" action="<?=$PHP_SELF?>">
<table align="center" cellpadding="4" cellspacing="1"  border="0" width="600" class="tableinborder">
<tr><td align="center" colspan="2" class="tabletitle"><span class=\"normalfont\"><b>Neues Forum erstellen</b></span></td></tr>
<tr><td class="tableb"><b>Forenname</b></td><td class="tablea"><input name="name" type="text" size="60" maxlength="60"></td></tr>
<tr><td class="tableb"><b>Forenbeschreibung</b></td><td class="tablea"><input name="desc" type="text" size="60" maxlength="200"></td></tr>
<tr><td class="tableb"><b>Min. Leserechte</b></td><td class="tablea">
<select name=readclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");
?>

</select>
</td></tr>
<tr><td class="tableb"><b>Min. Schreibrechte</b></td><td class="tablea">
<select name=writeclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");
?>

</select></td></tr>
<tr><td class="tableb"><b>Min. Rechte Topic erstellen</b></td><td class="tablea">
<select name=createclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");
?>

</select></td></tr>
<tr><td class="tableb"><b>Forenrank</b></td><td class="tablea">
<select name=sort>

<?php
$res = mysql_query ("SELECT sort FROM forums");
$nr = mysql_num_rows($res);
$maxclass = $nr + 1;
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i>$i");
?>

</select>
</td></tr>
<tr><td align="center" colspan="2" class="tableb"><input type="hidden" name="action" value="addforum"><input type="submit" name="Submit" value="Erstellen"></td></tr>
</table>

<table align="center" cellspacing="0" cellpadding="0" border="0" width="600"><tr>
<td align="left"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/untenlinks.gif"></td>
<td align="center" width="100%" class="untenmitte"></td>
<td align="right"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/untenrechts.gif"></td>
</tr></table><br>

<?php
}

if ($act == "editforum") {
// EDIT PAGE FOR THE FORUMS

$id = $_GET["id"];

$result = mysql_query ("SELECT * FROM forums where id = '$id'");

if ($row = mysql_fetch_array($result)) {
do {
?>
<form method="post" action="<?=$PHP_SELF?>">

<br><table align="center" cellspacing="0" cellpadding="0" border="0" width="600"><tr>
<td align="left"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/obenlinks.gif"></td>
<td align="center" width="100%" class="obenmitte"></td>
<td align="right"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/obenrechts.gif"></td>
</tr></table>

<table align="center" cellpadding="4" cellspacing="1" border="0" width="600" class="tableinborder">
<tr><td align="center" colspan="2" class="tabletitle"><span class"normalfont"><b>Forum <i>"<?=$row["name"]?>" bearbeiten</b></span></td></tr>
<tr><td class="tableb"><b>Forenname</b></td><td class="tablea"><input name="name" type="text" size="20" maxlength="60" value="<?=$row["name"]?>"></td></tr>
<tr><td class="tableb"><b>Forenbeschreibung</b></td><td class="tablea"><input name="desc" type="text" size="30" maxlength="200" value="<?=$row["description"]?>"></td></tr>
<tr><td class="tableb"><b>Min. Leserechte</b></td><td class="tablea">
<select name=readclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($row["minclassread"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");

?>
</select>
</td></tr>
<tr><td class="tableb"><b>Min. Schreibrechte</b></td><td class="tablea">
<select name=writeclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($row["minclasswrite"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");

?>
</select></td></tr>
<tr><td class="tableb"><b>Min. Rechte Topic erstellen</b></td><td class="tablea">
<select name=createclass>

<?php
$maxclass = get_user_class();
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($row["minclasscreate"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "");

?>
</select></td></tr>
<tr><td class="tableb"><b>Forenrank</b></td><td class="tablea">
<select name=sort>

<?php
$res = mysql_query ("SELECT sort FROM forums");
$nr = mysql_num_rows($res);
$maxclass = $nr + 1;
for ($i = 0; $i <= $maxclass; ++$i)
print("<option value=$i" . ($row["sort"] == $i ? " selected" : "") . ">$i");

?>
</select></td></tr>
<tr><td align="center" colspan="2" class="tableb"><input type="hidden" name="action" value="editforum"><input type="hidden" name="id" value="<?=$id?>"><input type="submit" name="Submit" value="Forum editieren"></td></tr>
</table>

<table align="center" cellspacing="0" cellpadding="0" border="0" width="600"><tr>
<td align="left"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/untenlinks.gif"></td>
<td align="center" width="100%" class="untenmitte"></td>
<td align="right"><img src="<?=$GLOBALS["PIC_BASE_URL"] . $GLOBALS["ss_uri"]?>/untenrechts.gif"></td>
</tr></table><br>

<?php
}

while ($row = mysql_fetch_array($result));
} else {
print "Sorry, aber es wurde kein Forum gefunden!";
  }
 }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////// FORUM bearbeiten Ende ///////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

end_frame();
stdfoot();
?>