<?php

/*
// +--------------------------------------------------------------------------+
// | Project:    NVTracker - NetVision BitTorrent Tracker                     |
// +--------------------------------------------------------------------------+
// | 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! |
// +--------------------------------------------------------------------------+
//
// erstellt von Cerberus - für e-Xtreme-Tracker -- 22.01.2008
*/

require_once($_SERVER["DOCUMENT_ROOT"] . "/include/bittorrent.php");

dbconn();
loggedinorreturn();

if ($_POST["a"] == "") $action = "view";
else $action = $_POST["a"];

if (get_user_class() < UC_MODERATOR)
{
   stderr("Error", "Du bist es nicht wert, diese Seite zu betrachten. Geh nach Hause zu deiner Mama !!!");
   exit;
}

if (($action != "view") && (get_user_class() != UC_CODER))
{
   stderr("Error", "Na so geht das nu aber schonmal garnicht !!!");
   exit;
}

function get_monat($mon)
{
  switch($mon)
  {
     case "01" : return "Januar";
                 break;
     case "02" : return "Februar";
                 break;
     case "03" : return "M&auml;rz";
                 break;
     case "04" : return "April";
                 break;
     case "05" : return "Mai";
                 break;
     case "06" : return "Juni";
                 break;
     case "07" : return "Juli";
                 break;
     case "08" : return "August";
                 break;
     case "09" : return "September";
                 break;
     case "10" : return "Oktober";
                 break;
     case "11" : return "November";
                 break;
     case "12" : return "Dezember";
                 break;
  }
}

function tabelle_start($monat, $jahr)
{
  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td colspan=\"2\" class=\"tabletitle\"><center><b>.: " . get_monat($monat) . " " . $jahr . " :.</b></center></td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td class=\"tablea\" width=\"100%\">\n");
  print("   <table class=\"tableinborder\" style=\"width: 100%;\" cellpadding=\"4\" cellspacing=\"1\">\n");
}

function tab_zeile($datum, $text, $id)
{
  $edit = "";
  if (get_user_class() == UC_CODER)
  {
    $edit .= "<form action=\"" . $_SERVER[PHP_SELF] . "\" method=\"post\">\n";
    $edit .= " <input type=\"hidden\" value=\"" . $id . "\" name=\"id\">\n";
    $edit .= " <input type=\"hidden\" value=\"edit\" name=\"a\">\n";
    $edit .= " <input type=\"submit\" value=\"Edit\" name=\"go\">\n";
    $edit .= "</form>\n";
  }
  print("     <tr>\n");
  print("       <td class=\"tablea\" valign=\"top\" width=\"90\"><b><u>" . $datum . "</u></b><br /><br />\n" . $edit . "</td>\n");
  print("       <td class=\"tablea\" valign=\"top\">\n");
  print($text . "\n");
  print("       </td>\n");
  print("     </tr>\n");
}

function tabelle_ende()
{
  print("   </table>\n");
  print("  </td>\n");
  print(" </tr>\n");
  print("</table>\n");
  print("<br>\n");
}

function trenner($jahr)
{
  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td class=\"tabletitle\" width=\"100%\"><center><font color=\"red\"><b>.: " . $jahr . " :.</b></font></center></td>\n");
  print(" </tr>\n");
  print("</table>\n");
  print("<br>\n");
}


stdhead("Coder-Logbuch v2.0");

/////////////////////////////////////////
//       neuen Eintrag erstellen       //
/////////////////////////////////////////
if ($action == "new")
{
  $tag   = date(d);
  $monat = date(m);
  $jahr  = date(Y);

  print("<form action=\"" . $_SERVER[PHP_SELF] . "\" method=\"post\">\n");
  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td colspan=\"3\" class=\"tabletitle\"><center><b>.: neuen Eintrag erstellen :.</b></center></td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td class=\"tablea\" width=\"33%\">Tag <input type=\"text\" value=\"" . $tag . "\" name=\"tag\"></td>\n");
  print("  <td class=\"tablea\" width=\"33%\">Monat <input type=\"text\" value=\"" . $monat . "\" name=\"monat\"></td>\n");
  print("  <td class=\"tablea\" width=\"33%\">Jahr <input type=\"text\" value=\"" . $jahr . "\" name=\"jahr\"></td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td class=\"tablea\" width=\"100%\" colspan=\"3\">\n");
  print("    Beschreibung:<br><textarea name=\"arbeiten\" cols=\"120\" rows=\"10\"></textarea>\n");
  print("  </td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" colspan=\"3\" class=\"tabletitle\">\n");
  print("   <center>\n");
  print("      <input type=\"hidden\" value=\"add\" name=\"a\">\n");
  print("      <input type=\"submit\" value=\"hinzuf&uuml;gen\" name=\"go\">\n");
  print("   </center>\n");
  print("  </td>\n");
  print(" </tr>\n");
  print("</table>\n");
  print("</form>\n");}

