<?

require_once("include/bittorrent.php");
dbconn(true);
loggedinorreturn();
if (get_user_class() < UC_USER){
stderr("Fehler","Zugriff erst ab User!!!");
}

stdhead("Partner Ankündigungen");
$action = htmlentities($_GET["action"]);

if(empty($action)) {

$get_partnerpm = mysql_query("SELECT * FROM partnernews ORDER BY id DESC");
begin_frame("Partner News");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
<?
if (get_user_class() >= UC_MODERATOR){
?>
  <tr>
    <td class="tableb" width="100%"><center><a href="partnerpm.php?action=create_partnerpm">Partner News hinzufügen</a></center></td>
  </tr>
<?
}
?>
</table>
<br />
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Tracker</td>
    <td class="tableb">Datum</td>
    <td class="tableb">Betreff</td>
    <td class="tableb">Eingetragen</td>
    <td class="tableb">News des Partners</td>
<?
if (get_user_class() >= UC_MODERATOR){
?>
    <td class="tableb" colspan="2">Optionen</td>
<?
}
?>
  </tr>
<?
while($data_partnerpm = mysql_fetch_array($get_partnerpm)) {
?>
  <tr>
    <td class="tablea"><?php echo htmlentities($data_partnerpm["tracker"]); ?></td>
    <td class="tablea"><?php echo htmlentities($data_partnerpm["datum"]); ?></td>
    <td class="tablea"><?php echo htmlentities($data_partnerpm["titel"]); ?></td>
<?
$sql = mysql_query("SELECT anon FROM users");
$user = mysql_fetch_array($sql);
if ($user["anon"] == "yes" && get_user_class() < UC_MODERATOR){
?>
    <td class="tablea">Anonym*</td>
<?
}else{
?>
    <td class="tablea"><a href="userdetails.php?id=<?php echo htmlentities($data_partnerpm["von"]); ?>"><?php echo htmlentities($data_partnerpm["von"]); ?></a></td>
<?
}
?>
    <td class="tablea"><a href="partnerpm.php" onmouseover="return overlib('<font color=red><b>Nachricht des Partners</b></font><br><?php echo htmlentities($data_partnerpm["text"]); ?>', CSSCLASS);" onmouseout="return nd();">Hier mit der Maus drüberfahren</a></td>
<?
if (get_user_class() >= UC_MODERATOR){
?>
    <td class="tablea"><center><a href="partnerpm.php?action=edit_partnerpm&id=<?php echo htmlentities($data_partnerpm["id"]); ?>">Editieren</a></center></td>
    <td class="tablea"><center><a href="partnerpm.php?action=delete_partnerpm&id=<?php echo htmlentities($data_partnerpm["id"]); ?>">Löschen</a></center></td>
<?
}
?>
  </tr>
<? } ?>
</table>
<?
end_frame();
}
if($action == "create_partnerpm" AND get_user_class() >= UC_MODERATOR) {
begin_frame("Partner News hinzufügen");
?>
<form method="post" action="partnerpm.php?action=create_partnerpm_do">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Tracker</td>
    <td class="tablea"><input type="text" name="tracker" /></td>
  </tr>
  <tr>
    <td class="tableb">Betreff</td>
    <td class="tablea"><input type="text" name="titel" /></td>
  </tr>
    <input type="hidden" name="username" value="<?=$CURUSER["username"]?>"/>
  <tr>
    <td class="tableb">Nachricht</td>
    <td class="tablea"><input type="text" name="text" /></td>
  </tr>
  <tr>
    <td class="tableb">Optionen</td>
    <td class="tablea"><input name="submit" type="submit" value="Eintragen" /> <input name="reset" type="reset" /></td>
  </tr>
</table>
</form>
<?
end_frame();
}

if($action == "edit_partnerpm" AND get_user_class() >= UC_MODERATOR) {
begin_frame("Partner News Editieren");
$id = $_GET["id"];
$data_partnerpm = mysql_fetch_array(mysql_query("SELECT * FROM partnernews WHERE id = '$id'"));
?>
<form method="post" action="partnerpm.php?action=edit_partnerpm_do&id=<?=$id?>">
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Tracker</td>
    <td class="tablea"><input type="text" name="tracker" value="<?php echo htmlentities($data_partnerpm["tracker"]); ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Betreff</td>
    <td class="tablea"><input type="text" name="titel" value="<?php echo htmlentities($data_partnerpm["titel"]); ?>" /></td>
  </tr>
    <input type="hidden" name="username" value="<?=$CURUSER["username"]?>"/>
  <tr>
    <td class="tableb">Nachricht</td>
    <td class="tablea"><input type="text" name="text" value="<?php echo htmlentities($data_partnerpm["text"]); ?>" /></td>
  </tr>
  <tr>
    <td class="tableb">Optionen</td>
    <td class="tablea"><input name="submit" type="submit" value="Eintragen" /> <input name="reset" type="reset" /></td>
  </tr>
</table>
</form>
<?
end_frame();
}

if($action == "create_partnerpm_do" AND get_user_class() >= UC_MODERATOR) {

$error = 0;
$tracker = $_POST["tracker"];
$titel = $_POST["titel"];
$username = $_POST["username"];
$text = $_POST["text"];

if(empty($tracker) OR empty($titel) OR empty($text)) { $error = 1; }

begin_frame("Partner News Erstellen");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Du musst alle Felder ausfüllen..... [<a href="partnerpm.php?action=create_partnerpm">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("INSERT INTO partnernews (datum, von, titel, text, tracker) Values( Now(), ".sqlesc($username).", ".sqlesc($titel).", ".sqlesc($text).", ".sqlesc($tracker).")") or sqlerr(__FILE__,__LINE__);
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Partner News erfolgreich eingetragen..... [<a href="partnerpm.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "edit_partnerpm_do" AND get_user_class() >= UC_MODERATOR) {

$error = 0;
$id = $_GET["id"];
$tracker = $_POST["tracker"];
$titel = $_POST["titel"];
$text = $_POST["text"];

if(empty($tracker) OR empty($titel) OR empty($text)) { $error = 1; }

begin_frame("Partner News Editieren");
if($error == 1) {
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Du musst alle Felder ausfüllen..... [<a href="partnerpm.php?action=edit_partnerpm&id=<?=$id?>">Zurück</a>]</td>
  </tr>
</table>
<?
} else {
mysql_query("UPDATE partnernews SET tracker='$tracker', titel='$titel', text='$text' WHERE id = '$id'");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Partner News erfolgreich editiert..... [<a href="partnerpm.php">Weiter</a>]</td>
  </tr>
</table>
<?
}
end_frame();
}
if($action == "delete_partnerpm" AND get_user_class() >= UC_MODERATOR) {

$id = $_GET["id"];
mysql_query("DELETE FROM partnernews WHERE id = '$id'");
begin_frame("Partner News Löschen");
?>
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tableinborder">
  <tr>
    <td class="tableb">Partner News erfolgreich gelöscht..... [<a href="partnerpm.php">Weiter</a>]</td>
  </tr>
</table>
<?
end_frame();
}
stdfoot();
?>