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

loggedinonly();

if (!$CURUSER || $CURUSER["class"] < 6){
show_error_msg(""._ERROR_."",""._ACCESS_DEN_."",1);   
}

function navmenu(){
global $site_config;

//Get Last Cleanup
$res = mysql_query("SELECT last_time FROM tasks WHERE task = 'cleanup'");
$row = mysql_fetch_array($res);
if (!$row){
        $lastclean="".NDONE."";   
}else{
    $row[0]=gmtime()-$row[0]; $days=intval($row[0] / 86400);$row[0]-=$days*86400;
    $hours=intval($row[0] / 3600); $row[0]-=$hours*3600; $mins=intval($row[0] / 60);
    $secs=$row[0]-($mins*60);
    $lastclean = "$days days, $hours hrs, $mins minutes, $secs seconds ago.";
}
begin_frame("".ADMINISTRATION."");
      print "".LAST_CLEAN.": ".$lastclean." [<a href=modocp.php?action=forceclean>".F_CLEAN."</a>]<BR><BR>"; 

    $pending = get_row_count("users", "WHERE status='pending'");
    echo "<CENTER><b>".USERS_VALID.":</b> <a href='modocp.php?action=confirmreg'>($pending)</a></CENTER><BR>";
$title = "".ADMINISTRATION."";
$hide = "<a href=\"javascript: klappe_block('b".$title."')\"><img border=\"0\" src=\"".$site_config["SITEURL"]."/images/plus.gif\" id=\"picb".$title."\" alt=\"".SHOW."/".HIDE."\">"; 
?>
<FIELDSET class=tablebg><LEGEND><?=$title?>&nbsp;&nbsp;<?=$hide?></LEGEND>
 <?
echo "<div id=\"kb".$title."\" style=\"display: none;\">\n";
?>
<table width="90%" cellspacing="0" cellpadding="0" align=center>

<TR>
<td class="admin"><a href=modocp.php?action=cheats><img src="images/admin/cheats.png" border=0><br>Detect Possible Cheaters</a><BR></td>
<td class="admin"><a href=modocp.php?action=peers><img src="images/admin/peers.png" border=0><br>Peers</a><BR></td>
<td class="admin"><a href=modocp.php?action=warned><img src="images/admin/warnedaccounts.png" border=0><br>Warned Users</a><BR></td>
<td class="admin"><a href=modocp.php?action=whoswhere><img src="images/admin/ipchecker.png" border=0><br>Who's Where</a><BR></td>
<td class="admin"><a href=modocp.php?action=torrentmanage><img src="images/admin/torrents.png" border=0><br>Torrents</a><BR></td>

</tr>

<tr><td colspan=5>&nbsp;</td></tr>
<td class="admin"><a href=modocp.php?action=newarc><img src="images/admin/news.png"  border=0><br>News Archive</a><BR></td>
<td class="admin"><a href=modocp.php?action=Server><img src="images/admin/server.png" border=0><br>Server Load</a><BR></td>
<td class="admin"><a href=uploadapps.php><img src="images/admin/upload.png" border=0><br>Uploader Applications</a><BR></td>
<td class="admin"><a href=modocp.php?action=censor><img src="images/admin/censor.png" border=0><br>Word Censor</a><BR></td>
<td class="admin"><a href=modocp.php?action=masspm><img src="images/admin/masspm.png" border=0><br>Mass PM</a><BR></td> 
</tr>
<tr><td colspan=5>&nbsp;</td></tr>
<td class="admin"><a href=modocp.php?action=emailbans><img src="images/admin/mail.png" border=0><br>Email Bans</a><BR></td>
<td class="admin"><a href=modocp.php?action=adduser><img src="images/admin/adduser.png" border=0><br>Add User</a><BR></td>
<td class="admin"><a href=modocp.php?action=confirmreg><img src="images/admin/confirm.png" border=0><br>Unactivated <br>Accounts</a><BR></td>
<td class="admin"><a href=modocp.php?action=clearshoutbox><img src="images/admin/clear.png" border=0><br>Clear Shoutbox<br></a><BR></td>
<td class="admin"><a href=modocp.php?action=reports&do=view><img src="images/admin/report.png" border=0><br>Reports</a><BR></td>
</tr>
<tr><td colspan=5>&nbsp;</td></tr>
<td class="admin"><a href=modocp.php?action=freetorrents><img src="images/admin/free.png" border=0><br>Free Leech Torrents</a><BR></td>
<td class="admin"><a href=modocp.php?action=lastcomm><img src="images/admin/comments.png" border=0><br>Latest Comments</a><BR></td>
<td class="admin"><a href=staffbox.php><img src="images/admin/masspm.png" border=0><br>Staff box</a><BR></td>                                                                                                                                                         
</table>
<?
echo"</div>";
?>

</FIELDSET>
<?
    end_frame();
}


if (!$action){
    stdhead(" Super Mod CP");
    navmenu();
    stdfoot();
}

if ($action=="whoswhere"){
    stdhead("Where are members");
    navmenu();

    begin_frame("Last 100 page views");
    print("<CENTER><table class=table_table width=80%><tr><td class=table_head>User</td><td class=table_head>Page</td><td class=table_head>Accessed</td></tr>");
    $res = mysql_query("SELECT id, username, page, last_access FROM users ORDER BY last_access DESC LIMIT 100");
    while ($arr = mysql_fetch_assoc($res))
    print("<tr><td class=table_col1><a href=account-details.php?id=$arr[id]><b>$arr[username]</b></a></td><td class=table_col2>".htmlspecialchars($arr["page"])."</td><td  class=table_col1>$arr[last_access]</td></tr>");
    print("</table></CENTER>");
    end_frame();

    stdfoot();
}

if ($action=="peers"){
    $site_config['RIGHTNAV'] = false; // Right Column Enable/Disable
    stdhead("Peers List");
    navmenu();

    begin_frame("Peers List");

    $count1 = number_format(get_row_count("peers"));

    print("<center>We have $count1 peers</center><br>");

    $res4 = mysql_query("SELECT COUNT(*) FROM peers $limit") or die(mysql_error());
    $row4 = mysql_fetch_array($res4);

    $count = $row4[0];
    $peersperpage = 50;

    list($pagertop, $pagerbottom, $limit) = pager($peersperpage, $count, "modocp.php?action=peers&");

    print("$pagertop");

    $sql = "SELECT * FROM peers ORDER BY started DESC $limit";
    $result = mysql_query($sql);

    if( mysql_num_rows($result) != 0 ) {
        print'<CENTER><table width=90% cellspacing=0 cellpadding=3 class=table_table>';
        print'<tr>';
        print'<td class=table_head align=center>User</td>';
        print'<td class=table_head align=center>Torrent</td>';
        print'<td class=table_head align=center>IP</td>';
        print'<td class=table_head align=center>Port</td>';?>
<?
            print("<td class=\"table_head\"><div align=center><img src=\"/images/users/uploaded.gif\" border=\"0\" alt=\"Uploaded\"></div></td>");
            print("<td class=\"table_head\"><div align=center><img src=\"/images/users/downloaded.gif\" border=\"0\" alt=\"Downloaded\"></div></td>");?>
<?
        print'<td class=table_head align=center>Client</td>';
        print'<td class=table_head align=center>Conn.</td>';
        print'<td class=table_head align=center>Seeding</td>';
        print'<td class=table_head align=center>Started</td>';
        print'<td class=table_head align=center>Last<br>Action</td>';
        print'</tr>';

        while($row = mysql_fetch_assoc($result)) {
            if ($site_config['MEMBERSONLY']) {
                $sql1 = "SELECT id, username FROM users WHERE id = $row[userid]";
                $result1 = mysql_query($sql1);
                $row1 = mysql_fetch_assoc($result1);
            }

            if ($row1['username'])
                print'<tr><td class=table_col1><a href="account-details.php?id=' . $row['userid'] . '">' . $row1['username'] . '</a></td>';
            else
                print'<tr><td class=table_col1>'.$row[ip].'</td>';

            $sql2 = "SELECT id, name FROM torrents WHERE id = $row[torrent]";
            $result2 = mysql_query($sql2);

            while ($row2 = mysql_fetch_assoc($result2)) {

                $smallname =substr(htmlspecialchars($row2["name"]) , 0, 30);
                    if ($smallname != htmlspecialchars($row2["name"])) {
                        $smallname .= '...';
                    }

                print'<td class=table_col1><a href="torrents-details.php?id=' . $row['torrent'] . '">' . $smallname . '</td>';
                print'<td align=center class=table_col1>' . $row['ip'] . '</td>';
                print'<td align=center class=table_col1>' . $row['port'] . '</td>';

                if ($row['uploaded'] < $row['downloaded'])
                    print'<td align=center class=table_col1><font class=leechers>' . mksize($row['uploaded']) . '</font></td>';
                else
                    if ($row['uploaded'] == '0')
                        print'<td align=center class=table_col1>' . mksize($row['uploaded']) . '</td>';
                    else
                        print'<td align=center class=table_col1><font class=seeders>' . mksize($row['uploaded']) . '</font></td>';
                print'<td align=center class=table_col1>' . mksize($row['downloaded']) . '</td>';
                print'<td align=center class=table_col1>' . $row['client'] . '</td>';
                if ($row['connectable'] == 'yes')
                    print'<td align=center class=table_col1><font class=seeders>' . $row['connectable'] . '</font></td>';
                else
                    print'<td align=center class=table_col1><font class=leechers>' . $row['connectable'] . '</font></td>';
                if ($row['seeder'] == 'yes')
                    print'<td align=center class=table_col1><font class=seeders>' . $row['seeder'] . '</font></td>';
                else
                    print'<td align=center class=table_col1><font color=red>' . $row['seeder'] . '</font></td>';
                print'<td align=center class=table_col1>' . $row['started'] . '</td>';
                print'<td align=center class=table_col1>' . $row['last_action'] . '</td>';
                print'</tr>';
            }
        }
        print'</table>';
        print("$pagerbottom</CENTER>");
    }else{
        print'<B><CENTER>No Peers</CENTER></B><BR>';
    }
    end_frame();

    stdfoot();
}

