Location: PHPKode > projects > H-tracker > uploadapps.php
<?
//
//  H-Tracker v0.2
//    http://h-tracker.org
//    Based on TorrentTrader (http://www.torrenttrader.org)
//
//
require_once("backend/functions.php");
dbconn();
loggedinonly();

if (get_user_class() < 5)
  show_error_msg("Error", "You shouldn't be here.");

$action = $_GET["action"];

// View applications

if (!$action || $action == "show") {
  
  if ($action == "show")
	$hide = "[<a href=/uploadapps.php>Hide accepted/rejected</a>]";
  else {
	$hide = "[<a href=/uploadapps.php?action=show>Show accepted/rejected</a>]";
	$where = "WHERE status = 'pending'";
	$where1 = "WHERE uploadapp.status = 'pending'";
  }
  
  $res = mysql_query("SELECT count(id) FROM uploadapp $where")  or sqlerr(__FILE__, __LINE__);
  $row = mysql_fetch_array($res);
  $url = " .$_SERVER[PHP_SELF]?";
  $count = $row[0];
  $perpage = 25;
  list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $url);

  stdhead("Uploader applications");
  begin_frame("Uploader applications");
  if ($count == 0) {
	print("<table class=tablebg width=90% border=0 cellspacing=0 cellpadding=5 align=center>\n");
	print("<tr><td class=rowtabhead colspan=2 align=center>$hide</td></tr>\n");                              
	print("<tr><td class=row1 colspan=2 align=center>There are currently no uploader applications</td></tr>\n");
    print("<tr><td class=rowend colspan=2 align=center></td></tr>\n");  
	print("</table>");
  } else {
      $res = mysql_query("SELECT uploadapp.*, users.id AS uid, users.username, users.class, users.added, users.uploaded, users.downloaded FROM uploadapp INNER JOIN users on uploadapp.userid = users.id $where1 $limit") or sqlerr(__FILE__, __LINE__);
    while ($arr = mysql_fetch_assoc($res))
    {
      if ($arr["status"] == "accepted")
        $status = "<font class=success>Accepted</font>";
      elseif ($arr["status"] == "rejected")
        $status = "<font class=error>Rejected</font>";
      else
        $status = "<font class=complete>Pending</font>";
      $membertime = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]));
      $elapsed = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["applied"]));
        if ($arr["downloaded"] > 0) {
    $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
  } elseif ($arr["uploaded"] > 0)
    $ratio = "Inf.";
  else
    $ratio = "---";
	print("<table class=table_table width=100% border=0 cellspacing=0 cellpadding=5><tr><td>\n");
	echo $pagertop;
	print("<table width=95% class=tablebg cellspacing=0 cellpadding=5 align=center>\n");
    print("<tr><td class=rowtabhead colspan=2 align=center>$hide</td></tr>\n");  
	print("<tr><td class=row1 align=right>Applied</td><td class=row2>$elapsed ago</td><tr>\n");
	print("<tr><td class=row1 align=right>Application</td><td class=row2><a href=?action=viewapp&id=$arr[id]>View application</a></td></tr>\n");
	print("<tr><td class=row1 align=right>Username</td><td class=row2><a href=account-details.php?id=$arr[uid]>$arr[username]</a></td></tr>\n");
	print("<tr><td class=row1 align=right>Member for</td><td class=row2>$membertime</td></tr>\n");
	print("<tr><td class=row1 align=right>Class</td><td class=row2>".get_user_class_name($arr["class"])."</td></tr>\n");
	print("<tr><td class=row1 align=right>Uploaded</td><td class=row2>".mksize($arr["uploaded"])."</td></tr>\n");
    print("<tr><td class=row1 align=right>Downloaded</td><td class=row2>".mksize($arr["downloaded"])."</td></tr>\n");
	print("<tr><td class=row1 align=right>Ratio</td><td class=row2>$ratio</td></tr>\n");
	print("<tr><td class=row1 align=right>Status</td><td class=row2>$status</td></tr>\n");
	print("<tr><td class=row1 align=right>Delete</td><form method=post action=?action=takeappdelete><td class=row2><input type=\"checkbox\" name=\"deleteapp[]\" value=\"" . $arr[id] . "\" /></td></tr>\n");
	}
	print("<tr><td class=rowend colspan=2 align=center><input type=submit value=Delete></td></tr>\n");
    print("</table>\n");  
	print("</form>");
	echo $pagerbottom;
	print("</td></tr></table>\n");
  }
  end_frame();
  stdfoot();
}

