<?

/*
// +--------------------------------------------------------------------------+
// | 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_once("include/bittorrent.php");

hit_start();

function bark($msg) {
	genbark($msg, "Aktualisierung Deiner Daten fehlgeschlagen!");
}

dbconn();

hit_count();

loggedinorreturn();

if (isset($_POST["rulessubmit"])) {
    if ($_POST["acceptrules"] == "yes") {
	mysql_query("UPDATE `users` SET `accept_rules`='yes' WHERE `id`=".$CURUSER["id"]);
	stderr("Regeln akzeptiert!", "<p>Du hast die Regeln akzeptiert, und kannst nun den Tracker weiter verwenden.</p><p>Bitte halte Dich auch an die Regeln!</p>");
    } else
	bark("Du musst die geänderten Regeln akzeptieren, bevor Du diesen Tracker weiterhin verwenden darfst!");
}

if (!mkglobal("email:chpassword:passagain"))
	bark("missing form data");

// $set = array();

$updateset = array();
$changedemail = 0;

if ($chpassword != "") {
	if (strlen($chpassword) > 40)
		bark("Sorry, Dein Passwort ist zu lang (Maximal 40 Zeichen)");
	if ($chpassword != $passagain)
		bark("Die Passwörter stimmen nicht überein! Du musst Dich vertippt haben. bitte versuche es erneut!");

	$sec = mksecret();

        $passhash = md5($sec . $chpassword . $sec);

	$updateset[] = "secret = " . sqlesc($sec);
	$updateset[] = "passhash = " . sqlesc($passhash);
	logincookie($CURUSER["id"], $passhash);
}

if ($email != $CURUSER["email"]) {
	if (!validemail($email))
		bark("Das scheint keine gültige E-Mail Adresse zu sein.");
  $r = mysql_query("SELECT id FROM users WHERE email=" . sqlesc($email)) or sqlerr();
	if (mysql_num_rows($r) > 0)
		bark("Die E-Mail Adresse $email wird bereits verwendet.");
	$changedemail = 1;
}

$showrec = ($_POST["showrec"]!= "" ? "yes" : "no");

$acceptpms = $_POST["acceptpms"];
$geschlecht = $_POST["geschlecht"];
$gender = $_POST["gender"];
$parked = $_POST["parked"];
$wech = $_POST["wech"];
$xxx = $_POST["xxx"];
$uplspeed = htmlentities ($_POST["uplspeed"]);
$downspeed = htmlentities ($_POST["downspeed"]);
$isp = htmlentities ($_POST["isp"]);
$dsl_speed = $_POST["dsl_speed"];
$indexnav = $_POST["indexnav"];
$comnav = $_POST["comnav"];
$tornav = $_POST["tornav"];
$usernav = $_POST["usernav"];
$helpnav = $_POST["helpnav"];
$gamenav = $_POST["gamenav"];
$extranav = $_POST["extranav"];
$tspeaknav = $_POST["tspeaknav"];
$radionav = $_POST["radionav"];
$adminnav = $_POST["adminnav"];
$showradionav = $_POST["showradionav"];
$showtspeaknav = $_POST["showtspeaknav"];
$deletepms = ($_POST["deletepms"] != "" ? "yes" : "no");
$savepms = ($_POST["savepms"] != "" ? "yes" : "no");
$hideuseruploads = ($_POST["useruploads"] == "yes" ? "yes" : "no");
$wgeturl = ($_POST["wgeturl"] == "yes" ? "yes" : "no");
$acceptemails = $_POST["acceptemails"];
$werbung = $_POST["werbung"];
  	

$bgshout = $_POST["bgshout"];
$pmnotif = $_POST["pmnotif"];
$emailnotif = $_POST["emailnotif"];
$notifs = ($pmnotif == 'yes' ? "[pm]" : "");
$notifs .= ($emailnotif == 'yes' ? "[email]" : "");
$r = mysql_query("SELECT id FROM categories") or sqlerr();
$rows = mysql_num_rows($r);
for ($i = 0; $i < $rows; ++$i)
{
	$a = mysql_fetch_assoc($r);
	if ($HTTP_POST_VARS["cat$a[id]"] == 'yes')
	  $notifs .= "[cat$a[id]]";
}
$avatar = $_POST["avatar"];
$shoutanfang = $_POST["shoutanfang"];
$shoutende = $_POST["shoutende"];
$statbox = $_POST["statbox"];
$rstats = ($_POST["log_ratio"] != "" ? "yes" : "no");
$avatars = ($_POST["avatars"] != "" ? "yes" : "no");
$pcoff = $_POST["pcoff"];
$chpasskey = ($_POST["chpasskey"] == "1" ? "yes" : "no");
// $ircnick = $_POST["ircnick"];
// $ircpass = $_POST["ircpass"];
$info = $_POST["info"];
$stylesheet2 = $_POST["stylesheet2"];
$stylesheet = $_POST["stylesheet"];
$commentpm = $_POST["commentpm"];
$country = $_POST["country"];
//$timezone = 0 + $_POST["timezone"];
//$dst = ($_POST["dst"] != "" ? "yes" : "no");

/*
if ($privacy != "normal" && $privacy != "low" && $privacy != "strong")
	bark("whoops");

$updateset[] = "privacy = '$privacy'";
*/