if ($action=="forceclean"){
    $now = gmtime();
    mysql_query("UPDATE tasks SET last_time=$now WHERE task='cleanup'");
    require_once("backend/cleanup.php");
    do_cleanup();
    show_success_msg("Complete","Force Clean Completed",1);
    die;
}

if ($action=="torrentmanage"){
    stdhead("Torrent Management");
    navmenu();

    $search = trim($search);

    if ($search != '' ){
        $where = "WHERE name LIKE " . sqlesc("%$search%") . "";
    }

    
    $res2 = mysql_query("SELECT COUNT(*) FROM torrents $where");
    $row = mysql_fetch_array($res2);
    $count = $row[0];

    $perpage = 50;

    list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "modocp.php?action=torrentmanage&");

    begin_frame("Torrent Management");

    print("<CENTER><form method=get action=?>\n");
    print("<input type=hidden name=action value=torrentmanage>\n");
    print("" . SEARCH . ": <input type=text size=30 name=search>\n");
    print("<input type=submit value='Search'>\n");
    print("</form></CENTER>\n");

    echo $pagertop;
    ?>
    <CENTER><table align=center cellpadding="0" cellspacing="0" class="table_table" width="100%" border="1">
    <tr>
    <td class=table_head align=center>Name</td>
    <td class=table_head align=center>Visible</td>
    <td class=table_head align=center>Banned</td>
    <td class=table_head align=center>Seeders</td>
    <td class=table_head align=center>Leechers</td>
    <td class=table_head align=center>External?</td>
    <td class=table_head align=center>Edit?</td>
    </tr>
    <?
    $rqq = "SELECT id, name, seeders, leechers, visible, banned, external FROM torrents $where ORDER BY name $limit";
    $resqq = mysql_query($rqq);

    while ($row = mysql_fetch_array($resqq)){
        extract ($row);

        $char1 = 35; //cut name length 
        $smallname = CutName(htmlspecialchars($row["name"]), $char1);

        echo "<tr><td class=table_col1><a href=\"torrents-details.php?id=$row[id]\">" . $smallname . "</a></td><td class=table_col2>$row[visible]</td><td class=table_col1>$row[banned]</td><td class=table_col2>$row[seeders]</td><td class=table_col1>$row[leechers]</td><td class=table_col2>$row[external]</td><td class=table_col1><a href=\"torrents-edit.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;id=" . $row["id"] . "\"><font size=1 face=Verdana>EDIT</a></td></tr>\n";
    }

    echo "</table></CENTER>\n";

    print($pagerbottom);

    end_frame();
    stdfoot();
}


if ($action == "cheats") {
    stdhead("Possible Cheater Detection");
    navmenu();

    if ($daysago && $megabts){

        $timeago = 84600 * $daysago; //last 7 days
        $bytesover = 1048576 * $megabts; //over 500MB Upped

        $result = mysql_query("select * FROM users WHERE UNIX_TIMESTAMP('" . get_date_time() . "') - UNIX_TIMESTAMP(added) < '$timeago' AND status='confirmed' AND uploaded > '$bytesover' ORDER BY uploaded DESC "); 
        $num = mysql_num_rows($result); // how many uploaders

        begin_frame("Possible Cheater Detection");
        echo "<p>" . $num . " Users with found over last ".$daysago." days with more than ".$megabts." MB (".$bytesover.") Bytes Uploaded.</p>";

        $zerofix = $num - 1; // remove one row because mysql starts at zero

        if ($num > 0){
        echo "<table align=center class=table_table>";
        echo "<tr>";
         echo "<td class=table_head>No.</td>";
         echo "<td class=table_head>" . USERNAME . "</td>";
         echo "<td class=table_head>" . UPLOADED . "</td>";
         echo "<td class=table_head>" . DOWNLOADED . "</td>";
         echo "<td class=table_head>" . RATIO . "</td>";
         echo "<td class=table_head>" . TORRENTS_POSTED . "</td>";
         echo "<td class=table_head>AVG Daily Upload</td>";
         echo "<td class=table_head>" . ACCOUNT_SEND_MSG . "</td>";
         echo "<td class=table_head>Joined</td>";
        echo "</tr>";

        for ($i = 0; $i <= $zerofix; $i++) {
             $id = mysql_result($result, $i, "id");
             $username = mysql_result($result, $i, "username");
             $added = mysql_result($result, $i, "added");
             $uploaded = mysql_result($result, $i, "uploaded");
             $downloaded = mysql_result($result, $i, "downloaded");
             $donated = mysql_result($result, $i, "donated");
             $warned = mysql_result($result, $i, "warned");
             $joindate = "" . get_elapsed_time(sql_timestamp_to_unix_timestamp($added)) . " ago";
             $upperquery = "SELECT added FROM torrents WHERE owner = $id";
             $upperresult = mysql_query($upperquery);
             $seconds = mkprettytime(utc_to_tz_time() - utc_to_tz_time($added));
             $days = explode("d ", $seconds);

             if(sizeof($days) > 1) {
                 $dayUpload  = $uploaded / $days[0];
                 $dayDownload = $downloaded / $days[0];
            }
         
          $torrentinfo = mysql_fetch_array($upperresult);
         
          $numtorrents = mysql_num_rows($upperresult);
           
          if ($downloaded > 0){
           $ratio = $uploaded / $downloaded;
           $ratio = number_format($ratio, 3);
           $color = get_ratio_color($ratio);
           if ($color)
           $ratio = "<font color=$color>$ratio</font>";
           }
          else
           if ($uploaded > 0)
            $ratio = "Inf.";
           else
            $ratio = "---";
          
         
         $counter = $i + 1;
         
         echo "<tr>";
          echo "<td align=center class=table_col1>$counter.</td>";
          echo "<td class=table_col2><a href=account-details.php?id=$id>$username</a></td>";
          echo "<td class=table_col1>" . mksize($uploaded). "</td>";
          echo "<td class=table_col2>" . mksize($downloaded) . "</td>";
          echo "<td class=table_col1>$ratio</td>";
          if ($numtorrents == 0) echo "<td class=table_col2><font color=red>$numtorrents torrents</font></td>";
          else echo "<td class=table_col2>$numtorrents torrents</td>";

          echo "<td class=table_col1>" . mksize($dayUpload) . "</td>";

          echo "<td align=center class=table_col2><a href=mailbox.php?compose&id=$id>PM</a></td>";
          echo "<td class=table_col1>" . $joindate . "</td>";
         echo "</tr>";

         
         }
        echo "</table><br><br>";
        end_frame();
        }

        if ($num == 0)
        {
        end_frame();
        }

    }else{
    begin_frame("Possible Cheater Detection");?>
    <form action='modocp.php?action=cheats' method='post'>
       <table align=center class=table_table width='80%'>
        <tr><td width='140' class=table_col1>Number of days joined: </td><td class=table_col2><input type='text' size='4' maxlength='4' name='daysago'> Days</td></tr>
        <tr><td class=table_col1>MB Uploaded: </td><td class=table_col2><input type='text' size='6' maxlength='6' name='megabts'> MB</td></tr>
        <tr><td align=right><input type='submit' value='Submit'></td></tr></table>
        </form><?
    end_frame();
    }
    stdfoot();
}

