<?

ini_set('display_errors', 'Off');

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) {
    define( 'ROOT', 'http://'.$_SERVER['HTTP_HOST'] );
    define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );
    session_start();
    include_once ROOT_DIR . '/engine/config.php';
} else {
    if ( !defined( 'MISOFT' ) ) { exit(); }
}

if ( $_POST['p'] == 'ajax' ) {
    header( 'Content-type: text/html; charset=windows-1251' );
}

switch ( ( int ) $_GET['type'] ) {
    case 1:
        $toptype = 'WHERE account != 5 ORDER BY referals DESC LIMIT 10';
        $typeznachenie = 'Рефералов';
        $typeSql = 'referals';
        break;
    case 2:
        $toptype = 'WHERE account != 5 ORDER BY reyting DESC LIMIT 10';
        $typeznachenie = 'Рейтинг';
        $typeSql = 'reyting';
        break;
    case 3:
        $toptype = 'WHERE account != 5 ORDER BY (money + paid) DESC LIMIT 10';
        $typeznachenie = 'Заработано';
        $typeSql = 'money';
        break;
    case 4:
        $toptype = 'WHERE account != 5 ORDER BY serf_view DESC LIMIT 10';
        $typeznachenie = 'Кликов';
        $typeSql = 'serf_view';
        break;
    default:
        $toptype = 'WHERE account != 5 ORDER BY referals DESC LIMIT 10';
        $typeznachenie = 'Рефералов';
        $typeSql = 'referals';
        break;
}

?>

<table class="topuser10">
    <thead>
        <th style="width: 20px;">№</th>
        <th style="text-align: left;">Пользователь</th>
        <th style="width: 50px; text-align: center;"><?=$typeznachenie?></th>
    </thead>
    <?
    $numberTop10 = 0;
    $top10 = mysql_query( "SELECT username, referals, reyting, money, paid, serf_view FROM user $toptype" );
    while ( $top10_row = mysql_fetch_array( $top10 ) ) {
        $numberTop10++;
        ?>
        <tr>
            <td class="top_t1"><?=$numberTop10?></td>
            <td class="top_t2"><?=$top10_row['username']?></td>
            <td class="top_t3"><?if ( $typeSql == 'money' ) echo moneyraund( $top10_row[$typeSql] + $top10_row['paid'], 2 ); else echo ( int ) $top10_row[$typeSql];?></td>
        </tr>
        <?
    }
    ?>
</table>