$updateset[] = "oldtorrentlist = " . ($_POST["torrentlist"]=="old"?"'yes'":"'no'");

// BEGIN: Account Parken
if(get_user_class()>=UC_USER)
{
  if($_POST["parked"]=="yes") $updateset[] = "parked = 'yes'";
  else $updateset[] = "parked = 'no'";
}
//ENDE: Account Parken

// BEGIN: Anonymous Torrent Liste by truenoir
if(get_user_class()>=UC_POWER_USER)
{
  if($_POST["anon"]=="yes") $updateset[] = "anon = 'yes'";
  else $updateset[] = "anon = 'no'";
}
// END: Anonymous Torrent Liste by truenoir
$icq = unesc($_POST["icq"]);
if (strlen($icq) > 10)
    bark("Sorry, deine Icq NUmmer ist zu lang.(Max - 10)");
$updateset[] = "icq = " . sqlesc($icq);

$msn = unesc($_POST["msn"]);
if (strlen($msn) > 30)
    bark("Sorry, deine MSN Addresse ist zu lang.(Max - 30)");
$updateset[] = "msn = " . sqlesc($msn);

$aim = unesc($_POST["aim"]);
if (strlen($aim) > 30)
    bark("Sorry, dein AOL Screenname ist zu lang(Max - 30)");
$updateset[] = "aim = " . sqlesc($aim);

$yahoo = unesc($_POST["yahoo"]);
if (strlen($yahoo) > 30)
    bark("Sorry, dein Yahoo Screenname ist zu lang(Max - 30)");
$updateset[] = "yahoo = " . sqlesc($yahoo);

$skype = unesc($_POST["skype"]);
if (strlen($skype) > 20)
    bark("Sorry, dein Skypename ist zu lang(Max - 20)");
$updateset[] = "skype = " . sqlesc($skype);
$updateset[] = "geschlecht = " . sqlesc($geschlecht);
$updateset[] = "gender = " . sqlesc($gender);
$updateset[] = "torrentsperpage = " . min(100, 0 + $_POST["torrentsperpage"]);
$updateset[] = "topicsperpage = " . min(100, 0 + $_POST["topicsperpage"]);
$updateset[] = "postsperpage = " . min(100, 0 + $_POST["postsperpage"]);





if (is_valid_id($stylesheet))
  $updateset[] = "stylesheet = '$stylesheet'";


if (is_valid_id($country))
  $updateset[] = "country = $country";
$updateset[] = "pcoff =  " . sqlesc($pcoff);