if ($action == "warned") {
    stdhead("Warned Users Management");
    navmenu();

    
    $res2 = mysql_query("SELECT COUNT(*) FROM users WHERE warned='yes'");
    $row = mysql_fetch_array($res2);
    $count = $row[0];

    $perpage = 50;

    list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "modocp.php?action=warned&");

    begin_frame("Warned Users Management");

    echo $pagertop;
    ?>
    <CENTER><table align=center cellpadding="0" cellspacing="0" class="table_table" width="100%" border="1">
    <tr>
    <td class=table_head align=center>Username</td>
    <td class=table_head align=center>Added</td>
    <td class=table_head align=center>Last Visit</td>
    <td class=table_head align=center>Uploaded</td>
    <td class=table_head align=center>Downloaded</td>
    <td class=table_head align=center>Edit?</td>
    </tr>
    <?
    
    $rqq = "SELECT id, username, last_access, added, uploaded, downloaded FROM users WHERE warned='yes' ORDER BY username $limit";
    $resqq = mysql_query($rqq);

    while ($row = mysql_fetch_array($resqq)){
        extract ($row);

        echo "<tr><td class=table_col1><a href=account-details.php?id=$row[id]>$row[username]</a></td><td class=table_col2>".utc_to_tz($row['added'])."</td><td class=table_col1>$row[last_access]</td><td class=table_col2>".mksize($row["uploaded"])."</td><td class=table_col1>".mksize($row["downloaded"])."</td><td class=table_col2><a href=account-details.php?id=$row[id]>EDIT</a></td></tr>\n";
    }

    echo "</table></CENTER>\n";

    print($pagerbottom);

    end_frame();
    stdfoot();
}
      #======================================================================#
# Add Users
#======================================================================#
if ($action == "adduser") {
function validusername($username)
{
if ($username == "")
return false;

// The following characters are allowed in user names
$allowedchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

for ($i = 0; $i < strlen($username); ++$i)
if (strpos($allowedchars, $username[$i]) === false)
return false;

return true;
}
      
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if ($_POST["username"] == "" || $_POST["password"] == "" || $_POST["email"] == "" || $_POST["class"] == "" || $_POST["seedbonus"] == "" || $_POST["modcomment"] == "")
show_error_msg("Error", "Missing form data.");
if (!validusername($_POST["username"]))
show_error_msg("Error", "Invalid username.");
if ($_POST["password"] != $_POST["password2"])
show_error_msg("Error", "Passwords mismatch.");
if (!validemail($_POST['email']))
show_error_msg("Error", "Not valid email");
$username = sqlesc($_POST["username"]);
$password = $_POST["password"];
$email = $_POST["email"];
$res = mysql_query("SELECT COUNT(*) FROM users WHERE email='$email'") or die(mysql_error());
$arr = mysql_fetch_row($res);
if ($arr[0] != 0)
show_error_msg("Error", "The e-mail address is already in use.");
$secret = mksecret();
$passhash = sqlesc(md5($password));
$secret = sqlesc($secret);
$added = sqlesc(get_date_time());
$class = 0+$_POST["class"];
$seedbonus = 0+$_POST["seedbonus"];
$modcomment = $_POST["modcomment"]; 
mysql_query("INSERT INTO users (added, last_access, secret, username, password, status, email, class, seedbonus, modcomment) VALUES($added, $added, $secret, $username, $passhash, 'confirmed', ".sqlesc($email).", $class, $seedbonus, ".sqlesc($modcomment).")") or die(mysql_error());
$res = mysql_query("SELECT id FROM users WHERE username=$username");
$arr = mysql_fetch_row($res);
if (!$arr)
show_error_msg("Error", "Unable to create the account. The user name is possibly already taken.");
header("Location: /account-details.php?id=$arr[0]");
die;
}
        
stdhead("Add user");
navmenu();
begin_frame("Add user");
?>
<form method=post action=modocp.php?action=adduser>
<table width='90%' class=table_table align=center cellspacing=0 cellpadding=5>
<tr><td class=ttable_col1>Username</td><td class=ttable_col2><input type=text name=username size=40></td></tr>
<tr><td class=ttable_col1>Password</td><td class=ttable_col2><input type=password name=password size=40></td></tr>
<tr><td class=ttable_col1>Re-type password</td><td class=ttable_col2><input type=password name=password2 size=40></td></tr>
<tr><td class=ttable_col1>E-mail</td><td class=ttable_col2><input type=text name=email size=40></td></tr>
<tr><td class=ttable_col1>Bonus</td><td class=ttable_col2><input type=text size=5 name=seedbonus value="0.0"></td></tr>
<?php
print("<tr><td class=ttable_col1>Class</td><td align=left class=ttable_col2><select name=class>\n");
        $maxclass = $CURUSER["class"];
        for ($i = 1; $i < $maxclass; ++$i)
        print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "\n");
        print("</select></td></tr>\n");
$modcomment = gmdate("Y-m-d")." - User added by ".$CURUSER['username'].".\n".$modcomment;                                                                                     
?>
<tr><td class=ttable_col1>Comment</td><td class=ttable_col2><input type=text size=40 name=modcomment value="<?php echo $modcomment?>" READONLY></td></tr>
<tr><td colspan=2 align=center><input type=submit value="Okay" class=lbutton></td></tr>
</table>
</form>
<?
end_frame();
stdfoot();
}
#======================================================================#
# END Add Users
#======================================================================#

#================#
# Archive news
#================#
if ($action == "newarc") {
    stdhead("News Archive");
    navmenu();
begin_frame("News Archive");

$query = 'SELECT news.id, news.title, news.userid, news.added, news.body, users.username FROM news INNER JOIN users ON users.id = news.userid ORDER BY added DESC';
$resu = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($resu))
{
$numcomm = number_format(get_row_count("comments", "WHERE news='".$row['id']."'"));
begin_frame("" . $row['title'] . "");
print("<I>Posted By " . $row['username'] . "</i> On " . $row['added'] . "\n");
echo"<BR>" . format_comment($row["body"],0) ." <BR><BR>Comments (<a href=comments.php?type=news&id=".$row['id'].">".$numcomm."</a>)";
end_frame();
}
end_frame();
stdfoot();
}

#===============#
#end archive
#===============#

