<?php

	function mail_Rundmail($email, $title, $nachricht) {
		GLOBAL $_CONFIG;
		
		$betreff = $_CONFIG['allg_svr_name'].' :: '.$title;
		
		$header  = "MIME-Version: 1.0\r\n";
		$header .= "Content-type: text/html; charset=utf-8\r\n"; 
		$header .= "From: noreply@".$_CONFIG['allg_svr_domain']."\r\n";
		$header .= "X-Mailer: PHP/". phpversion();
		
		$textbeginn = '
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>'.$betreff.'</title>
				
				<style type="text/css" media="screen">
					<!--
					.content {width:807px; margin:20px auto 0px auto;}
						.content .top {width:807px; height:3px; background:url(\'http://sapphireflyff.de/images/structure/content/edge.png\') no-repeat 0px 0px;}
						.content .middle {width:791px; background:url(\'http://sapphireflyff.de/images/structure/content/middle.png\') repeat-y; padding:5px 8px;}
							.content .middle .top {width:791px; height:3px; background:url(\'http://sapphireflyff.de/images/structure/content/inlay_edge.png\') no-repeat 0px 0px;}
							.content .middle .middle {width:771px; background:url(\'http://sapphireflyff.de/images/structure/content/inlay_middle.png\') repeat-y; padding:0px 10px 7px 10px;}
							.content .middle .bottom {width:791px; height:3px; background:url(\'http://sapphireflyff.de/images/structure/content/inlay_edge.png\') no-repeat 0px -3px;}
						.content .bottom {width:807px; height:3px; background:url(\'http://sapphireflyff.de/images/structure/content/edge.png\') no-repeat 0px -3px;}
						
					a, a:visited {font:14px Catriel,Verdana,sans-serif; color:#cc6600; text-shadow: #efefef 1px 1px; font-weight:normal;}
					a:hover {color:#ff7e00;}
					a:active {text-decoration:none;}
					a.nound {text-decoration:none;}
					
					td, div {font:14px Catriel,Verdana,sans-serif; color:#000000; line-height:1.4em; text-decoration: none; text-shadow: #efefef 1px 1px; font-weight:normal;}
					td.page_title {font:22px Gothic,Verdana,sans-serif; border-bottom:#c0c0c0 solid 1px; margin-bottom:20px;}
					-->
				</style>
			</head>
			<body style="background:url(\'http://sapphireflyff.de/images/backgrounds/bg.png\') repeat; margin:0px; padding:0px;">
				<center><img src="http://sapphireflyff.de/images/header/header.png" title="Sapphire Flyff" height="135" width="501"></center>
				<div class="content">
					<div class="top"></div>
						<div class="middle">
						<div class="top"></div>
						<div class="middle">
							<table width="100%" cellspacing="0" cellpadding="3">
								<tr><td align="center" class="page_title">'.$title.'</td></tr>
								<tr>
									<td>';
		$textende = '
									</td>
								</tr>
							</table>
						</div>
						<div class="bottom"></div>
					</div>
					<div class="bottom"></div>
				</div>
			</body>
		</html>';
		
		mail($email, $betreff, $textbeginn.$nachricht.$textende, $header);
		return TRUE;
	}

	function zeitUmrechnung($inputSeconds) {
	
		if($inputSeconds > 60*60*24) {
			$output = date('d.m.Y, H:i', $inputSeconds). ' Uhr';
		}
		elseif($inputSeconds > 60*60) {
			$hours = floor($inputSeconds / 3600);
			$minutes = floor(($inputSeconds / 3600 - $hours) * 60);
			$output = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($minutes, 2, '0', STR_PAD_LEFT) . ' Stunden';
		}
		elseif($inputSeconds > 60) {
			$minutes = floor($inputSeconds / 60);
			$seconds = floor(($inputSeconds / 60 - $minutes) * 60);
			$output = str_pad($minutes, 2, '0', STR_PAD_LEFT) . ':' . str_pad($seconds, 2, '0', STR_PAD_LEFT) . ' Minuten';
			
		}
		else {
			$output = str_pad($inputSeconds, 2, '0', STR_PAD_LEFT) . ' Sekunden';
		}
		
		return $output;
	}
	function paymentwall($a) {
		if($a == 199) {$a = 1.99;}
		elseif($a == 299) {$a = 2.99;}
		elseif($a == 399) {$a = 3.99;}
		elseif($a == 499) {$a = 4.99;}
		elseif($a == 500) {$a = 5.00;}
		elseif($a == 750) {$a = 5.00;}
		elseif($a == 999) {$a = 9.99;}
		elseif($a == 1000) {$a = 10.00;}
		elseif($a == 1500) {$a = 10.00;}
		elseif($a == 2700) {$a = 25.00;}
		elseif($a == 4050) {$a = 25.00;}
		elseif($a == 5600) {$a = 50.00;}
		elseif($a == 8400) {$a = 50.00;}
		elseif($a == 12000) {$a = 100.00;}
		elseif($a == 18000) {$a = 100.00;}
		else {$a == 0.01;}
		
		return $a;
	}

	function getCurrency($intCurrency) {
		if($intCurrency == 0) {
			return '<img src="../../images/icons/shop/price.png" alt="Donatepoints"/> dPs';
		}
		else {
			return '<img src="../../images/icons/shop/votepoints.png" alt="Votepoints"/> VPs';
		}
	}
function createMessage($strContent, $mode, $strAdditionalCSS = NULL, $blnDisplayTitle = TRUE) {
	global $_CONFIG;

	// Mode to class name
	if($mode == 'fail') {
		$strClassName = $_CONFIG['web_messages_types_cssClasses']['fail'];
	}
	elseif($mode == 'success') {
		$strClassName = $_CONFIG['web_messages_types_cssClasses']['success'];
	}
	else {
		$strClassName = $_CONFIG['web_messages_types_cssClasses']['hint'];
	}

	// Additional CSS
	if($strAdditionalCSS) {
		$strAdditionalCSS = 'style = "' . $strAdditionalCSS . '"';
	}

	$strTitle = '';
	if($_CONFIG['web_messages_fail_title_enabled'] AND $mode == 'fail' AND $blnDisplayTitle) {
		$strTitle = '<p class="title">Das Skript konnte nicht ausgeführt werden:</p>';
	}

	// Building up the message
	if(is_array($strContent)) {

		if(count($strContent) > 0) {
			$strMessageConstruct = '
			<div class="' . $strClassName . '">
				' . $strTitle . '
				<ol>';
			foreach($strContent as $strValue) {$strMessageConstruct .= '<li>' . $strValue . '</li>';}
			$strMessageConstruct .= '
				</ol>
			</div>';
		}
		else {
			$strMessageConstruct = '<div class="' . $strClassName . '" ' . $strAdditionalCSS . '>' . $strContent[0] . '</div>';
		}
	}
	else {
		$strMessageConstruct = '
				<div class="' . $strClassName . '" ' . $strAdditionalCSS . '>
					' . $strTitle . '
					<p>' . $strContent . '</p>
				</div>';
	}

	return $strMessageConstruct;
}

	function mssql_escape_string($string) {
		$replaced_string = str_replace("'", "''", $string);
		return $replaced_string;
	}
	
	function RepStr($string){
		return preg_replace("/[^0-9a-zA-Z]/","",$string);
	}
	
	function ReturnMsg($n){
		if($n == 0)
			return 'Nein';
		else
			return 'Ja';
	}
	
	function GetCharacterName($id){
		global $odbc_connect, $_CONFIG;
		$select = odbc_exec($odbc_connect, 'SELECT m_szName FROM [' . $_CONFIG['db_databases']['chr'] . '].[dbo].[CHARACTER_TBL] WHERE [m_idPlayer] =\''.mssql_escape_string($id).'\'');
		return odbc_result($select, 'm_szName');
	}
	function GetCharacterID($id){
		global $odbc_connect, $_CONFIG;
		$select = odbc_exec($odbc_connect, 'SELECT m_idPlayer FROM [' . $_CONFIG['db_databases']['chr'] . '].[dbo].[CHARACTER_TBL] WHERE [m_szName] =\''.mssql_escape_string($id).'\'');
		return odbc_result($select, 'm_idPlayer');
	}
	function GetAccountEmail($id){
		global $odbc_connect, $_CONFIG;
		$select = odbc_exec($odbc_connect, 'SELECT email FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL_DETAIL] WHERE [account] =\''.mssql_escape_string($id).'\'');
		return odbc_result($select, 'email');
	}
	
	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 getAuth($a){
		if($a == 'F')
			return 'Normal';
		else if($a == 'L')
			return 'Supporter';
		else if($a == 'M')
			return 'GM';
		else if($a == 'N')
			return 'Head-GM';
		else if($a == 'P')
			return 'Admin';
		else if($a == 'Z')
			return 'Developer';
	}
	
	function getSex($sex){
		if($sex == '0')
			return 'M&auml;nnlich';
		else
			return 'Weiblich';
	}
	
	function authgroup($index) {
		switch($index) {
			case 'F': $group = 'User'; break;
			case 'M': $group = 'GameMaster'; break;
			case 'N': $group = 'GameMaster'; break;
			case 'L': $group = 'GameMaster'; break;
			case 'P': $group = 'Administrator'; break;
			case 'Z': $group = 'Administrator'; break;
			default: $group = 'User'; break;
		}
		return $group;
	}
	
	function send_item($playerid, $itemid, $quantity) {
		global $odbc_connect, $_CONFIG;
		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['chr'] . ']');
		odbc_exec($odbc_connect, 'INSERT INTO [ITEM_SEND_TBL](
		m_idPlayer, serverindex, Item_Name, Item_count, idSender
		) VALUES(
		\''.mssql_escape_string($playerid).'\',
		\'01\',
		\''.mssql_escape_string($itemid).'\',
		\''.mssql_escape_string($quantity).'\',
		\'0000000\')');
	}
	
	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;
	}
	
	function ClearLoggingDatabase() {
		global $odbc_connect, $_CONFIG;
		$thisTimeStampInPast = mktime(date('H'),date('i'),date('s'),date('m'),date('d')-7,date('y'));
		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['log'] . ']');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE CHARACTER_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_BILLING_ITEM_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_CHARACTER_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_DEATH_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_GUILD_BANK_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_GUILD_DISPERSION_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_GUILD_SERVICE_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_GUILD_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_GUILD_WAR_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_HONOR_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_INS_DUNGEON_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_ITEM_EVENT_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_ITEM_REMOVE_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_ITEM_SEND_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_ITEM_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_LEVELUP_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_PK_PVP_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_QUEST_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_RESPAWN_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_SKILL_FREQUENCY_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_SVRDOWN_TBL');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE LOG_UNIQUE_TBL');
		odbc_exec($odbc_connect, 'DELETE FROM [LOG_USER_CNT_TBL] WHERE [s_date] < '.date('YmdHis', $thisTimeStampInPast).' AND [number] < 472');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblCampus_PointLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblCampusLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblChangeNameHistoryLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblChangeNameLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblGuildHouse_FurnitureLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblGuildHouseLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblLogExpBox');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblPetLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblQuestLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblQuizAnswerLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblQuizLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblQuizUserLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblSkillPointLog');
		odbc_exec($odbc_connect, 'TRUNCATE TABLE tblSystemErrorLog');
		odbc_exec($odbc_connect, 'DBCC SHRINKDATABASE (0)');
	}
	
	function ClearGuildSiegeLog(){
		global $odbc_connect, $_CONFIG;
		odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['chr'] . ']');
		odbc_exec($odbc_connect, 'DELETE FROM tblCombatInfo');
		odbc_exec($odbc_connect, 'DELETE FROM tblCombatJoinGuild');
		odbc_exec($odbc_connect, 'DELETE FROM tblCombatJoinPlayer');
		odbc_exec($odbc_connect, 'DBCC SHRINKDATABASE (0)');
	}
	// ä
?>