<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
// BotBanish 7.1.06
// Randem Systems: https://randemsystems.support
// BotBanish Website Settings Configuration
// Date: 04/11/2026
// Usage: https://userdomain.com/BotBanish/bot/Subs/BotBanish_SettingsScreen.php
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

	$info = BotBanishGetSystemType();
	$type = $info['type'];

	define('BOTBANISH_SYSTEM', $type);

	if (!defined($type))
		define($type, 1);

	$location = substr($_SERVER['SCRIPT_FILENAME'], 0, strripos($_SERVER['SCRIPT_FILENAME'], '/') + 1);
	$filename = realpath($location . '../Include/BotBanish_PreIncludes.php');

	if (!file_exists($filename))
		exit;

	require_once $filename;
	
	require_once $BotBanishSettings['BOTBANISH_SUBS_DIR'] . 'BotBanish_Subs_Screen.php';
	require_once $BotBanishSettings['BOTBANISH_SUBS_DIR'] . 'BotBanish_Subs_FormInput.php';

	$system = BotBanishCheckSystem();
	$type = $system['system'];

	$options = BotBanishGetOptionVars('WEBSITE');
	$title = $BotBanishSettings['BOTBANISH_VERSION'] . ' ';
	$screenData = getScreenData($options);
	$screenData = array_merge($screenData, array('BOTBANISH_POST_CODE' => 0, 'BOTBANISH_SYSTEM' => $system));

	// Save the posted values

	if (isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] === 'POST'))
		BotBanishSettingsTablePutValues($screenData);

	BotBanishSetLanguage($BotBanishSettings['BOTBANISH_LANGUAGE_SELECT']);

	DisplaySettingsScreen($title);

function BotBanishGetSystemType() {
	
	$info = array();
	
	if (isset($_POST['BOTBANISH_POST_CODE'])) {
		
		$info = BotBanishSaveInfo();
	
	} else {
		
		$method = isset($_POST) && !empty($_POST) ? $_POST : $_GET;

		if (!isset($method['system']) || empty($method['system'])) {

			echo 'Must have system parameter (SMF / WORDPRESS / WEBSITE / SERVER)';
			exit;
		}
	
		$type = isset($method['system']) ? $method['system'] : 'website';
		$info['type'] = strtoupper($type);
	}
	
	return $info;
}

function getScreenData($options) {

	global $BotBanishSettings;

	$screenData = array();

	if ($_SERVER['REQUEST_METHOD'] === 'POST') {

		foreach ($_POST as $key => $value) {

			$screenData[$key] = $value;
			BotBanishDefineGlobals($key, $value);
		}

	} else {

		foreach ($options as $option) {

			$name = $option['name'];
			$screenData[$name] = $BotBanishSettings[$name];
			BotBanishDefineGlobals($screenData[$name], $BotBanishSettings[$name]);
		}
	}
	
	return $screenData;
}

