<?php 

    // CONFIG
    $odbc_host = 'ZULU542\SQLEXPRESS';
    $odbc_user = 'sa';
    $odbc_pass = '7126qTzasdQ1789qmncüay1';
    // CONFIG END
    
    echo '<h1>Top 100 Spieler</h1>';
    $odbc_link = odbc_connect ( "Driver={SQL Server};Server=".$odbc_host.";Database=World00_Character;" , $odbc_user , $odbc_pass );
    
    $sql[1] = 'SELECT TOP 100 nCharNo, sID, nExp , nLevel FROM tCharacter WHERE nAdminLevel = 0 AND bDeleted = 0 ORDER  BY nExp DESC';
    $rs[1] = odbc_exec ( $odbc_link , $sql[1] );
    if ( !$rs[1] )
        {
        exit ( 'Error in SQL' );
        }
    
    $i = 1;
        
    echo '<table width="100%">';
    echo '    <tr>';
    echo '        <td>';
    echo '            #';
    echo '        </td>';
    echo '        <td>';
    echo '            Name';
    echo '        </td>';
    echo '        <td>';
    echo '            Exp';
    echo '        </td>';
    echo '        <td>';
    echo '            Level';
    echo '        </td>';
    echo '        <td>';
    echo '            Klasse';
    echo '        </td>';
    echo '        <td>';
    echo '            Gilde';
    echo '        </td>';
    echo '    </tr>';
    while ( odbc_fetch_row ( $rs[1] ) )
        {
        $sID = odbc_result ( $rs[1] , 'sID' );
        $nExp = odbc_result ( $rs[1] , 'nExp' );
        $nLevel = odbc_result ( $rs[1] , 'nLevel' );
        $nName = 'Keine Gilde';
        $sID = str_replace ( '?', '&dagger;', str_replace ( '?' , '&auml;' , str_replace ( '?' , '&Auml;' , str_replace ( '?' , '&ouml;' , str_replace ( '?' , '&Ouml;' , str_replace ( '?' , '&uuml;' , str_replace ( '?' , '&Uuml;' , str_replace ( '?' , '&szlig;' , $sID ) ) ) ) ) ) ) );
        
        $nCharNo = odbc_result ( $rs[1] , 'nCharNo' );
        
        $sql[2] = 'SELECT TOP 1 nNo FROM tGuildMember WHERE nCharNo = '.$nCharNo;
        $rs[2] = odbc_exec ( $odbc_link , $sql[2] );
        if ( !$rs[2] )
            {
            exit ( 'Error in SQL' );
            }
        while ( odbc_fetch_row ( $rs[2] ) )
            {
            $nNo = odbc_result ( $rs[2] , 'nNo' );
            $sql[3] = 'SELECT TOP 1 sName FROM tGuild WHERE nNo = '.$nNo;
            $rs[3] = odbc_exec ( $odbc_link , $sql[3] );
            while ( odbc_fetch_row ( $rs[3] ) )
                {
                $nName = odbc_result ( $rs[3] , 'sName' );
                }
            }
            
        $sql[4] = 'SELECT TOP 1 nClass FROM tCharacterShape WHERE nCharNo = '.$nCharNo;
        $rs[4] = odbc_exec ( $odbc_link , $sql[4] );
        if ( !$rs[4] )
            {
            exit ( 'Error in SQL' );
            }
        while ( odbc_fetch_row ( $rs[4] ) )
            {
            $nClass = odbc_result ( $rs[4] , 'nClass' );
            }
        
        switch ($nClass)
            {
            //Krieger
            case 1:
                $nClass = 'Fighter';
                break;
            case 2:
                $nClass = 'Highlander';
                break;
            case 3:
                $nClass = 'Feldherr';
                break;
            case 4:
                $nClass = 'Gladiator';
                break;
            case 5:
                $nClass = 'Ordensritter';
                break;
            
            //Priester    
            case 8:
                $nClass = 'Priester';
                break;
            case 9:
                $nClass = 'Kleriker';
                break;
            case 10:
                $nClass = 'Hohepriester';
                break;
            case 11:
                $nClass = 'Heilige Ritter';
                break;
            case 12:
                $nClass = 'W&auml;chter';
                break;
            
            //Jäger    
            case 15:
                $nClass = 'J&auml;ger';
                break;
            case 16:
                $nClass = 'Fallensteller';
                break;
            case 17:
                $nClass = 'Gro&szlig;wildj&auml;ger';
                break;
            case 18:
                $nClass = 'Scharfsch&uuml;tze';
                break;
            case 19:
                $nClass = 'Waldl&auml;ufer';
                break;
            
            //Magier    
            case 22:
                $nClass = 'Magier';
                break;
            case 23:
                $nClass = 'Erzmagier';
                break;
            case 24:
                $nClass = 'Beschw&ouml;rer';
                break;
            case 25:
                $nClass = 'Hexenmeister';
                break;
            case 26:
                $nClass = 'Zauberer';
                break;
            
            //Standart    
            default:
                $nClass = 'Unbekannte Klasse';
                break;
            }
        
        echo '    <tr>';
        echo '        <td>';
        echo '            '.$i;
        echo '        </td>';
        echo '        <td>';
        echo '            '.$sID;
        echo '        </td>'; 
        echo '        <td>';
        echo '            '.$nExp;  
        echo '        </td>';
        echo '        <td>';
        echo '            '.$nLevel;
        echo '        </td>';
        echo '        <td>';
        echo '            '.$nClass;
        echo '        </td>';
        echo '        <td>';
        echo '            '.$nName;
        echo '        </td>';
        echo '    </tr>';
        
        $i++;
        }
        
    odbc_close ( $odbc_link );
    
    echo '</table>';

?>