#========================#
# top 10
#========================#
if ($action == "top") {
    stdhead("Top 10");
    navmenu();
/*//DONATOR TABLE FUNCTION
function donortable($res, $frame_caption) {
print ("<div align=left><B>$frame_caption </B><BR>");
if (mysql_num_rows($res) > 0)
{
print("<table border=1 cellspacing=0 cellpadding=2 class=table_table>\n");
$num = 0;

while ($a = mysql_fetch_assoc($res)) {
++$num;
$dis = $a["donated"];
if ($dis == "0")
break;
if ($dis == $last)
$rank = " ";
else
$rank = $num;
if ($rank && $num > 10)
break;
if ($menu != "1") {
echo "<tr>"
."<td class=table_head>" . ACCOUNT_RANK . "</td>"
."<td class=table_head>" . ACCOUNT_USER . "</td>"
."<td class=table_head>" . DONATED . "</td>"
."</tr>";
$menu = 1;
}
print("<tr><td class=table_col1>$num</td><td class=table_col2 align=left><a href=account-details.php?id=$a[id]><b>$a[username]" .
"</b></a></td><td class=table_col1 align=right>$$dis</td></tr>");
$last = $dis;
}
echo "</table></div>";
}else{
echo "<font color=red>" . NOTHING_TO_SHOW . "</font></div>";
}
}*/


function usertable($res, $frame_caption) {
print ("<div align=left><B>$frame_caption </B><BR>");
if (mysql_num_rows($res) > 0)
{
print("<table border=1 cellspacing=0 cellpadding=2 class=table_table>\n");
$num = 0;
while ($a = mysql_fetch_assoc($res)) {
++$num;
if ($a["uploaded"] == "0")
break;
if ($a["downloaded"]) {
$ratio = $a["uploaded"] / $a["downloaded"];
$color = get_ratio_color($ratio);
$ratio = number_format($ratio, 2);
if ($color)
$ratio = "<font color=$color>$ratio</font>";
}
else
$ratio = "Inf.";
if ($menu != "1") {
echo "<tr>"
."<td class=table_head>" . ACCOUNT_RANK . "</td>"
."<td class=table_head align=left>" . ACCOUNT_USER . "</td>"
."<td class=table_head>" . UPLOADED . "</td>"
."<td class=table_head>" . DOWNLOADED . "</td>"
."<td class=table_head align=right>" . RATIO . "</td>"
."</tr>";
$menu = 1;
}
print("<tr><td class=table_col1>$num</td><td class=table_col2 align=left><a href=account-details.php?id=" . $a["id"] . "><b>" . $a["username"] .
"</b></a></td><td class=table_col1 align=right>" . mksize($a["uploaded"]) .
"</td><td class=table_col2 align=right>" . mksize($a["downloaded"]) .
"</td><td class=table_col1 align=right>" . $ratio . "</td></tr>");
}
echo "</table></div>";
}else{
echo "<font color=red>" . NOTHING_TO_SHOW . "</font></div>";
}
}

function _torrenttable($res, $frame_caption) {
print ("<div align=left><B>$frame_caption </B><BR>");
if (mysql_num_rows($res) > 0)
{
print("<table border=1 cellspacing=0 cellpadding=2 class=table_table>\n");
$num = 0;
while ($a = mysql_fetch_assoc($res)) {
++$num;
if ($a["leechers"])
{
$r = $a["seeders"] / $a["leechers"];
$ratio = "<font color=" . get_ratio_color($r) . ">" . number_format($r, 2) . "</font>";
}
else
$ratio = "Inf.";
if ($menu != "1") {
echo "<tr>"
."<td class=ttable_head>" . ACCOUNT_RANK . "</td>"
."<td class=ttable_head align=left>" . NAME . "</td>"
."<td class=ttable_head align=right>" . COMPLETED . "</td>"
."<td class=ttable_head align=right>" . SEEDS . "</td>"
."<td class=ttable_head align=right>" . LEECH . "</td>"
."<td class=ttable_head align=right>" . PEERS . "</td>"
."<td class=ttable_head align=right>" . RATIO . "</td>"
."</tr>";
$menu = 1;
}
print("<tr><td class=ttable_col1>$num</td><td class=ttable_col2 align=left><a href=torrents-details.php?id=" . $a["id"] . "&hit=1><b>" .
$a["name"] . "</b></a></td><td class=ttable_col1 align=center>" . number_format($a["times_completed"]) .
"</td><td class=ttable_col2 align=center>" . number_format($a["seeders"]) .
"</td><td class=ttable_col1 align=center>" . number_format($a["leechers"]) .
"</td><td class=ttable_col2 align=center>" . ($a["leechers"] + $a["seeders"]) .
"</td><td class=ttable_col1 align=right>$ratio</td>\n");
}
echo "</table></div>";
}else{
echo "<font color=red>" . NOTHING_TO_SHOW . "</font></div>";
}
}

function countriestable($res, $frame_caption) {
print ("<div align=left><B>$frame_caption </B><BR>");
if (mysql_num_rows($res) > 0)
{
print("<table border=1 cellspacing=0 cellpadding=2 class=table_table>\n");

echo "<tr>";
echo "<td class=table_head>" . ACCOUNT_RANK . "</td>";
echo "<td class=table_head align=left>" . COUNTRY . "</td>";
echo "<td class=table_head align=right>" . USERS . "</td>";
echo "</tr>";

$num = 0;
while ($a = mysql_fetch_assoc($res))
{
++$num;
print("<tr><td class=table_col1>$num</td><td class=table_col2 align=left><img align=center src=images/flag/$a[flagpic]>&nbsp;<b>$a[name]</b></td><td align=right class=table_col1>$a[num]</td></tr>\n");
}
echo "</table></div>";
}else{
echo "<font color=red>" . NOTHING_TO_SHOW . "</font></div>";
}
}
function postertable($res, $frame_caption) {
print ("<div align=left><B>$frame_caption </B><BR>");
if (mysql_num_rows($res) > 0)
{
print("<table border=1 cellspacing=0 cellpadding=2 class=table_table>\n");

echo "<tr>";
echo "<td class=table_head width=80>" . ACCOUNT_RANK . "</td>";
echo "<td class=table_head align=left>" . ACCOUNT_USER . "</td>";
echo "<td class=table_head align=left width=100>" . TORRENTS_POSTED . "</td>";
echo "</tr>";

$num = 0;
while ($a = mysql_fetch_assoc($res))
{
++$num;
print("<tr><td class=table_col1>$num</td><td class=table_col2 align=left><a href=account-details.php?id=$a[id]><b>$a[username]</b></td><td align=right class=table_col1>$a[num]</td></tr>\n");
}
echo "</table></div>";
}else{
echo "<font color=red>" . NOTHING_TO_SHOW . "</font></div>";
}
}

//main stats here
$a = @mysql_fetch_assoc(@mysql_query("SELECT id,username FROM users WHERE status='confirmed' ORDER BY id DESC LIMIT 1"));
if ($CURUSER)
$latestuser = "<a href=account-details.php?id=" . $a["id"] . ">" . $a["username"] . "</a>";
else
$latestuser = "<b>$a[username]</b>";
$registered = number_format(get_row_count("users"));
$torrents = number_format(get_row_count("torrents"));

$result = mysql_query("SELECT SUM(downloaded) AS totaldl FROM users") or sqlerr(__FILE__, __LINE__); 

while ($row = mysql_fetch_array ($result)) 
{ 
$totaldownloaded = $row["totaldl"]; 
} 
$result = mysql_query("SELECT SUM(uploaded) AS totalul FROM users") or sqlerr(__FILE__, __LINE__); 

while ($row = mysql_fetch_array ($result)) 
{ 
$totaluploaded = $row["totalul"]; 
}
$seeders = get_row_count("peers", "WHERE seeder='yes'");
$leechers = get_row_count("peers", "WHERE seeder='no'");
$usersactive = 0;
if ($leechers == 0)
$ratio = "100";
else
$ratio = round($seeders / $leechers * 100);
if ($ratio < 20)
$ratio = "<font class=red>" . $ratio . "%</font>";
else
$ratio .= "%";
$peers = number_format($seeders + $leechers);
$seeders = number_format($seeders);
$leechers = number_format($leechers);
//start count visited today
$res = mysql_query("SELECT COUNT(*) FROM users WHERE UNIX_TIMESTAMP(" . get_dt_num() . ") - UNIX_TIMESTAMP(last_access) < 86400");
$arr3 = mysql_fetch_row($res);
$totaltoday = $arr3[0];
// start count registered today
$res = mysql_query("SELECT COUNT(*) FROM users WHERE UNIX_TIMESTAMP(" . get_dt_num() . ") - UNIX_TIMESTAMP(added) < 86400");
$arr44 = mysql_fetch_row($res);
$regtoday = $arr44[0];
//start count online now
$res = mysql_query("SELECT COUNT(*) FROM users WHERE UNIX_TIMESTAMP(" . get_dt_num() . ") - UNIX_TIMESTAMP(last_access) < 900");
$arr4 = mysql_fetch_row($res);
$totalnow = $arr4[0];
if ($CURUSER)
guestadd();
if (!$activepeople)
$activepeople = "" . NO_USERS . "";

if (!$todayactive)
$todayactive = "" . NO_USERS . "";
$guests = getguests();
if (!$guests)
$guests = "0";

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
//end here

///////////////////////////////////////// PAGE LAYOUT //////////////////////////////

stdhead();

begin_frame("" . STATS . "", center);

echo "<div align=left><font class=stats>" . WELCOME_NEW . ": " . $latestuser . "</font><br>";
if (!$activepeople)
echo "<br><font class=stats>" . ONLINE_USERS . ": (" . $totalnow . ")<b>0 Members</b></font>";
else
echo "<br><font class=stats>" . ONLINE_USERS . ": (" . $totalnow . ")</font>";
$totalusers = $totalnow + $guests;
echo "<br><font class=stats>" . GUESTS_ONLINE . ": (" . $guests . ")</font>";
echo "<br><font class=stats>" . TOTAL_ONLINE . ": (" . $totalusers . ")</font>";
if (!$todayactive)
echo "<br><font class=stats>" . VISITORS_TODAY . ": (<!--<a href='visitorstoday.php'>-->" . $totaltoday . "<!--</a>-->)<br>0 Members</font>";
else
echo "<br><font class=stats>" . VISITORS_TODAY . ": (<!--<a href='visitorstoday.php'>-->" . $totaltoday . "<!--</a>-->)<!--<br>" . $todayactive . "--></font>";
echo "<br><font class=stats>" . TOTAL_USERS . ": " . $registered . "</font>";
echo "<br><font class=stats>" . NEWUSERS_TODAY . ": " . $regtoday . "</font>";
echo "<br><font class=stats>" . ACTIVE_TRANSFERS . ": " . $peers . "</font>";
ECHO "<br><font class=stats>" . DOWNLOADED . ": " . mksize($totaldownloaded) . "</FONT>";
ECHO "<br><font class=stats>" . UPLOADED . ": " . mksize($totaluploaded) . "</FONT>";
echo "<br><font class=stats>" . TRACKING . " " . $torrents . " Torrents</font>";
echo "<br><font class=stats>" . SEEDS . ": " . $seeders . "</font>";
echo "<br><font class=stats>" . LEECH . ": " . $leechers . "</font>";
echo "<br><font class=stats>" . SEED_RATIO . ": " . $ratio . "</font>";
echo "<br><br></div>";

/////////////////////////////////////////
/////////////////////////////////////////
echo "<div align=left>";
echo "<strong>Thanks to all Donators</strong>";
echo "<br/>";
echo "<table cellpadding=0 cellspacing=0 style='border-collapse: collapse' bordercolor=#D6D9DB width='25.2%' border=1>
<tr><td td width='50%' class=table_head align=center><font size=1 face=Verdana color=black>" .MEMBER. "</td>
<td td width='50%' class=table_head align=center><font size=1 face=Verdana color=black>" .DONATION."</td>
</tr></table>";
echo "<marquee onmouseover=this.stop() onmouseout=this.start() scrollAmount=1 direction=up width='50%' height='200'>";
$sql = "SELECT id, username, donated FROM users WHERE donated != '' ORDER BY donated DESC ";
$mysql_result=mysql_query($sql) or die (mysql_error());; 
while ($row=mysql_fetch_array($mysql_result))
{
$id = $row['id'];
$username = $row['username'];
$donated = $row['donated'];
echo "<table cellpadding=0 cellspacing=0 style='border-collapse: collapse' bordercolor=#D6D9DB width='50%' border=1>
<tr><td width='50%' class=table_col1 align=center><strong><a href=account-details.php?id=$id>".$username."</a></strong></td>
<td width='50%'class=table_col2 align=center>don de ".$donated." &#8364;</td></tr></table>";
}
echo "<div align='left'><strong><br>Thanks All!</strong><br>";
echo "</marquee><br>";
echo "</div>";
echo"<br/>";
////////////////////////////////////////

$r = mysql_query("SELECT users.id, users.username, COUNT(torrents.owner) as num FROM torrents LEFT JOIN users ON users.id = torrents.owner GROUP BY owner ORDER BY num DESC LIMIT 10") or sqlerr();
postertable($r, "Top 10 Posters</font>"); echo "<br>";

$r = mysql_query("SELECT * FROM users WHERE secret <> '' ORDER BY uploaded DESC LIMIT 10") or die;
usertable($r, "Top 10 Uploaders"); echo "<br>";

$r = mysql_query("SELECT * FROM users WHERE secret <> '' ORDER BY downloaded DESC LIMIT 10") or die;
usertable($r, "Top 10 Leechers"); echo "<br>";

$r = mysql_query("SELECT * FROM users WHERE downloaded > 104857600 ORDER BY uploaded - downloaded DESC LIMIT 10") or die;
usertable($r, "Top 10 Best Sharers <font class=small>(with minimum 100 MB downloaded)</font>"); echo "<br>";

$r = mysql_query("SELECT * FROM users WHERE downloaded > 104857600 AND secret <> '' ORDER BY downloaded - uploaded DESC, downloaded DESC LIMIT 10") or die;
usertable($r, "Top 10 Worst Sharers <font class=small>(with minimum 100 MB downloaded)</font>"); echo "<br>";

$r = mysql_query("SELECT * FROM torrents ORDER BY seeders + leechers DESC, seeders DESC, added ASC LIMIT 10") or sqlerr();
_torrenttable($r, "Top 10 Most Active Torrents</font>"); echo "<br>";

$r = mysql_query("SELECT * FROM torrents WHERE seeders >= 5 ORDER BY seeders / leechers DESC, seeders DESC, added ASC LIMIT 10") or sqlerr();
_torrenttable($r, "Top 10 Best Seeded Torrents <font class=small>(with minimum 5 seeders)</font>"); echo "<br>";

$r = mysql_query("SELECT * FROM torrents WHERE leechers >= 5 AND times_completed > 0 ORDER BY seeders / leechers ASC, leechers DESC LIMIT 10") or sqlerr();
_torrenttable($r, "Top 10 Worst Seeded Torrents <font class=small>(with minimum 5 leechers, excluding unsnatched torrents)</font>"); echo "<br>";

/*$r = mysql_query("SELECT * FROM users ORDER BY donated DESC, username LIMIT 100") or die;
donortable($r, "Top 10 Donors"); echo "<br>";*/

$r = mysql_query("SELECT name, flagpic, COUNT(users.country) as num FROM countries LEFT JOIN users ON users.country = countries.id GROUP BY name ORDER BY num DESC LIMIT 10") or sqlerr();
countriestable($r, "Top 10 Countries</font>");echo "<br><br>";
end_frame();
stdfoot();

}


