<?php
	function mssql_escape_string($string) {
		$replaced_string = str_replace("'", "''", $string);
		return $replaced_string;
	}

    function getItemName($intItemID, $row = '') {
        GLOBAL $odbc_connect, $_CONFIG;

        if(is_numeric($intItemID)) {

            if(empty($row)) {
                $resSearchItem = @odbc_exec($odbc_connect, 'SELECT [name] FROM [' . $_CONFIG['db_databases']['web'] . '].dbo.[LOG_ITEMS] WHERE [id] = ' . $intItemID);

                if(odbc_num_rows($resSearchItem) > 0) {
                    $return = @odbc_result($resSearchItem, 'name');
                }
                else {
                    $return = $intItemID;
                }
            }
            else {
                $resSearchItem = @odbc_exec($odbc_connect, 'SELECT ['.$row.'] FROM [' . $_CONFIG['db_databases']['web'] . '].dbo.[LOG_ITEMS] WHERE [id] = ' . $intItemID);

                if(odbc_num_rows($resSearchItem) > 0) {
                    $return = @odbc_result($resSearchItem, $row);
                }
                else {
                    $return = $intItemID;
                }
            }


        }
        else {
            $return = $intItemID;
        }
        return $return;
    }

    function getUserName($intCharacterID) {
        GLOBAL $odbc_connect, $_CONFIG;

        if(is_numeric($intCharacterID)) {

            $resSearchItem = @odbc_exec($odbc_connect, 'SELECT [m_szName] FROM [' . $_CONFIG['db_databases']['chr'] . '].dbo.[CHARACTER_TBL] WHERE [m_idPlayer] = ' . $intCharacterID);
            if(odbc_num_rows($resSearchItem) > 0) {
                $return = utf8_encode(@odbc_result($resSearchItem, 'm_szName'));
            }
            else {
                $return = $intCharacterID;
            }
        }
        else {
            $return = $intCharacterID;
        }
        return $return;
    }

    function isAccountBanned($intDate) {
        if($intDate < date('Ymd')) {
            return 'Nein';
        }
        else {
            return '<span class="alert">Bis einschließlich '.substr($intDate,6,2).'.'.substr($intDate,4,2).'.'.substr($intDate,0,4).'</span>';
        }
    }

    function checkCharacterState($strInput, $mode = '') {
        if($strInput == 'F') {
            $strReturn = '';
        }
        else {
            if($mode == 'char') {
                $strReturn = ' / <span style="color: #cc0000;">Gelöscht</span>';
            }
            else {
                $strReturn = ' und <span style="color: #cc0000;">gelöscht</span>';
            }
        }
        return $strReturn;
    }

    function checkCharacterOnlineState($intInput) {
        if($intInput > 0) {
            $strReturn = '<span style="color: #00aa00">Online</span> (Channel: 1-' . $intInput . ')';
        }
        else {
            $strReturn = 'Offline';
        }
        return $strReturn;
    }

	function RepStr($string){
		return preg_replace("/[^0-9a-zA-Z]/","",$string);
	}

	function getChannel($ch){
		return 'Channel '.$ch;
	}
	
	function getColor($a, $b){
		if( $a == 'F' )
			return '<font color="black">'.$b.'</font>';
		else if( $a == 'L' )
			return '<font color="red"><b>[Supporter] '.$b.'</b></font>';
		else if( $a == 'M' )
			return '<font color="red"><b>[GM] '.$b.'</b></font>';
		else if( $a == 'N' )
			return '<font color="red"><b>[Head-GM] '.$b.'</b></font>';
		else if( $a == 'P' )
			return '<font color="red"><b>[Admin] '.$b.'</b></font>';
		else if( $a == 'Z' )
			return '<font color="red"><b>[Admin] '.$b.'</b></font>';
	}
	
	function getColor2($a, $b){
		if( $a == 'F' )
			return '<font color="black">'.$b.'</font>';
		else if( $a == 'L' )
			return '<font color="darkgold"><b>'.$b.'</b></font>';
		else if( $a == 'M' )
			return '<font color="red"><b>'.$b.'</b></font>';
		else if( $a == 'N' )
			return '<font color="red"><b>'.$b.'</b></font>';
		else if( $a == 'P' )
			return '<font color="red"><b>'.$b.'</b></font>';
		else if( $a == 'Z' )
			return '<font color="red"><b>'.$b.'</b></font>';
	}
	
	function getAccounts(){
		global $odbc_connect, $_CONFIG;
		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
		$count = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL]');
		return odbc_num_rows($count);
	}

	function getNonActivateAccounts(){
		global $odbc_connect, $_CONFIG;
		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['acc'] . ']');
		$count = odbc_exec($odbc_connect, 'SELECT * FROM [ACCOUNT_TBL_VALIDATE]');
		return odbc_num_rows($count);
	}
	
	function getjob($jobid) {
		switch($jobid) {
			case 0: $jobname = 'Vagrant'; break;
			case 1: $jobname = 'Mercenary'; break;
			case 2: $jobname = 'Assist'; break;
			case 3: $jobname = 'Acrobat'; break;
			case 4: $jobname = 'Magician'; break;
			case 5: $jobname = 'Puppeter'; break;
			case 6: $jobname = 'Knight'; break;
			case 7: $jobname = 'Blade'; break;
			case 8: $jobname = 'Jester'; break;
			case 9: $jobname = 'Ranger'; break;
			case 10: $jobname = 'Ringmaster'; break;
			case 11: $jobname = 'Billposter'; break;
			case 12: $jobname = 'Psykeeper'; break;
			case 13: $jobname = 'Elementor'; break;
			case 14: $jobname = 'Gatekeeper'; break;
			case 15: $jobname = 'Doppler'; break;
			case 16: $jobname = 'Master Knight'; break;
			case 17: $jobname = 'Master Blade'; break;
			case 18: $jobname = 'Master Jester'; break;
			case 19: $jobname = 'Master Ranger'; break;
			case 20: $jobname = 'Master Ringmaster'; break;
			case 21: $jobname = 'Master Billposter'; break;
			case 22: $jobname = 'Master Psykeeper'; break;
			case 23: $jobname = 'Master Elementor'; break;
			case 24: $jobname = 'Hero Knight'; break;
			case 25: $jobname = 'Hero Blade'; break;
			case 26: $jobname = 'Hero Jester'; break;
			case 27: $jobname = 'Hero Ranger'; break;
			case 28: $jobname = 'Hero Ringmaster'; break;
			case 29: $jobname = 'Hero Billposter'; break;
			case 30: $jobname = 'Hero Psykeeper'; break;
			case 31: $jobname = 'Hero Elementor'; break;
			case 32: $jobname = 'Lord Templer'; break;
			case 33: $jobname = 'Storm Blade'; break;
			case 34: $jobname = 'Wind Lurker'; break;
			case 35: $jobname = 'Crack Shooter'; break;
			case 36: $jobname = 'Florist'; break;
			case 37: $jobname = 'Force Master'; break;
			case 38: $jobname = 'Mentalist'; break;
			case 39: $jobname = 'Arcanist'; break;
			default: $jobname = 'n/a'; break;
		}
		
		return $jobname;
	}