
<?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['regist_siteTitle']; ?></p>

<?php
	if(isset($_POST['registSubmit'])) {
		$account = cleanSqlInput($_POST['registAccountID']);
		$pass1 = cleanSqlInput($_POST['registPassword']);
		$pass2 = cleanSqlInput($_POST['registPasswordRepeat']);
		$email = cleanSqlInput($_POST['registMail']);
		$email2 = cleanSqlInput($_POST['registMailRepeat']);
		$provider = preg_replace("^(.*?)@(.*?)^", "$2", $email);
		$gefra = cleanSqlInput($_POST['registSecretQuestion']);
		$geant = cleanSqlInput($_POST['registSecretAnswer']);
		$birthday = cleanSqlInput($_POST['registBirthday']);
		$md5pw = md5($_CONFIG['allg_svr_salt'].$pass1);
		$strOutputErrorArray = array();
		$accountcheck1 = @odbc_num_rows(@odbc_exec($odbc_connect, 'SELECT [account] FROM [' . $_CONFIG['db_databases']['acc'] . '].[dbo].[ACCOUNT_TBL] WHERE account = \''.$account.'\''));
		$accountcheck2 = @odbc_num_rows(@odbc_exec($odbc_connect, 'SELECT [account] FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] WHERE [type] = 0 AND [account] = \''.$account.'\''));



		if(!$_CONFIG['registration_enabled']) {
			$strOutputErrorArray[] = $_LANG['error_registration_disabled'];
		}
        if(isSpamming($_POST['inputCheckTimestamp'], $_POST['inputCheckKey'], $_SESSION['inputCheckKey'])) {
            $strOutputErrorArray[] = $_LANG['error_spam'];
        }
		if(empty($account) or empty($pass1) or empty($pass2) or empty($email) or empty($email2) or empty($gefra) or empty($geant) or empty($birthday)) {
			$strOutputErrorArray[] = $_LANG['error_fill_in_all_fields'];
		}
		if(!isset($_POST['registCheckbox'])) {
			$strOutputErrorArray[] = $_LANG['error_confirm_reading_rules'];
		}
		if($accountcheck1 > 0 OR $accountcheck2 > 0) {
			$strOutputErrorArray[] = $_LANG['error_accountname_is_taken'];
		}
		if((strlen($account) > 16) || (strlen($account) < 3)) {
			$strOutputErrorArray[] = $_LANG['error_account_length'];
		}
		if ($account != preg_replace ("/[^A-Za-z0-9]/", "", $account)) {
			$strOutputErrorArray[] = $_LANG['error_no_special_characters_account'];
		}
		if((strlen($pass1) > 16) || (strlen($pass1) < 6)) {
			$strOutputErrorArray[] = $_LANG['error_password_length'];
		}
		if($pass1 != $pass2) {
			$strOutputErrorArray[] = $_LANG['error_passwords_indistinguishable'];
		}
		if($geant != preg_replace('/[^A-Za-z0-9 ]/', '', $geant)) {
			$strOutputErrorArray[] = $_LANG['error_no_special_characters_secret_answer'];
		}
		if(strtolower($email) != strtolower($email2)) {
			$strOutputErrorArray[] = $_LANG['error_mails_indistinguishable'];
		}
        if(!preg_match('/^[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+\.[a-zA-Z]{2,4}$/', $email)) {
            $strOutputErrorArray[] = $_LANG['error_mail_must_be_valid'];
        }
		if(in_array($provider, $_CONFIG['web_mail_provider'])) {
			$strOutputErrorArray[] = $_LANG['error_spam_provider'];
		}
		if(!strtotime($birthday)) {
			$strOutputErrorArray[] = $_LANG['error_valid_birthday'];
		}
		if(count($strOutputErrorArray) > 0) {
			echo createMessage($strOutputErrorArray, 'fail');
		}
		else {
			$key = random_string();
			mailRegistration($email, $account, $pass1, $_CONFIG['allg_secretquestions'][$gefra], $geant, date($_CONFIG['web_date_format']['date'], strtotime($birthday)), $key);
			@odbc_exec($odbc_connect, '
				INSERT INTO [' . $_CONFIG['db_databases']['web'] . '].[dbo].[VALIDATE] (
					[key],
					[type],
					[account],
					[timestamp],
					[fieldAlfa],
					[fieldBravo],
					[fieldCharlie],
					[fieldDelta],
					[fieldEcho],
					[fieldFoxtrot]
				) VALUES (
					\'' . $key . '\',
					0,
					\''.$account.'\',
					\''.time().'\',
					\''.$email.'\',
					\''.$md5pw.'\',
					\''.md5($_CONFIG['security_secretAnswerSalt'].$geant).'\',
					\''.date($_CONFIG['web_date_format']['date'], strtotime($birthday)).'\',
					'.$gefra.',
					\''.$_SERVER['REMOTE_ADDR'].'\'
				)
			');

			echo createMessage($_LANG['success_registration'], 'success');
		}
	}
	else {
		if($_CONFIG['registration_enabled']) {
			echo createMessage($_LANG['notify_registration'], 'hint');
		}
		else {
			echo createMessage($_LANG['error_registration_disabled'], 'fail');
		}
	}
?>
<form method="post"><br />
	<input type="hidden" name="inputCheckTimestamp" value="<?php echo time();?>" />
	<input type="hidden" name="inputCheckKey" value="<?php echo random_string();?>" />
<fieldset>
	<legend><?php echo $_LANG['regist_account_information_subTitle']; ?></legend>
	<input type="text" name="registAccountID" id="registAccountID" maxlength="16" placeholder="<?php echo $_LANG['account']; ?>" required="required"/><label class="labelRegistration" for="registAccountID"><?php echo $_LANG['account']; ?> :</label><br />
	<input type="password" name="registPassword" id="registPassword" placeholder="<?php echo $_LANG['password']; ?>" required="required"/> <input type="password" name="registPasswordRepeat" id="registPasswordRepeat" class="password" placeholder="<?php echo $_LANG['repeat_password']; ?>" required="required"/><label class="labelRegistration" for="registPassword"><?php echo $_LANG['password']; ?> :</label><br />
</fieldset>
<br />
<fieldset>
	<legend><?php echo $_LANG['regist_security_subTitle']; ?></legend>
	<input type="email" name="registMail" id="registMail" class="email" placeholder="e.mail@e-mail.com" required="required"/> <input type="email" name="registMailRepeat" id="registMailRepeat" class="email" placeholder="<?php echo $_LANG['mail_repeat']; ?>" required="required"/><label class="labelRegistration" for="registMail"><?php echo $_LANG['mail']; ?> :</label>
	<input type="text" name="registBirthday" id="registBirthday" class="birthday" placeholder="<?php echo $_LANG['birthday']; ?>" required="required"/><label class="labelRegistration" for="registBirthday"><?php echo $_LANG['birthday']; ?> :</label><br />
	<select name="registSecretQuestion" id="registSecretQuestion" class="frage" required="required">
		<option value="" selected="selected"></option>
		<?php 
		foreach($_CONFIG['allg_secretquestions'] as $id => $frage) {
			echo '<option value="'.$id.'" >'.$frage.'</option>';
		}
		?>
	</select><label class="labelRegistration" for="registSecretQuestion"><?php echo $_LANG['secret_question']; ?> :</label><br />
	<input type="text" name="registSecretAnswer" id="registSecretAnswer" class="antwort" placeholder="<?php echo $_LANG['secret_answer']; ?>" required="required"/><label class="labelRegistration" for="registSecretAnswer"><?php echo $_LANG['secret_answer']; ?> :</label>
</fieldset>
<br />
<fieldset>
	<legend><?php echo $_LANG['regist_rules_subTitle']; ?></legend>
	<input type="checkbox" name="registCheckbox" id="registCheckbox" style="margin:14px 10px;" required="required"/><label style="float:left;" for="registCheckbox"><?php echo $_LANG['regist_read_confirmation']; ?> </label><br /><br style="clear:both;"/>
</fieldset>
	<input type="submit" name="registSubmit" value="<?php echo $_LANG['button_send_registration']; ?>" class="button_235" style="margin:10px 0px 10px 190px;" />
</form>