//$updateset[] = "timezone = $timezone";
//$updateset[] = "dst = '$dst'";
$updateset[] = "showrec = " . sqlesc($showrec);
$updateset[] = "info = " . sqlesc($info);
$updateset[] = "acceptpms = " . sqlesc($acceptpms);
//BEGIN: Account Parken by volcem
$updateset[] = "parked = " . sqlesc($parked);
$updateset[] = "wech = " . sqlesc($wech);
//ENDE:Account Parken by volcem
$updateset[] = "xxx = '$xxx'";
$updateset[] = "uplspeed = " . sqlesc($uplspeed);
$updateset[] = "downspeed = " . sqlesc($downspeed);
$updateset[] = "isp = " . sqlesc($isp);
$updateset[] = "dsl_speed = " . sqlesc($dsl_speed);
$updateset[] = "indexnav = " . sqlesc($indexnav);
$updateset[] = "comnav = " . sqlesc($comnav);
$updateset[] = "tornav = " . sqlesc($tornav);
$updateset[] = "usernav = " . sqlesc($usernav);
$updateset[] = "helpnav = " . sqlesc($helpnav);
$updateset[] = "gamenav = " . sqlesc($gamenav);
$updateset[] = "bgshout = $bgshout";
$updateset[] = "extranav = " . sqlesc($extranav);
$updateset[] = "tspeaknav = " . sqlesc($tspeaknav);
$updateset[] = "radionav = " . sqlesc($radionav);
$updateset[] = "adminnav = " . sqlesc($adminnav);
$updateset[] = "showradionav = " . sqlesc($showradionav);
$updateset[] = "showtspeaknav = " . sqlesc($showtspeaknav);
$updateset[] = "deletepms = '$deletepms'";
$updateset[] = "savepms = '$savepms'";
$updateset[] = "accept_email = " . sqlesc($acceptemails);
$updateset[] = "werbung = " . sqlesc($werbung);
$updateset[] = "notifs = '$notifs'";
$updateset[] = "commentpm = " . sqlesc($commentpm);
$updateset[] = "avatar = " . sqlesc($avatar);
$updateset[] = "shoutanfang = " . sqlesc($shoutanfang);
$updateset[] = "shoutende = " . sqlesc($shoutende);
$updateset[] = "log_ratio = '$rstats'";
$updateset[] = "statbox = " . sqlesc($statbox);;
$updateset[] = "avatars = '$avatars'";
$updateset[] = "hideuseruploads = '$hideuseruploads'";
$updateset[] = "wgeturl = '$wgeturl'";

if ($chpasskey == "yes") {
    $updateset[] = "passkey = " . sqlesc(mksecret(8));
    write_log("passkeyreset", "PassKey wurde von Benutzer '<a href=\"userdetails.php?id=".$CURUSER["id"]."\">".$CURUSER["username"]."</a>' zurückgesetzt.");
}

/* ****** */

$urladd = "";

if ($changedemail) {
	$sec = mksecret();
	$hash = md5($sec . $email . $sec);
	$obemail = urlencode($email);
	$updateset[] = "editsecret = " . sqlesc($sec);
	$thishost = $_SERVER["HTTP_HOST"];
	$thisdomain = preg_replace('/^www\./is', "", $thishost);
	$body = <<<EOD
Du hast in Auftrag gegeben, dass Dein Profil (Benutzername {$CURUSER["username"]})
auf $thisdomain mit dieser E-Mail Adresse ($email) als Kontaktadresse aktualisiert
werden soll.

Wenn Du dies nicht beauftragt hast, ignoriere bitte diese Mail. Die Person, die
Deine E-Mail Adresse eingegeben hat, hatte die IP-Adresse {$_SERVER["REMOTE_ADDR"]}.
Bitte antworte nicht auf diese automatisch generierte Nachricht.

Um die Aktualisierung Deines Profils abzuschließen, klicke auf folgenden Link:

http://$thishost/confirmemail.php?id={$CURUSER["id"]}&secret=$hash&email=$obemail

Die neue E-Mail Adresse wird dann in Deinem Profil erscheinen. Wenn Du
diesen Link nicht anklickst, wird Dein Profil unverändert bleiben.
EOD;

	mail($email, "$thisdomain Profiländerungsbestätigung", $body, "From: ".$GLOBALS["SITEEMAIL"]);

	$urladd .= "&mailsent=1";
}

mysql_query("UPDATE users SET " . implode(",", $updateset) . " WHERE id = " . $CURUSER["id"]) or sqlerr(__FILE__,__LINE__);

// Session aktualisieren
session_unset();
$_SESSION["userdata"] = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = " . $CURUSER["id"]));



header("Location: $BASEURL/my.php?edited=1&".SID.$urladd);

hit_end();

?>