#===========================#
#server load
#=========================#

if ($action == "Server") {
stdhead("Server Load");
    navmenu();
begin_frame("Server Load");

if (!function_exists("getmicrotime"))
{
   function getmicrotime(){
       list($usec, $sec) = explode(" ",microtime());
       return ((float)$usec + (float)$sec);
       }
}

$percent = min(100, round(@exec('ps ax | grep -c apache') / 256 * 10 ),4);

// try other method
if ($percent == 0)
    {
    $time_start = getmicrotime();
    $time = round(getmicrotime() - $time_start,4);
    $percent = $time * 60;
    }


echo "<div align=\"center\">".TRACKER_LOAD.": ($percent %)</div><table class=tablebg align=center border=0 width=400><tr><td style='padding: 0px; background-image: url(images/loadbarbg.gif); background-repeat: repeat-x'>";

//TRACKER LOAD
if ($percent <= 70) $pic = "image/loadbargreen.gif";
elseif ($percent <= 90) $pic = "images/loadbaryellow.gif";
else $pic = "images/loadbarred.gif";
$width = $percent*4;
echo "<img height=15 width=$width src=\"$pic\" alt='$percent%'></td></tr></table>";
echo "<center>" . trim(@exec('uptime')) . "</center><br>";

if (isset($load))
print("<tr><td class=row1>10min load average (%)</td><td align=right>$load</td></tr>\n");
print("<br>");
$percent = min(100, round(@exec('ps ax | grep -c apache') / 256 * 50),4);
// try other method
if ($percent == 0)
    {
    $time = round(getmicrotime() - $time_start,4);
    $percent = $time * 60;
    }

echo "<div align=\"center\">".GLOBAL_SERVER_LOAD.": ($percent %)</div><table class=row1 align=center border=0 width=400><tr><td style='padding: 0px; background-image: url(images/loadbarbg.gif); background-repeat: repeat-x'>";

 if ($percent <= 70) $pic = "images/loadbargreen.gif";
  elseif ($percent <= 90) $pic = "images/loadbaryellow.gif";
   else $pic = "images/loadbarred.gif";
        $width = $percent * 4;
echo "<img height=15 width=$width src=\"$pic\" alt='$percent%'></td></tr></table><br /><br />";
end_frame();
stdfoot();

}
#===========#
#end serverload
#============#



