<?php $root=$_SERVER['DOCUMENT_ROOT'];$wroot=dirname($_SERVER['SCRIPT_NAME']);while((strlen($wroot)>1)&&(!file_exists($root.$wroot.'/main')))$wroot=dirname($wroot);if($wroot=='/')$wroot='';require_once($root.$wroot.'/main/app/App.php');
if (!$app->privileged('admin')) $app->nopage('This page can only be accessed by admins.');
else{
	$ppcfg=json_decode(file_get_contents(__DIR__.'/config.json'),true);
	if ($app->getPost('update')){
		$ppcfg['livemode']=$app->getPost('livemode');
		$ppcfg['sbox_clientId']=$app->getPost('sbox_clientId');
		$ppcfg['sbox_clientSecret']=$app->getPost('sbox_clientSecret');
		$ppcfg['live_clientId']=$app->getPost('live_clientId');
		$ppcfg['live_clientSecret']=$app->getPost('live_clientSecret');
		file_put_contents(__DIR__.'/config.json',json_encode($ppcfg));
	}
	$app->heads('PayPal Configuration');
	$app->header();
?>
<section>
	<article>
		<h1 class='article'>PayPal Configuration</h1>
		<form method='post' class='tall'>
			<article style='display:inline-block;'>
				<h3>Sandbox/Live</h3>
				<input type='range' class='boolean' name='livemode' min='0' max='1' step='1' value=<?php if ($ppcfg['livemode']) echo "'1'"; else echo "'0'"; ?> />
				<p class='center'><?php echo $ppcfg['livemode']?"live":"sandbox"; ?> mode</p>
			</article>
			<br/>
			<article style='display:inline-block;width:auto;'>
				<h5>Sandbox Credentials</h5>
				<input type='text' name='sbox_clientId' placeholder='clientId' value='<?php echo $ppcfg['sbox_clientId']; ?>' />
				<input type='text' name='sbox_clientSecret' placeholder='clientSecret' value='<?php echo $ppcfg['sbox_clientSecret']; ?>' />
				<h5>Live Credentials</h5>
				<input type='text' name='live_clientId' placeholder='clientId' value='<?php echo $ppcfg['live_clientId']; ?>' />
				<input type='text' name='live_clientSecret' placeholder='clientSecret' value='<?php echo $ppcfg['live_clientSecret']; ?>' />
			</article>
			<p class='center'>
				<input class='center' style='display:inline-block;' name='update' type='submit' value='Use these Settings' />
			</p>
		</form>
	</article>
</section>
<?php
	$app->footer();
	$app->tails();
}
?>