function DisplaySettingsScreen($title) {

//============================================================================
// Client side settings
//============================================================================

	global $BotBanishSettings, $BotBanishText, $screenData, $options, $system;

echo '
<!DOCTYPE html>
<html lang="en">
<head>
<title>' . $BotBanishText["BotBanish_Configuration"] . '</title>' .
$BotBanishSettings['BOTBANISH_PAGE_HEADER'] .
'</head>';

	$heading = $BotBanishText['BotBanish_Configuration'];
	include $BotBanishSettings['BOTBANISH_TEMPLATES_DIR'] . 'BotBanish_Banner.php';

	$color = 'background-color: ' . $BotBanishSettings['BOTBANISH_COLOR']['BrightBlue'] . ';';

	echo '
	<div>
		<table style="table-layout: fixed;" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
			<tr width="100%">
				<td width="100%" class="face_padding_cell">';

					echo '
					<form name="theForm" id="theForm" action="" method="post" enctype="multipart/form-data">
					<input type="hidden" id="BOTBANISH_CONFIGURATION" name="BOTBANISH_CONFIGURATION" value="' . $BotBanishSettings['BOTBANISH_CONFIGURATION'] .'">
					<input type="hidden" id="BOTBANISH_POST_CODE" name="BOTBANISH_POST_CODE" value="' . $screenData['BOTBANISH_POST_CODE'] . '">
					<input type="hidden" id="BOTBANISH_SYSTEM" name="BOTBANISH_SYSTEM" value="' . $BotBanishSettings['BOTBANISH_SYSTEM'] . '">

						<table style="table-layout: fixed; '. $color . ' border-collapse:collapse;" border="10" width="65%" align="center">';

						$last_section = '';

						foreach ($options as $option) {

							$str = BotBanishGetOptionInputInfo($option, 'theForm');

							if (BotBanishSkipOption($system['system'], $option['name'], $option))
							continue;

							if (isset($option['section']) && ($option['section'] != $last_section)) {

								echo '
									</table>
									<table style="table-layout: fixed; '. $color . ' border-collapse:collapse; border="0" width="65%" align="center">
										<tr>
											<td style="width: 100%; text-align: center;">
										
												<div style="vertical-align: top; overflow-wrap: break-all; white-space:normal; ' . $color . ' width: 100%; height: 30px; border-bottom: 2px solid black; text-align: center">
												  <span style="font-size: 25px; padding: 0 10px;">
													<b>' . $option['section'] . '
												  </span>
												</div>
										
											</td>
										</tr>
									</table>

									<table style="table-layout: fixed; '. $color . ' border-collapse:collapse;" border="10" width="65%" align="center">';

								$last_section = $option['section'];
							}

						echo '
							<tr style="width: 100%;">
								<td style="vertical-align: top; overflow-wrap: break-all; white-space:normal; ' . $color . ' text-align: right; width: 35%;";>
									' . $BotBanishText[$option['name']] . ':
								</td>
								<td style="text-align: left; width: 55%;">' . $str . '</td>
							</tr>
							';
						}

					echo '
						</table>';
						BotBanishSubmitButton();
					echo '
					</form>
				</td>
			</tr>
		</table>';

	echo '
		<script>';
	require $BotBanishSettings['BOTBANISH_INCLUDE_DIR'] . 'BotBanish.js';
	echo '
		</script>
	</body>
</html>';
}

function BotBanishSubmitButton() {

	global $BotBanishText;

	echo '
	</div>
	<div width="100%" align="center">
		<table width="40%">
			<tr>
				<td class=botbanish_button align="left">
					 <button type="submit" id="button">' . $BotBanishText['save'] . '</button>
				</td>
			</tr>
		</table>
	</div>';
}

function BotBanishGetOptionInputInfo($option, $theForm) {

	global $BotBanishSettings, $BotBanishText;

	$name = $option['name'];
	$readonly = isset($option['readonly']) && $option['readonly'] ? ' readonly disabled ' : '';

	switch ($option['type']) {

		case 'boolval':

			$str = DisplayCheckbox($name, $BotBanishSettings[$name], $readonly . 'value="' . $BotBanishSettings[$name] . '"');
			break;

		case 'text':

			$str = DisplayTextInputField($name, $option['size'], '', $BotBanishSettings[$name], $readonly);
			break;

		case 'large_text':

			$str = DisplayCommentInputField($name, $option['rows'], $option['cols'], $BotBanishSettings[$name], $readonly);
			break;

		case 'select':

			$str = select_droplist($name, $BotBanishSettings[$option['items']], 'onSubmit1(' . $theForm . ', BOTBANISH_POST_CODE)' . $readonly, '', $option['pct']);
			break;

		case 'number':

			$str = DisplayNumberInputField($name, $option['size'], '', $BotBanishSettings[$name], 'min="' . $option['min'] . '" max="' . $option['max'] . '"' . $readonly);
			break;
	}

	return $str;
}

function BotBanishSaveInfo() {
	
	foreach ($_POST as $key => $value) {
		
		if (stripos($key, 'BOTBANISH') !== false)
			$dataArray[$key] = $value;
	}

	$type = isset($_POST['BOTBANISH_SYSTEM']) ? $_POST['BOTBANISH_SYSTEM'] : 'WEBSITE';
	
	return array('type' => $type, 'data' => $dataArray);
}
?>