/////////////////////////////////////////
//       neuen Eintrag einfügen        //
/////////////////////////////////////////
if ($action == "add")
{
  $tag    = htmlentities($_POST["tag"]);
  $monat  = htmlentities($_POST["monat"]);
  $jahr   = htmlentities($_POST["jahr"]);
  $text   = nl2br(htmlentities($_POST["arbeiten"]));
  $text   = str_replace("'","&prime;",$text);
  $t_code = strtotime($tag.".".$monat.".".$jahr);

  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tabletitle\"><center><b>.: neuen Eintrag einf&uuml;gen :.</b></center></td>\n");
  print(" </tr>\n");

  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tablea\">\n");
  $query = "INSERT INTO trackerlog (timecode, tag, monat, jahr, eintrag) VALUES ($t_code, '$tag', '$monat', '$jahr', '$text')";
  if (mysql_query($query))
  {
    print("<font color=\"green\">Erfolgreich</font><br />\n");
    print("TimeCode :" . $t_code . "<br />\n");
    print("Datum :" . $tag . "." . $monat . "." . $jahr . "<br />\n");
    print("Daten :<br />\n");
    print($text . "\n");
  }
  else
  {
    print("<font color=\"red\">Fehler beim einf&uuml;gen</font><br />\n");
    print("TimeCode :" . $t_code . "<br />\n");
    print("Datum :" . $tag . "." . $monat . "." . $jahr . "<br />\n");
    print("Daten :<br />\n");
    print($text . "\n");
  }
  print("  </td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tabletitle\"><center><b><a href=\"" . $_SERVER[PHP_SELF] . "\">weiter &rArr;</a></b></center></td>\n");
  print(" </tr>\n");
  print("</table>\n");
}

/////////////////////////////////
//       Eintrag ändern        //
/////////////////////////////////
if ($action == "update")
{
  $id    = intval($_POST["id"]);
  $tag   = htmlentities($_POST["tag"]);
  $monat = htmlentities($_POST["monat"]);
  $jahr  = htmlentities($_POST["jahr"]);
  $text  = nl2br(htmlentities($_POST["text_edit"]));
  $text  = str_replace("'","&prime;",$text);
 
  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tabletitle\"><center><b>.: Eintrag " . $id . " ge&auml;ndert :.</b></center></td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tablea\">\n");
  $query = "UPDATE trackerlog SET tag='$tag', monat='$monat', jahr='$jahr', eintrag='$text' WHERE id='$id'";
  if (mysql_query($query))
  {
    print("<font color=\"green\">Erfolgreich</font><br />\n");
    print("Datum :" . $tag . "." . $monat . "." . $jahr . "<br />\n");
    print("Daten :<br>\n");
    print($text . "\n");
  }
  else
  {
    print("<font color=\"red\">Fehler beim &auml;dern der Daten</font><br />\n");
    print("Datum :" . $tag . "." . $monat . "." . $jahr . "<br />\n");
    print("Daten :<br />\n");
    print($text . "\n");
  }
  print("  </td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tabletitle\"><center><b><a href=\"" . $_SERVER[PHP_SELF] . "\">weiter &rArr;</a></b></center></td>\n");
  print(" </tr>\n");
  print("</table>\n");
}