#======================================================================#
#    Manual Conf Reg
#======================================================================#
if($action == "confirmreg")
{
stdhead("Manual Registration Confirm");
navmenu();
begin_frame("Info On This List", justify);
?>
<p align="justify">This page shows all users that have not clicked the ACTIVATION link in the signup email, they cannot access the site until they have clicked this link.  You should only manually confirm a user if they request it (via email, irc or other method), where they have lost or not received the email.  All PENDING users will be cleaned from the system every so often.</p>
<?
end_frame();
begin_frame("Manual Registration Confirm", center);
begin_table();
$perpage = 100;
print("<tr><td align=\"center\"  class=alt3 align=left><font size=1 face=Verdana>Username</td><td align=\"center\"  class=alt3><font size=1 face=Verdana>Email Address</td><td align=\"center\"  class=alt3><font size=1 face=Verdana>Date Registered</td><td align=\"center\"  class=alt3 align=left><font size=1 face=Verdana>IP</td><td align=\"center\"  class=alt3><font size=1 face=Verdana>Status</td></tr>\n");

$resww = "SELECT * FROM users WHERE status='pending' ORDER BY username";
$reqww = mysql_query($resww);
while ($row = mysql_fetch_array($reqww))
    {
     extract ($row);
  echo "<tr><td align='center'>$row[username]</td><td align='center'>$row[email]</td><td align='center'>$row[added]</td><td align='center'>$row[ip]</td><td align='center'><a href='modocp.php?action=editreg&id=$row[id]'>$row[status]</a></td></tr>\n";

    }
end_table();
end_frame();
stdfoot();
}

if($action == "save_editreg")
// SAVE THEME EDIT FUNCTION
    {
        mysql_query("UPDATE users SET status='$ed_status' WHERE id=$id");
show_success_msg("Updated", "<br><br><center><b>Updated Completed</b><BR><BR><a href='modocp.php?action=confirmreg'>Click here</a> to go back.</center>");
}

if($action == "editreg" && $id != "")
// EDIT USER REG FORM
{
    $qq = mysql_query("SELECT * FROM users WHERE id = $id");
    $ee = mysql_fetch_array($qq);
    stdhead();
    navmenu();
    begin_frame();
    ?>

    <form action='modocp.php' method='post'>
    <input type='hidden' name='id' value='<?=$id?>'>
    <input type='hidden' name='action' value='save_editreg'>
    Name: <?=$ee[username]?><br />
    Current Status: <?=$ee[status]?><br>
    <select name='ed_status'>
        <option value='pending' <? if($status == "pending") echo "selected"; ?>>pending
        <option value='confirmed' <? if($status == "confirmed") echo "selected"; ?>>confirmed
        </select>
    <!--<input type='text' value='<?=$ee[status]?>' size='30' maxlength='30' name='ed_status'><br />-->
    <input type='submit' value='   Save   ' style='background:#eeeeee'>&nbsp;&nbsp;&nbsp;<input type='reset' value='  Reset  ' style='background:#eeeeee'>
    </form>
    <?
        end_frame();
stdfoot();
}

if ($action=="reports" && $do=="view"){
    stdhead("Reported Items");
    navmenu();

    begin_frame("Reported Items");

    $res = mysql_query("SELECT count(id) FROM reports WHERE complete='0'") or die(mysql_error());
    $row = mysql_fetch_array($res);

    $count = $row[0];
    $perpage = 25;
    list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?type=" . $_GET["type"] . "&" );

    echo "<BR><CENTER><B><a href=#>View Archived Reports</a></B></CENTER><BR>";

    echo $pagertop;

    print("<table border=1 cellspacing=0 cellpadding=1 align=center width=95% class=table_table>\n");
    print("<tr><td class=table_head align=center>By</td><td class=table_head align=center>Reported</td><td class=table_head align=center>Type</td><td class=table_head align=center>Reason</td><td class=table_head align=center>Dealt With</td>");
    print("</tr>");
    $res = mysql_query("SELECT reports.id, reports.dealtwith,reports.dealtby, reports.addedby, reports.votedfor,reports.votedfor_xtra, reports.reason, reports.type, users.username, reports.complete FROM reports INNER JOIN users on reports.addedby = users.id WHERE complete = '0' ORDER BY id desc $limit");

    while ($arr = mysql_fetch_assoc($res))
    {
    if ($arr[dealtwith])
    {
    $res3 = mysql_query("SELECT username FROM users WHERE id=$arr[dealtby]");
    $arr3 = mysql_fetch_assoc($res3);
    $dealtwith = "<font color=green><b>Yes - <a href=account-details.php?id=$arr[dealtby]><b>$arr3[username]</b></a></b></font>";
    }
    else
    $dealtwith = "<font color=red><b>No</b></font>";
    if ($arr[type] == "user")
    {
    $type = "account-details.php?id=$arr[votedfor]";
    $res2 = mysql_query("SELECT username FROM users WHERE id=$arr[votedfor]");
    $arr2 = mysql_fetch_assoc($res2);
    $name = $arr2[username];
    }
    else if  ($arr[type] == "comment")
    {
    $res2 = mysql_query("SELECT text, news, torrent FROM comments WHERE id=$arr[votedfor]");
    $arr2 = mysql_fetch_assoc($res2);
    if($arr2[torrent]){
    $type = "comments.php?id=$arr[votedfor]&type=torrent&id=$arr2[torrent]";
    $name = format_comment($arr2[text]);
    }elseif($arr2[news]){
    $type = "comments.php?type=news&id=$arr2[news]";
    $name = format_comment($arr2[text]);
    }
    }
    else if ($arr[type] == "torrent")
    {
    $type = "torrents-details.php?id=$arr[votedfor]";
    $res2 = mysql_query("SELECT name FROM torrents WHERE id=$arr[votedfor]");
    $arr2 = mysql_fetch_assoc($res2);
    $name = $arr2[name];
    if ($name == "")
     $name = "<b>[Deleted]</b>";
    }
    print("<tr><td class=table_col1><a href=account-details.php?id=$arr[addedby]><b>$arr[username]</b></a></td><td align=left class=table_col2><a href=$type><b>$name</b></a></td><td align=left class=table_col1>$arr[type]</td><td align=left class=table_col2>$arr[reason]</td><td align=left class=table_col1>$dealtwith</td>\n");
    print("</tr>");
    }

    print("</table>\n");



    echo $pagerbottom;

    end_frame();
    stdfoot();
}
if ($action == "clearshoutbox") {
    stdhead("Clear Shoutbox");
    navmenu();
        begin_frame("Clear Shoutbox", center);
            if ($yes == "yes") {
                $res = mysql_query("TRUNCATE `shoutbox`");
                if ($res) echo "Shoutbox cleared";
            } else {
                echo "<div align=center>Are you sure you want to clear the shoutbox?<br>";
                echo "<a href='modocp.php?action=clearshoutbox&yes=yes'><b>Yes</b></a></div>";
            }
    end_frame();
    stdfoot();
}

