<?php if (!defined('access')) {die("Die gesuchte Ressource wurde entfernt oder umbenannt, oder sie steht vorübergehend nicht zur Verfügung.");} ?>
<p class="page_title">
	<?php echo $_LANG['donate_siteTitle']?>
</p>
<?php	
if($_CONFIG['donate_enable'] OR in_array($_SESSION['user'],$_CONFIG['allg_svr_admins'])) {
	
	if(!empty($_SESSION['user'])) {
		$input = odbc_fetch_array(odbc_exec($odbc_connect, 'SELECT TOP 1 [account], [email] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL_DETAIL] WHERE [account] = \'' . cleanSqlInput($_SESSION['user']) . '\''));
		$inputAccountName = $input['account'];
		$inputEmail = $input['email'];
	}
	else {
		$inputAccountName = '';
		$inputEmail = '';
	}
	$strOutputErrorArray = array();
	
	if(isset($_POST['uKashSubmit']) AND ($_CONFIG['donate_ukash_enabled'] OR in_array($_SESSION['user'],$_CONFIG['allg_svr_admins']))) {

		$_POST['uKashCode'] = str_replace('.', '', $_POST['uKashCode']);

        if(isSpamming($_POST['uKashInputCheckTimestamp'], $_POST['uKashInputCheckKey'], $_SESSION['inputCheckKey'])) {
            $strOutputErrorArray[] = $_LANG['error_spam'];
        }
		if(empty($_POST['uKashAccount']) OR empty($_POST['uKashMail']) OR empty($_POST['uKashGuthaben']) OR empty($_POST['uKashCode']) or !isset($_POST['uKashCheckbox'])) {
			$strOutputErrorArray[] = $_LANG['error_fill_in_all_fields'];
		}
		if(odbc_num_rows(odbc_exec($odbc_connect, 'SELECT [account] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL] WHERE [account] = \'' . cleanSqlInput($_POST['uKashAccount']) . '\'')) < 1) {
			$strOutputErrorArray[] = $_LANG['error_no_account_with_that_name'];
		}
		if(!is_numeric($_POST['uKashCode']) OR substr($_POST['uKashCode'],0,7) != $_CONFIG['donate_ukash_code_start'] OR !in_array(substr($_POST['uKashCode'],7,2), $_CONFIG['donate_ukash_code_countries'])) {
			$strOutputErrorArray[] = $_LANG['error_donate_code_is_wrong'];
		}
		if(count($strOutputErrorArray) > 0) {
			$outputNotify = createMessage($strOutputErrorArray, 'fail');
		}
		else {
			$account = cleanSqlInput($_POST['uKashAccount']);
			$mail = cleanSqlInput($_POST['uKashMail']);
			$guthaben = cleanSqlInput($_POST['uKashGuthaben']);
			$dps = $_CONFIG['donate_ukash_values'][$guthaben];
			$key = random_string();
			$code = cleanSqlInput($_POST['uKashCode']);
			
			if(@odbc_exec($odbc_connect, '
				INSERT INTO [' . $_CONFIG['db_databases']['web'] . '].[dbo].[LOG_DONATIONS] (
					[key],
					[type],
					[state],
					[account],
					[worth],
					[points],
					[timestamp]
				) VALUES (
					\'' . $key. '\',
					2,
					0,
					\'' . $account. '\',
					' . $guthaben. ',
					' . $dps. ',
					' . time() . '
				)
			')) {
				mailDonationUserNotification($account,$mail,$guthaben,$dps,time(),$key);
				mailDonationAdminNotification($account,$mail,$guthaben,$dps,$code,time(),$key,$_LANG['donate_ukash']);
				$outputNotify = createMessage($_LANG['success_donation'], 'success', NULL, $_LANG['success_donation_title']);
			}
			else {
				$outputNotify = createMessage($_LANG['error_donation_not_in_db'], 'fail');
			}
		}
	}	
	if(isset($_POST['paysafeSubmit']) AND ($_CONFIG['donate_paysafe_enabled'] OR in_array($_SESSION['user'],$_CONFIG['allg_svr_admins']))) {

        if(isSpamming($_POST['paysafeInputCheckTimestamp'], $_POST['paysafeInputCheckKey'], $_SESSION['inputCheckKey'])) {
            $strOutputErrorArray[] = $_LANG['error_spam'];
        }
		if(empty($_POST['paysafeAccount']) OR empty($_POST['paysafeMail']) OR empty($_POST['paysafeGuthaben']) or !isset($_POST['paysafeCheckbox'])) {
			$strOutputErrorArray[] = $_LANG['error_fill_in_all_fields'];
		}
		if(@odbc_num_rows(@odbc_exec($odbc_connect, 'SELECT [account] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL] WHERE account = \'' . cleanSqlInput($_POST['paysafeAccount']) . '\'')) < 1) {
			$strOutputErrorArray[] = $_LANG['error_no_account_with_that_name'];
		}
		if($_POST['paysafeCode1'] >= 1000 OR strlen($_POST['paysafeCode1']) <> 4 OR strlen($_POST['paysafeCode2']) <> 4 OR strlen($_POST['paysafeCode3']) <> 4 OR strlen($_POST['paysafeCode4']) <> 4 OR !is_numeric($_POST['paysafeCode1'].$_POST['paysafeCode2'].$_POST['paysafeCode3'].$_POST['paysafeCode4']) OR $_POST['paysafeCode1'].$_POST['paysafeCode2'].$_POST['paysafeCode3'].$_POST['paysafeCode4'] == 1234567812345678 OR $_POST['paysafeCode1'].$_POST['paysafeCode2'].$_POST['paysafeCode3'].$_POST['paysafeCode4'] == '0123456789012345') {
			$strOutputErrorArray[] = $_LANG['error_donate_code_is_wrong'];
		}
		if(count($strOutputErrorArray) > 0) {
			$outputNotify = createMessage($strOutputErrorArray, 'fail');
		}
		else {
			
			$account = cleanSqlInput($_POST['paysafeAccount']);
			$email = cleanSqlInput($_POST['paysafeMail']);
			$wert = cleanSqlInput($_POST['paysafeGuthaben']);
			$dps = $_CONFIG['donate_paysafe_values'][$wert];
			$pscCode = cleanSqlInput($_POST['paysafeCode1']) . '-' . cleanSqlInput($_POST['paysafeCode2']) . '-' . cleanSqlInput($_POST['paysafeCode3']) . '-' . cleanSqlInput($_POST['paysafeCode4']);
			$key = random_string();
			$time = time();

			if(@odbc_exec($odbc_connect, '
				INSERT INTO [' . $_CONFIG['db_databases']['web'] . '].[dbo].[LOG_DONATIONS] (
					[key],
					[type],
					[state],
					[account],
					[worth],
					[points],
					[timestamp]
				) VALUES (
					\'' . $key. '\',
					0,
					0,
					\'' . $account. '\',
					' . $wert. ',
					' . $dps. ',
					' . $time . '
				)
			')) {
				mailDonationUserNotification($account,$email,$wert,$dps,$time,$key);
				mailDonationAdminNotification($account,$email,$wert,$dps,$pscCode,time(),$key,$_LANG['donate_paysafe']);
				$outputNotify = createMessage($_LANG['success_donation'], 'success', NULL, $_LANG['success_donation_title']);
			}
			else {
				$outputNotify = createMessage($_LANG['error_donation_not_in_db'], 'fail');
			}
		}
	}
	if(isset($_POST['paypalSubmit']) AND ($_CONFIG['donate_paypal_enabled'] OR in_array($_SESSION['user'],$_CONFIG['allg_svr_admins']))) {

        if(isSpamming($_POST['paypalInputCheckTimestamp'], $_POST['paypalInputCheckKey'], $_SESSION['inputCheckKey'])) {
            $strOutputErrorArray[] = $_LANG['error_spam'];
        }
		if(empty($_POST['paypalAccount']) OR empty($_POST['paypalMail']) OR empty($_POST['paypalGuthaben']) OR empty($_POST['paypalRealName']) OR empty($_POST['paypalRealMail']) or !isset($_POST['paypalCheckbox'])) {
			$strOutputErrorArray[] = $_LANG['error_fill_in_all_fields'];
		}
		if(@odbc_num_rows(@odbc_exec($odbc_connect, 'SELECT [account] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL] WHERE account = \'' . cleanSqlInput($_POST['paypalAccount']) . '\'')) < 1) {
			$strOutputErrorArray[] = $_LANG['error_no_account_with_that_name'];
		}
		if(count($strOutputErrorArray) > 0) {
			$outputNotify = createMessage($strOutputErrorArray, 'fail');
		}
		else {
			$key = random_string();
			$account = cleanSqlInput($_POST['paypalAccount']);
			$mail = cleanSqlInput($_POST['paypalMail']);
			$wert = cleanSqlInput($_POST['paypalGuthaben']);
			$dps = $_CONFIG['donate_paypal_values'][$wert];
			$name = cleanSqlInput($_POST['paypalRealName']);
			$email = cleanSqlInput($_POST['paypalRealMail']);
			
			if(@odbc_exec($odbc_connect, '
				INSERT INTO [' . $_CONFIG['db_databases']['web'] . '].[dbo].[LOG_DONATIONS] (
					[key],
					[type],
					[state],
					[account],
					[worth],
					[points],
					[timestamp],
					[fieldAlfa],
					[fieldBravo]
				) VALUES (
					\'' . $key. '\',
					1,
					0,
					\'' . $account. '\',
					' . $wert. ',
					' . $dps. ',
					' . time() . ',
					\'' . $name . '\',
					\'' . $email . '\'
				)
			')) {
			mailDonationUserNotification($account,$mail,$wert,$dps,time(),$key);
			mailDonationAdminNotification($account,$mail,$wert,$dps,'-',time(),$key,$_LANG['donate_paypal'],$name,$email);
			$outputNotify = createMessage($_LANG['success_donation'], 'success', NULL, $_LANG['success_donation_title']);
		}
		else {
			$outputNotify = createMessage($_LANG['error_donation_not_in_db'], 'fail');
		}
	}
}

	echo '<h2>' . $_LANG['general_plu'] . '  ' . $_LANG['information_plu'] . '</h2>
<p><br>
	' . $_LANG['donate_information_text'] . '
</p>
<br />
<h2>' . $_LANG['donate_table'] . '</h2>
<div class="table">
	<div class="thead">
		<div class="tr">
			<div class="p10 center">&nbsp;</div>
			<div class="p30 center">UKash</div>
			<div class="p30 center">Paysafe</div>
			<div class="p30 center">Paypal</div>
		</div>
	</div>
	<div class="tbody">';
	
	$arrayKeys = getAllDonateValues();
	
	for($iterator = 0; $iterator < count($arrayKeys); $iterator++) {
		$currencyValue = $arrayKeys[$iterator];
		
		echo '
		<div class="tr">
			<div class="p10 center">' . $currencyValue  . ' ' . $_CONFIG['web_currencies']['real']['symbol'] . '</div>
			<div class="p30 center">' . getDonateValueOutput($_CONFIG['donate_ukash_values'], $currencyValue) . '</div>
			<div class="p30 center">' . getDonateValueOutput($_CONFIG['donate_paysafe_values'], $currencyValue) . '</div>
			<div class="p30 center">' . getDonateValueOutput($_CONFIG['donate_paypal_values'], $currencyValue) . '</div>
		</div>
		';
	}
echo '
		<div class="tr">
			<div class="p10 center">&nbsp;</div>
			<div class="p30 center">' . checkBooleanState($_CONFIG['donate_ukash_enabled']) . '</div>
			<div class="p30 center">' . checkBooleanState($_CONFIG['donate_paysafe_enabled']) . '</div>
			<div class="p30 center">' . checkBooleanState($_CONFIG['donate_paypal_enabled']) . '</div>
		</div>
	</div>
</div>
<br />
' . $outputNotify . '';

	if($_CONFIG['donate_ukash_enabled']) {
		echo '
<hr class="clear" />
<h3>' . $_LANG['donate_ukash'] . '</h3>
<a onclick="javascript:switching(\'uKash\');" class="weiterleitung nound">' . $_LANG['donate_open_form'] . '</a>
<p>
	' . $_LANG['donate_ukash_information'] . '
</p>
<form method="post" id="uKash" class="formDonation">
	<input type="hidden" name="uKashInputCheckTimestamp" value="' . time() . '" />
	<input type="hidden" name="uKashInputCheckKey" value="' . random_string() . '" />
	<input type="text" id="uKashAccount"name="uKashAccount" class="account" value="' . $inputAccountName . '" required="required" placeholder="' . $_LANG['account'] . '"/>		<label class="w170" for="uKashAccount">' . $_LANG['account'] . '</label><br style="clear:both;" />
	<input type="email" id="uKashMail" name="uKashMail" class="email" value="' . $inputEmail . '" required="required" placeholder="' . $_LANG['mail'] . '"/>					<label class="w170" for="uKashMail">' . $_LANG['mail'] . '</label><br style="clear:both;" />
	<select name="uKashGuthaben" class="small" required="required">
		<option value=""></option>';
		foreach($_CONFIG['donate_ukash_values'] as $betrag => $dps) {echo '<option value="'.$betrag.'">'.$betrag.' ' . $_CONFIG['web_currencies']['real']['name'] . ' / '.$dps.' ' . $_CONFIG['web_currencies']['donate']['name'] . '</option>';}
		echo '	
	</select><label class="w170" for="uKashGuthaben">' . $_LANG['value'] . '</label><br style="clear:both;" />
	<input type="number" id="uKashCode" name="uKashCode" class="donate" required="required"/>											<label class="w170" for="uKashCode">' . $_LANG['donate_ukash'] . ' ' . $_LANG['code'] . '</label><br style="clear:both;" />
	<input type="checkbox" id="uKashCheckbox" name="uKashCheckbox" style="float:left; margin:15px 10px;" required="required"/>			<label style="width:350px;" for="uKashCheckbox">' . $_LANG['donate_promise'] . '.</label><br style="clear:both;" /><br />
	<input type="submit" name="uKashSubmit" value="' . $_LANG['donate_using'] . ' ' . $_LANG['donate_ukash'] . '" class="button_235" style="margin:5px 25%;"/>
</form>';
	}
	if($_CONFIG['donate_paysafe_enabled']) {
		echo '
<hr class="clear" />
<h3>' . $_LANG['donate_paysafe'] . '</h3>
<a onclick="javascript:switching(\'Paysafe\');" class="weiterleitung nound">' . $_LANG['donate_open_form'] . '</a>
<p>
	' . $_LANG['donate_paysafe_information'] . '
</p>

<form method="post" id="Paysafe" class="formDonation">
	<p class="hint nomar nopad">' . $_LANG['donate_paysafe_hint'] . '</p>
	<input type="hidden" name="paysafeInputCheckTimestamp" value="' . time() . '" />
	<input type="hidden" name="paysafeInputCheckKey" value="' . random_string() . '" />
	<input type="text" id="paysafeAccount" name="paysafeAccount" class="account" value="' . $inputAccountName . '" placeholder="' . $_LANG['account'] . '" required="required"/>		<label class="w170" for="paysafeAccount">' . $_LANG['account'] . '</label><br class="clear" />
	<input type="email" id="paysafeMail" name="paysafeMail" class="email" value="' . $inputEmail . '" placeholder="' . $_LANG['mail'] . '" required="required"/>				<label class="w170" for="paysafeMail">' . $_LANG['mail'] . '</label><br class="clear" />
	<select id="paysafeGuthaben" name="paysafeGuthaben" class="small" required="required">
		<option value=""></option>';
		foreach($_CONFIG['donate_paysafe_values'] as $betrag => $dps) {echo '<option value="'.$betrag.'">'.$betrag.' ' . $_CONFIG['web_currencies']['real']['name'] . ' / '.$dps.' ' . $_CONFIG['web_currencies']['donate']['name'] . '</option>';}
		echo '	
	</select><label class="w170" for="paysafeGuthaben">' . $_LANG['value'] . '</label><br class="clear" />
	<input name="paysafeCode1" type="number" maxlength="4" class="w030" placeholder="1234" required="required" id="paysafeCode1"/>
	<input name="paysafeCode2" type="number" maxlength="4" class="w030" placeholder="5678" required="required"/>
	<input name="paysafeCode3" type="number" maxlength="4" class="w030" placeholder="1234" required="required"/>
	<input name="paysafeCode4" type="number" maxlength="4" class="w030" placeholder="5678" required="required"/>

	<label class="w170" for="paysafeCode1">' . $_LANG['donate_paysafe'] . ' ' . $_LANG['code'] . '</label><br class="clear" />
	<input type="checkbox" id="paysafeCheckbox" name="paysafeCheckbox" style="float:left; margin:15px 10px;" required="required"/>			<label for="paysafeCheckbox" style="width:360px;">' . $_LANG['donate_promise'] . '.</label><br class="clear" />
	<input type="submit" name="paysafeSubmit" value="' . $_LANG['donate_using'] . ' ' . $_LANG['donate_paysafe'] . '" class="button_235" style="margin:5px 25%;"/>
</form>';
	}
	if($_CONFIG['donate_paypal_enabled']) {
		echo '
<hr class="clear" />
<h3>' . $_LANG['donate_paypal'] . '</h3>
<a onclick="javascript:switching(\'Paypal2\');" class="weiterleitung nound">' . $_LANG['donate_open_form'] . '</a>
<p>
	' . $_LANG['donate_paysafe_information'] . '
</p>';
		echo '
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="Paypal2" class="formDonation" style="text-align:center;" target="_blank">
	<p class="hint nomar nopad">' . $_LANG['donate_paypal_hint'] . '</p>
	<input type="hidden" name="cmd" value="_s-xclick">
	<input type="hidden" name="hosted_button_id" value="TTG4ZNX3KNMZW">
	<input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donate_LG.gif" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal." onclick="javascript:switching(\'Paypal1\');">
	<img alt="" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
<form method="post" id="Paypal1" class="formDonation">
	<input type="hidden" name="paypalInputCheckTimestamp" value="' . time() . '" />
	<input type="hidden" name="paypalInputCheckKey" value="' . random_string() . '" />
	<input type="text" id="paypalAccount" name="paypalAccount" class="account" value="' . $inputAccountName . '" placeholder="' . $_LANG['account'] . '" required="required"/>	<label class="w170" for="paypalAccount">' . $_LANG['account'] . ' :</label><br style="clear:both;" />
	<input type="email" id="paypalMail" name="paypalMail" class="email" value="' . $inputEmail . '" placeholder="' . $_LANG['mail'] . '" required="required"/>				<label class="w170" for="paypalMail">' . $_LANG['mail'] . ' :</label><br style="clear:both;" />
	<select id="paypalGuthaben" name="paypalGuthaben" class="small" required="required">
		<option value=""></option>';
		foreach($_CONFIG['donate_paypal_values'] as $betrag => $dps) {echo '<option value="'.$betrag.'">'.$betrag.' ' . $_CONFIG['web_currencies']['real']['name'] . ' / '.$dps.' ' . $_CONFIG['web_currencies']['donate']['name'] . '</option>';}
		echo '	
	</select><label class="w170" for="paypalGuthaben">' . $_LANG['value'] . '</label><br style="clear:both;" />
	<input type="text" id="paypalRealName" name="paypalRealName" class="account" placeholder="' . $_LANG['donate_paypal'] . ' ' . $_LANG['name'] . '" required="required"/>		<label class="w170" for="paypalRealName">' . $_LANG['donate_paypal'] . ' ' . $_LANG['name'] . '</label><br style="clear:both;" />
	<input type="email" id="paypalRealMail" name="paypalRealMail" class="email" placeholder="' . $_LANG['donate_paypal'] . ' ' . $_LANG['mail'] . '" required="required"/>		<label class="w170" for="paypalRealMail">' . $_LANG['donate_paypal'] . ' ' . $_LANG['mail'] . '</label><br style="clear:both;" /><br />
	<input type="checkbox" id="paypalCheckbox" name="paypalCheckbox" style="float:left; margin:15px 10px;" required="required"/>		<label style="width:360px;" for="paypalCheckbox">' . $_LANG['donate_promise'] . ' ' . $_LANG['donate_promise_paypaladdition'] . '</label><br style="clear:both;" /><br />
	<input type="submit" name="paypalSubmit" value="' . $_LANG['donate_using'] . ' ' . $_LANG['donate_paypal'] . '" class="button_235" style="margin:5px 25%;"/>
</form>';
	}
}
else {
	echo createMessage($_LANG['notify_donate_deactivated'], 'hint');
}