<?php
session_start();
define('access', true);
include_once('../../includes/xinc_detection.php');
include('../../includes/xinc_config.php');
include('inc/functions.inc.php');

	if(isset($_SESSION['user']) && (array_key_exists(@odbc_result(@odbc_exec($odbc_connect, 'SELECT [m_chLoginAuthority] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL_DETAIL] WHERE [account] = \''.mssql_escape_string($_SESSION['user']).'\''), 'm_chLoginAuthority'), $_CONFIG['allg_svr_rights']) OR in_array($_SESSION['user'], $_CONFIG['allg_svr_admins']))) {
		
			//
			// Functions - Begin
			//
			
			odbc_exec($odbc_connect, 'USE [' . $_CONFIG['db_databases']['web'] . ']');
			
			
	
			if($_GET['a'] == 'banpopup') {
				$years = array(1970,date('Y'),date('Y')+1,date('Y')+2,date('Y')+3,date('Y')+10);
				$month = array('01'=>'Januar', '02'=>'Februar', '03'=>'M&auml;rz', '04'=>'April', '05'=>'Mai', '06'=>'Juni', '07'=>'Juli', '08'=>'August', '09'=>'September',10=>'Oktober', 11=>'November', 12 =>'Dezember');
				$days = array('01','02','03','04','05','06','07','08','09',10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);

                echo 'Ban Account: <b>'.$_GET['account'].'</b> <span style="float: right;color: #f30;cursor:pointer;" onclick="$(\'#banpopup\').hide();">x</span><hr/>';
				echo '<form method="post">
						<select name="year" required="required">';
				foreach ($years as $year) 			{if(date('Y') == $year) {$selected=' selected';} else {$selected = '';} echo '<option value="'.$year.'"'.$selected.'>'.$year.'</option>';}
				echo '	</select> <select name="month" required="required">';
				foreach ($month as $month => $name) {if(date('m') == $month) {$selected=' selected';} else {$selected = '';} echo '<option value="'.$month.'"'.$selected.'>'.$name.'</option>';}
				echo '	</select> <select name="day" required="required">';
				foreach ($days as $day) 			{if(date('d') == $day) {$selected=' selected';} else {$selected = '';} echo '<option value="'.$day.'"'.$selected.'>'.$day.'</option>';}
				echo '	</select>
	                    <input name="account" type="hidden" value="' . $_GET['account'] . '"/>
						<br /><br /><input type="text" name="reason" value="" placeholder="Reason" required="required"/> <input type="submit" name="ban_submit" value="Submit" /></form>';
			}
			if($_GET['a'] == 'denyValidation') {
				@odbc_exec($odbc_connect, 'DELETE FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [key] = \''.mssql_escape_string($_GET['key']).'\'');
			}
			
			if($_GET['a'] == 'acceptValidation') {
				$key = mssql_escape_string($_GET['key']);
				$validateArray = @odbc_exec($odbc_connect, 'SELECT * FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [key] = \''.$key.'\'');
				$type = @odbc_result($validateArray, 'type');
					
				if($type == 0) {
					$account = odbc_result($validateArray, 'account');
					$pass = odbc_result($validateArray, 'fieldBravo');
					$email = odbc_result($validateArray, 'fieldAlfa');
					$gefra = odbc_result($validateArray, 'fieldEcho');
					$geant = odbc_result($validateArray, 'fieldCharlie');
					$bdate = odbc_result($validateArray, 'fieldDelta');
                    $ip = $validateSelectArray['fieldFoxtrot'];

				
					@odbc_exec($odbc_connect, 'EXEC [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[usp_createAccount] @account=\''.$account.'\', @pw=\''.$pass.'\', @email=\''.$email.'\', @gefra=\''.$gefra.'\', @geant=\''.$geant.'\', @birthday = \'' . $bdate . '\', @ip=\''.$ip.'\', @lang=\'' . $_CONFIG['web_default_lang'] . '\'');
					@odbc_exec($odbc_connect, 'DELETE FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [key] = \''.$key.'\'');
				}
				elseif($type == 'Passwort') {
					$account = odbc_result($validateArray, 'account');
					$newpw = odbc_result($validateArray, 'password');
					
					@odbc_exec($odbc_connect, 'UPDATE [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL] SET [password] = \''. md5($_CONFIG['allg_svr_salt'].$newpw) .'\' WHERE [account] = \''.$account.'\'');
					@odbc_exec($odbc_connect, 'DELETE FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [key] = \''.$key.'\'');
				}
				elseif($type == 'Mailänderung') {
					$account = odbc_result($validateArray, 'account');
					$newmail = odbc_result($validateArray, 'email');
					
					@odbc_exec($odbc_connect, 'UPDATE [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL_DETAIL] SET [email] = \''.$newmail.'\' WHERE [account] = \''.$account.'\'');
					@odbc_exec($odbc_connect, 'DELETE FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [key] = \''.$key.'\'');
				}
			}
			
			//
			// Functions - End
			//
	}
?>