if ($action=="emailbans"){
    stdhead("Email Bans");
    navmenu();

    $remove = $HTTP_GET_VARS['remove'];

    if (is_valid_id($remove)){
        mysql_query("DELETE FROM email_bans WHERE id=$remove") or die(mysql_error());
        write_log("Email Ban $remove was removed by ($CURUSER[username])");
    }

    if ($_GET["add"] == '1'){
        $mail_domain = trim($_POST["mail_domain"]);
        $comment = trim($_POST["comment"]);

        if (!$mail_domain || !$comment){
            show_error_msg("Error", "Missing form data.",0);
            stdfoot();
            die;
        }
        $mail_domain= sqlesc($mail_domain);
        $comment = sqlesc($comment);
        $added = sqlesc(get_date_time());

        mysql_query("INSERT INTO email_bans (added, addedby, mail_domain, comment) VALUES($added, $CURUSER[id], $mail_domain, $comment)") or die(mysql_error());

        write_log("Email Ban $mail_domain was added by ($CURUSER[username])");
        show_success_msg("Complete", "Email Ban Added",0);
        stdfoot();
        die;
    }

    begin_frame("Emails Or Domains Adress Bans");
    print("You can block specific email addresses or domains from signing up to your tracker<BR><BR><BR><b>&nbsp;Add Emails OR Domains Ban</b>\n");
    print("<table border=0 cellspacing=0 cellpadding=5 align=center>\n");
    print("<form method=post action=modocp.php?action=emailbans&add=1>\n");
    print("<tr><td align=right>Email Address OR Domain To Ban</td><td><input type=text name=mail_domain size=40></td>\n");
    print("<tr><td align=right>Comment</td><td><input type=text name=comment size=40></td>\n");
    print("<tr><td colspan=2 align=center><input type=submit value='Add Ban'></td></tr>\n");
    print("</form>\n</table>\n<br>");
    //}

    $res2 = mysql_query("SELECT count(id) FROM email_bans") or die(mysql_error());
    $row = mysql_fetch_array($res2);
    $url = " .$_SERVER[PHP_SELF]";
    $count = $row[0];
    $perpage = 40;list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $url);
    print("<BR><b>&nbsp;Current Email Bans ($count)</b>\n");

    if ($count == 0){
        print("<p align=center><b>Nothing found</b></p><br>\n");
    }else{
        echo $pagertop;
        print("<table border=0 cellspacing=0 cellpadding=5 width=90% align=center class=table_table>\n");
        print("<tr><td class=table_head>Added</td><td  class=table_head align=left>Mail Address Or Domain</td>"."<td class=table_head align=left>Banned By</td><td  class=table_head align=left>Comment</td><td class=table_head>Remove</td></tr>\n");
        $res = mysql_query("SELECT * FROM email_bans ORDER BY added DESC $limit") or die(mysql_error());

        while ($arr = mysql_fetch_assoc($res)){
            $r2 = mysql_query("SELECT username FROM users WHERE id=$arr[userid]") or die(mysql_error());
            $a2 = mysql_fetch_assoc($r2);

            $r4 = mysql_query("SELECT username,id FROM users WHERE id=$arr[addedby]") or die(mysql_error());
            $a4 = mysql_fetch_assoc($r4);
            print("<tr><td class=table_col1>".utc_to_tz($arr['added'])."</td><td align=left class=table_col2>$arr[mail_domain]</td><td align=left class=table_col1><a href=account-details.php?id=$a4[id]>$a4[username]"."</a></td><td align=left class=table_col2>$arr[comment]</td><td class=table_col1><a href=modocp.php?action=emailbans&remove=$arr[id]>Remove</a></td></tr>\n");
        }

        print("</table>\n");

        echo $pagerbottom;
        echo "<br>";
    }
    end_frame();
    stdfoot();
}

if ($action=="polls" && $do=="view"){
	stdhead("Polls Management");
	navmenu();
	begin_frame("Polls Management");

	echo "<CENTER><a href=modocp.php?action=polls&do=add>Add New Poll</a></CENTER>";
	echo "<CENTER><a href=modocp.php?action=polls&do=results>View Poll Results</a></CENTER>";

	echo "<BR><BR><b>Polls</b> (Top poll is current)<BR>";

	$query = mysql_query("SELECT id,question,added FROM polls ORDER BY added DESC") or die(mysql_error());

	while($row = MYSQL_FETCH_ARRAY($query)){
		echo "<a href=modocp.php?action=polls&do=add&subact=edit&pollid=$row[id]>".stripslashes($row["question"])."</a> - ".utc_to_tz($row['added'])." - <a href=modocp.php?action=polls&do=delete&id=$row[id]>Delete</a><BR>\n\n";
	}

	end_frame();

	stdfoot();
}

#======================================================================#
#    Free Torrents
#======================================================================#

if ($action=="freetorrents"){
    stdhead("Free Leech Torrent Management");
    navmenu();
        begin_frame("Free Leech Torrent Management");
    $search = trim($search);

    if ($search != '' ){
        $whereand = "AND name LIKE " . sqlesc("%$search%") . "";
    }

        if ($do=="setallfree") {
        mysql_query("UPDATE torrents SET freeleech='1'");
        print("<font class=success><center>Success, All torrents have been set free..</b></center></font><br>\n");

        }else

        if ($do=="setallnormal") {
        mysql_query("UPDATE torrents SET freeleech=''");
        print("<font class=success><center><b>Success, All torrents have been set normal..</b></center></font><br>\n");

}

    $res2 = mysql_query("SELECT COUNT(*) FROM torrents WHERE freeleech='1' $whereand");
    $row = mysql_fetch_array($res2);
    $count = $row[0];

    $perpage = 50;

    list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "modocp.php?action=freetorrents&");

    print("<CENTER><form method=get action=?>\n");
    print("<input type=hidden name=action value=torrentmanage>\n");
    print("" . SEARCH . ": <input type=text size=30 name=search>\n");
    print("<input type=submit value='Search'>\n");
    print("</form></CENTER>\n");

        echo "<br>";
        print("<font size=2><center>Click <a href=modocp.php?action=freetorrents&do=setallfree><b><u>here</b></u></a> to set all torrents free.. </center></font><br><br> <font size=2><center>Click <a href=modocp.php?action=freetorrents&do=setallnormal><b><u>here</u></b></a> to set all torrents normal..</center></font> \n");

    echo $pagertop;
    ?>
    <CENTER><table align=center cellpadding="0" cellspacing="0" class="table_table" width="100%" border="1">
    <tr>
    <td class=table_head align=center>Name</td>
    <td class=table_head align=center>Visible</td>
    <td class=table_head align=center>Banned</td>
    <td class=table_head align=center>Seeders</td>
    <td class=table_head align=center>Leechers</td>
    <td class=table_head align=center>Edit?</td>
    </tr>
    <?
    $rqq = "SELECT id, name, seeders, leechers, visible, banned FROM torrents WHERE freeleech='1' $whereand ORDER BY name $limit";
    $resqq = mysql_query($rqq);

    while ($row = mysql_fetch_array($resqq)){
        extract ($row);

        $char1 = 35; //cut name length
        $smallname = CutName(htmlspecialchars($row["name"]), $char1);

        echo "<tr><td class=table_col1>" . $smallname . "</td><td class=table_col2>$row[visible]</td><td class=table_col1>$row[banned]</td><td class=table_col2>$row[seeders]</td><td class=table_col1>$row[leechers]</td><td class=table_col2><a href=\"torrents-edit.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;id=" . $row["id"] . "\"><font size=1 face=Verdana>EDIT</a></td></tr>\n";
    }

    echo "</table></CENTER>\n";

    print($pagerbottom);

    end_frame();
    stdfoot();
}
#======================================================================#
#    END Free Torrents
#======================================================================#

if ($action=="lastcomm"){
    stdhead("Latest Comments");
    navmenu();
    begin_frame("Last Comments");
    echo "<table align=center cellpadding=1 cellspacing=0 width=100%><tr><td align=left><a href=\"modocp.php?action=lastcommnews\">View Last comments From News</a></td><td align=right><a href=\"modocp.php?action=lastcommtorrents\">View Last comments From torrents: </a></td></tr></table><br>";                            
    end_frame();
    stdfoot();
}