// View application

if ($action == "viewapp") {

  $id = $_GET["id"];
  $res = mysql_query("SELECT uploadapp.*, users.id AS uid, users.username, users.class, users.added, users.uploaded, users.downloaded FROM uploadapp INNER JOIN users on uploadapp.userid = users.id WHERE uploadapp.id=$id") or sqlerr(__FILE__, __LINE__);
  $arr = mysql_fetch_assoc($res);
  $membertime = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]));
  $elapsed = get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["applied"]));
          if ($arr["downloaded"] > 0) {
    $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
  } elseif ($arr["uploaded"] > 0)
    $ratio = "Inf.";
  else
    $ratio = "---";
  if($ratio > 10)
  $ratio = "10+";
  
  stdhead("Uploader applications");
  begin_frame("Uploader applications");
  print("<table class=tablebg width=95% cellspacing=0 cellpadding=5 align=center>");
  print("<tr><td  class=rowtabhead colspan=2 align=center>applications details</td></tr>");  
  print("<tr><td class=row1>My username is</td><td class=row2><a href=account-details.php?id=$arr[uid]>$arr[username]</a></td></tr>");
  print("<tr><td class=row1>I have joined at</td><td class=row2>$arr[added] ($membertime ago)</td></tr>");
  print("<tr><td class=row1>My upload amount is</td><td class=row2>".mksize($arr["uploaded"])."</td></tr>");
  print("<tr><td class=row1>My download amount is</td><td class=row2>".mksize($arr["downloaded"])."</td></tr>");
  print("<tr><td class=row1>My ratio is </td><td class=row2><font color=".get_ratio_color($ratio).">$ratio</font></td></tr>");
  print("<tr><td class=row1>I am connectable</td><td class=row2>$arr[connectable]</td></tr>");
  print("<tr><td class=row1>My current userclass is</td><td class=row2>".get_user_class_name($arr["class"])."</td></tr>");
  print("<tr><td class=row1>I have applied at</td><td class=row2>$arr[applied] ($elapsed ago)</td></tr>"); 
  print("<tr><td class=row1>My upload speed is</td><td class=row2>$arr[speed]</td></tr>");
  print("<tr><td class=row1>What I have to offer</td><td class=row2>$arr[offer]</td></tr>");
  print("<tr><td class=row1>Why I should be promoted</td><td class=row2>$arr[reason]</td></tr>");
  print("<tr><td class=row1>I am uploader at other sites</td><td class=row2>$arr[sites]</td></tr>");
  if ($arr["sitenames"] != "")
	print("<tr><td class=row1>Those sites are</td><td class=row2>$arr[sitenames]</td></tr>");
  print("<tr><td class=row1>I have scene access</td><td class=row2>$arr[scene]</td></tr>");
  print("<tr><td  class=row1 colspan=2>I know how to create, upload and seed torrents: <b>$arr[creating]</b><br>I understand that I have to keep seeding my torrents until there are at least two other seeders: <b>$arr[seeding]</b></td></tr>");
  if ($arr["status"] == "pending")
	print("<tr><td  class=row1 align=center colspan=2><form method=post action=?action=acceptapp><input name=id type=hidden value=$arr[id]><b>Note: (optional)</b><br><input type=text name=note size=40> <input type=submit value=Accept class=lbutton></form><br><form method=post action=?action=rejectapp><input name=id type=hidden value=$arr[id]><b>Reason: (optional)</b><br><input type=text name=reason size=40> <input type=submit value=Reject class=lbutton></form></td></tr>");
  else
  print("<tr><td  class=row1 colspan=2 align=center>Application ".($arr["status"] == "accepted" ? "accepted" : "rejected")." by <b>$arr[moderator]</b><br>Comment: $arr[comment]</td></tr>");
  print("<tr><td  class=rowend colspan=2 align=center><a href=uploadapps.php>Return to uploader applications page</a></td></tr>");  
  print("</table>");
  end_frame();
  stdfoot();
}

