<?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{
	$gapicfg=json_decode(file_get_contents(__DIR__.'/config.json'),true);
	if ($app->getPost('update')){
		$gapicfg['client_id']=$app->getPost('client_id');
		$gapicfg['client_secret']=$app->getPost('client_secret');
		file_put_contents(__DIR__.'/config.json',json_encode($gapicfg));
	}
	$app->heads('GoogleAPI Configuration');
	$app->header();
?>
<section>
	<article>
		<h1 class='article'>GoogleAPI Configuration</h1>
		<form method='post' class='tall'>
			<h5>Credentials for App in Google Console</h5>
			<article style='display:inline-block;width:auto;'>
				<p>Client ID
					<input type='text' name='client_id' placeholder='client_id' value='<?php echo $gapicfg['client_id']; ?>' />
				</p>
				<p>Client Secret
					<input type='text' name='client_secret' placeholder='client_secret' value='<?php echo $gapicfg['client_secret']; ?>' />
				</p>
			</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();
}
?>