////////////////////////////////////
//       Eintrag bearbeiten       //
////////////////////////////////////
if ($action == "edit")
{
  $id = intval($_POST["id"]);
  $res = mysql_query("SELECT * FROM trackerlog WHERE id = '$id'");
  if ($daten = mysql_fetch_array($res))
  {
    $text = str_replace("<br />","",$daten[eintrag]);
    print("<form action=\"" . $_SERVER[PHP_SELF] . "\" method=\"post\">\n");
    print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
    print(" <tr>\n");
    print("  <td colspan=\"3\" class=\"tabletitle\"><center><b>.: Eintrag " . $id . " bearbeiten :.</b></center></td>\n");
    print(" </tr>\n");
    print(" <tr>\n");
    print("  <td class=\"tablea\" width=\"33%\">Tag <input type=\"text\" value=\"" . $daten[tag] . "\" name=\"tag\"></td>\n");
    print("  <td class=\"tablea\" width=\"33%\">Monat <input type=\"text\" value=\"" . $daten[monat] . "\" name=\"monat\"></td>\n");
    print("  <td class=\"tablea\" width=\"33%\">Jahr <input type=\"text\" value=\"" . $daten[jahr] . "\" name=\"jahr\"></td>\n");
    print(" </tr>\n");
    print(" <tr>\n");
    print("  <td class=\"tablea\" width=\"100%\" colspan=\"3\">\n");
    print("    Beschreibung:<br><textarea name=\"text_edit\" cols=\"120\" rows=\"10\">" . $text . "</textarea>\n");
    print("  </td>\n");
    print(" </tr>\n");
    print(" <tr>\n");
    print("  <td width=\"100%\" colspan=\"3\" class=\"tabletitle\">\n");
    print("   <center>\n");
    print("      <input type=\"hidden\" value=\"" . $id . "\" name=\"id\">\n");
    print("      <input type=\"hidden\" value=\"update\" name=\"a\">\n");
    print("      <input type=\"submit\" value=\"&Auml;ndern\" name=\"go\">\n");
    print("   </center>\n");
    print("  </td>\n");
    print(" </tr>\n");
    print("</table>\n");
    print("</form>\n");
  }
}

/////////////////////////////////////////
//       alle Einträge anzeigen        //
/////////////////////////////////////////
if ($action == "view")
{
  print("<table style=\"width: 750px;\" class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\n");
  print(" <tr>\n");
  print("  <td colspan=\"2\" class=\"tabletitle\"><center><b>.: Allgemein :.</b></center></td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tablea\">\n");
  print("   <center>\n");
  print("     <font color=\"blue\">Hier kann das Team alle &Auml;nderungen am Tracker nachlesen.<br />\n");
  print("      Ich werde versuchen immer alles zu Dokumentieren, was ich wann wo ge&auml;ndert habe.<br />\n");
  print("      <i>mfg Cerberus</i>\n");
  print("     </font>\n");
  print("   </center>\n");
  print("  </td>\n");
  print(" </tr>\n");
  print(" <tr>\n");
  print("  <td width=\"100%\" class=\"tabletitle\">\n");
  print("   <center>\n");
  print("    <form action=\"" . $_SERVER[PHP_SELF] . "\" method=\"post\">\n");
  print("     <input type=\"hidden\" value=\"new\" name=\"a\">\n");
  print("     <input type=\"submit\" value=\"neuer Eintrag\" name=\"go\">\n");
  print("    </form>\n");
  print("   </center>\n");
  print("  </td>\n");
  print(" </tr>\n");
  print("</table>\n");
  print("<br>\n");

  $m = "";
  $y = "";
  $res = mysql_query("SELECT * FROM trackerlog ORDER BY timecode DESC");
  while($daten = mysql_fetch_array($res))
  {
    if (($y != '') && ($m != ''))
      if (($daten[jahr] != $y) || ($daten[monat] != $m))
      {
        tabelle_ende();
      }
    $datum = $daten[tag] . "." . $daten[monat] . ".";

    if (($daten[jahr] != $y) && ($y != ''))
      trenner($y);

    if (($daten[jahr] != $y) || ($daten[monat] != $m))
    {
      $m = $daten[monat];
      $y = $daten[jahr];
      tabelle_start($daten[monat], $daten[jahr]);
    }
    tab_zeile($datum, $daten[eintrag], $daten[id]);
  } 
  tabelle_ende();
}


stdfoot(true);
?> 