<?php

require_once("include/bittorrent.php");

function bark($msg) {
    stderr("Fehler", $msg);
}

dbconn();

loggedinorreturn();

if($_SERVER["REQUEST_METHOD"]==="POST") {
  $destid=$_POST["destid"]+0;
  $gb=trim($_POST["gbgift"])+0;
  $ok=(ereg("^[0-9]+$",$gb)&&$gb>0);
  $faktor=$_POST["gbfaktor"]+0;
  if($ok)
  {
    $sum=$gb*$faktor*1024;
    if($CURUSER["konto"]-$CURUSER["gbgift"]>=$sum)
    {
      mysql_query("update users set konto=konto+$sum where id=$destid");
      mysql_query("update users set konto=konto-$sum where id=$CURUSER[id]");
      $row=mysql_fetch_array(mysql_query("select * from users where id=$CURUSER[id]"));
      $GLOBALS["CURUSER"] = $row;
      $_SESSION["userdata"] = $row;
      sendPersonalMessage(0, $destid, "Spende", "Der User [URL=userdetails.php?id=$CURUSER[id]]$CURUSER[username][/URL] hat Dir\n\n[b]".mksize($sum)."[/b]\n\n geschenkt.");
      $row=mysql_fetch_array(mysql_query("select * from users where id=$destid"));
      write_modcomment($destid, 0, mksize($sum)." von [url=userdetails.php?id=".$CURUSER["id"]."]".$CURUSER["username"]."[/url] bekommen");
      write_modcomment($CURUSER["id"], 0, mksize($sum)." an [url=userdetails.php?id=$destid]".$row["username"]."[/url] verschenkt");
      header("Location: userdetails.php?id=$destid");
    }
    else
      bark("Dein Konto erlaubt eine solche Spende nicht");
  }
  else
    bark("Ungültige Eingabe");
}
else 
  bark("Zugriff verweigert");

?>