// Accept application

if ($action == "acceptapp") {

  $id = 0 + $_POST["id"];
  if (!is_valid_id($id))
  	show_error_msg("Error", "It appears that there is no uploader application with that ID.");

  $res = mysql_query("SELECT uploadapp.id, users.id AS uid FROM uploadapp INNER JOIN users on uploadapp.userid = users.id WHERE uploadapp.id=$id") or sqlerr(__FILE__, __LINE__);
  $arr = mysql_fetch_assoc($res);

  $note = $_POST["note"];

  $msg = sqlesc("Congratulations, your uploader application has been accepted! You have been promoted to Uploader and you are now able to upload torrents. Please make sure you have read the <a href=rules.php> guidlines on uploading</a> before you do.\n\nNote: $note");
  $dt = sqlesc(get_date_time());
  mysql_query("UPDATE uploadapp SET status = 'accepted', comment = ".sqlesc($note).", moderator = ".sqlesc($CURUSER["username"])." WHERE id=$id") or sqlerr(__FILE__, __LINE__);
  mysql_query("UPDATE users SET class = 4 WHERE id=$arr[uid]") or sqlerr(__FILE__, __LINE__);
  mysql_query("INSERT INTO messages(sender, receiver, added, msg, poster) VALUES(0, $arr[uid], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
  show_success_msg("Application accepted", "The application was succesfully accepted. The user has been promoted and has been sent a PM notification. Click <a href=uploadapps.php>here</a> to return to the upload applications page.");
}

// Reject application

if ($action == "rejectapp") {

  $id = 0 + $_POST["id"];
  if (!is_valid_id($id))
  	show_error_msg("Error", "It appears that there is no uploader application with that ID.");

  $res = mysql_query("SELECT uploadapp.id, users.id AS uid FROM uploadapp INNER JOIN users on uploadapp.userid = users.id WHERE uploadapp.id=$id") or sqlerr(__FILE__, __LINE__);
  $arr = mysql_fetch_assoc($res);

  $reason = $_POST["reason"];

  $msg = sqlesc("Sorry, your uploader application has been reject. It appears that you are not qualified enough to become uploader.\n\nReason: $reason");
  $dt = sqlesc(get_date_time());
  mysql_query("UPDATE uploadapp SET status = 'rejected', comment = ".sqlesc($reason).", moderator = ".sqlesc($CURUSER["username"])." WHERE id=$id") or sqlerr(__FILE__, __LINE__);
  mysql_query("INSERT INTO messages(sender, receiver, added, msg, poster) VALUES(0, $arr[uid], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
  show_error_msg("Application rejected", "The application was succesfully rejected. The user has been sent a PM notification. Click <a href=uploadapps.php>here</a> to return to the upload applications page.");
}

// Delete applications

if ($action == "takeappdelete") {

  $res = mysql_query("SELECT id FROM uploadapp WHERE id IN (" . implode(", ", $_POST["deleteapp"]) . ")") or sqlerr(__FILE__, __LINE__);
  while ($arr = mysql_fetch_assoc($res))
	mysql_query("DELETE FROM uploadapp WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__);
  show_success_msg("Deleted", "The upload applications were succesfully deleted. Click <a href=uploadapps.php>here</a> to return to the upload applications page.");
}

?>
Return current item: H-tracker