if ($action=="lastcommnews"){
    stdhead("Latest Comments");
    navmenu();

    $res = mysql_query("SELECT COUNT(*) FROM comments WHERE news > 0") or die(mysql_error()); 
    $arr = mysql_fetch_row($res); 
    $count = $arr[0];
    if(!$count){
     show_error_msg("Error","No comments");
    }
    begin_frame("Last Comments");

    $res = mysql_query("SELECT comments.id, comments.added, comments.user, comments.news, comments.text, news.title as tnome, users.username as unome FROM comments LEFT JOIN users ON users.id = comments.user LEFT JOIN news ON news.id = comments.news ORDER BY comments.news DESC LIMIT 5") or die(mysql_error());

    while ($arr = mysql_fetch_assoc($res)) {
        $userid = $arr["user"];
        $username = $arr["unome"];
        $data = $arr["added"];
        $tid = $arr["news"];
        $tnome = stripslashes($arr["tnome"]);
        $comentario = stripslashes(format_comment($arr["text"]));
        $cid = $arr["id"];
         if($tid > 0){
        echo "<table class=tablebg align=center width=98%><tr><td class=rowTabHead align=center>News: <a href=\"comments.php?type=news&id=$tid\">".$tnome."</a>&nbsp;&nbsp;<font class=error>Posted in <B>".$data."</B> by </font><a href=\"account-details.php?id=".$userid."\">".$username."</a><a href=\"comments.php?id=".$cid."&type=news&edit=1\">&nbsp;&nbsp;<img src=\"".$site_config['SITEURL']."/images/buttons/edit.png\" border=\"0\" title=\"Edit\"><a href=\"comments.php?id=".$cid."&type=news&delete=1\">&nbsp;&nbsp;<img src=\"".$site_config['SITEURL']."/images/buttons/delete.png\" border=\"0\" title=\"Delete\"></td></tr><tr><td class=row2>".$comentario."</td></tr><tr><td class=rowEnd></td></tr></table><br>";
       }

    }
    end_frame();
    stdfoot();
}


if ($action=="lastcommtorrents"){
    stdhead("Latest Comments");
    navmenu();

    $res = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent > 0") or die(mysql_error());
    $arr = mysql_fetch_row($res);
    $count = $arr[0];
    if(!$count){
     show_error_msg("Error","No comments");
    }
    begin_frame("Last Comments");  

    $res = mysql_query("SELECT comments.id, comments.added, comments.user, comments.torrent, comments.text, torrents.name as tnome, users.username as unome FROM comments LEFT JOIN users ON users.id = comments.user LEFT JOIN torrents ON torrents.id = comments.torrent ORDER BY comments.added DESC LIMIT 5") or die(mysql_error());

    while ($arr = mysql_fetch_assoc($res)) {
        $userid = $arr["user"];
        $username = $arr["unome"];
        $data = $arr["added"];
        $tid = $arr["torrent"];
        $tnome = stripslashes($arr["tnome"]);
        $comentario = stripslashes(format_comment($arr["text"]));
        $cid = $arr["id"];
        if($tid > 0){ 
        echo "<table class=tablebg align=center width=98%><tr><td class=rowTabHead align=center>Torrent: <a href=\"torrent-details.php?id=$tid\">".$tnome."</a>&nbsp;&nbsp;<font class=error>Posted in <B>".$data."</B> by </font><a href=\"account-details.php?id=".$userid."\">".$username."</a><a href=\"comments.php?id=".$cid."&type=torrent&edit=1\">&nbsp;&nbsp;<img src=\"".$site_config['SITEURL']."/images/buttons/edit.png\" border=\"0\" title=\"Edit\"><a href=\"comments.php?id=".$cid."&type=torrent&delete=1\">&nbsp;&nbsp;<img src=\"".$site_config['SITEURL']."/images/buttons/delete.png\" border=\"0\" title=\"Delete\"></td></tr><tr><td class=row2>".$comentario."</td></tr><tr><td class=rowEnd></td></tr></table><br>";  
        }

    }
    end_frame();
    stdfoot();
}

if ($action=="masspm"){
    stdhead("Mass Private Message");
    navmenu();


    //send pm
    if ($_GET["send"] == '1'){

        $sender_id = ($_POST['sender'] == 'system' ? 0 : $CURUSER['id']);

        $dt = sqlesc(get_date_time());
        $msg = $_POST['msg'];

        if (!$msg)
            show_error_msg("Error","Please Enter Something!",1);

        $updateset = $_POST['clases'];

        $query = mysql_query("SELECT id FROM users WHERE class IN (".implode(",", $updateset).")");
        while($dat=mysql_fetch_assoc($query)){
            mysql_query("INSERT INTO messages (sender, receiver, added, msg) VALUES ($sender_id, $dat[id], '" . get_date_time() . "', " . sqlesc($msg) .")");
        }

        write_log("A Mass PM was sent by ($CURUSER[username])");
        show_success_msg("Complete", "Mass PM Sent",1);
        die;
    }

    begin_frame("Mass Private Message");
    print("<table border=0 cellspacing=0 cellpadding=5 align=center width=90%>\n");
    print("<form method=post action=modocp.php?action=masspm&send=1>\n");
    print("<B>Send to:</B><BR>\n");

    $query = "SELECT group_id, level FROM groups";
    $res = mysql_query($query);

    while ($row = mysql_fetch_array($res)){
        extract ($row);
    
        echo "<input type=checkbox name=clases[] value=$row[group_id]> $row[level]<BR>\n";
    }

    ?>
    <BR><b>Message: </b><BR>
    <input type=hidden name=receiver value=<?=$receiver?>>
    <tr>
    <td><textarea name=msg cols=60 rows=10><?=$body?></textarea>
    <br>NOTE: Remember that BB can be used (NO HTML)</td>
    </tr>

    <tr>
    <td><b>Sender: </b>
    <?=$CURUSER['username']?> <input name="sender" type="radio" value="self" checked>
    System <input name="sender" type="radio" value="system"></td>
    </tr>

    <tr>
    <td><input type=submit value="Send" class=lbutton></td>
    </tr>
    </table></form>
    <?
    end_frame();
    stdfoot();
}

#======================================================================#
# Word Censor Filter
#======================================================================#
if($action == "censor") {
stdhead("Censor"); 
navmenu();
//FIX by hack346
if ($_POST['submit'] == 'Add Censor'){
$query = "INSERT INTO censor (word, censor) VALUES ('" . $_POST['word'] . "','" . $_POST['censor'] . "');";
             mysql_query($query);
             autolink("modocp.php?action=censor" , "Word added");  
             }
if ($_POST['delete'] == 'Delete Censor'){
  $aquery = "DELETE FROM censor WHERE word = '" . $_POST['censor'] . "' LIMIT 1";
  mysql_query($aquery);
  autolink("modocp.php?action=censor" , "Word removed from censor");
  }

begin_frame("Edit Censored Words");  
/*------------------
|HTML form for Word Censor
------------------*/
?>
<div align="center">
<table width='100%' cellspacing='3' cellpadding='3'>
<form id="Add Censor" name="Add Censor" method="POST" action="modocp.php?action=censor">
<tr>
<td bgcolor='#eeeeee'><font face="Verdana" size="1">Add Word Censor:  <input type="text" name="word" id="word" size="50" maxlength="255" value=""></font></td></tr>
<tr><td bgcolor='#eeeeee'><font face="Verdana" size="1">Censor Word With:  <input type="text" name="censor" id="censor" size="50" maxlength="255" value=""></font></td></tr>
<tr><td bgcolor='#eeeeee' align='left'>
<font size="1" face="Verdana"><input type="submit" name="submit" value="Add Censor"></font></td>
</tr>
</form>

<form id="Delete Censor" name="Delete Censor" method="POST" action="modocp.php?action=censor">
<tr>
<td bgcolor='#eeeeee'><font face="Verdana" size="1">Remove Censor For: <select name="censor">
<?
/*-------------
|Get the words currently censored
-------------*/
$select = "SELECT word FROM censor ORDER BY word";
$sres = mysql_query($select);
while ($srow = mysql_fetch_array($sres))
{
        echo "<option>" . $srow[word] . "</option>\n";
        }
echo'</select></font></td></tr><tr><td bgcolor="#eeeeee" align="left">
<font size="1" face="Verdana"><input type="submit" name="delete" value="Delete Censor"></font></td>
</tr></form></table></div>';
end_frame();
stdfoot();
}
// End forum Censored Words


?>
Return current item: H-tracker