<?php
/*****************************************************************************
 * LogInForm.php
 * Contains the login form template.
 *
 * Kabuki CMS (C) 2013-2015, Aaron van Geffen
 *****************************************************************************/

class LogInForm extends SubTemplate
{
	private $redirect_url = '';
	private $emailaddress = '';

	protected $_class = 'content-box container col-lg-6';

	public function setRedirectUrl($url)
	{
		$this->redirect_url = $url;
	}

	public function setEmail($addr)
	{
		$this->emailaddress = htmlspecialchars($addr);
	}

	protected function html_content()
	{
		if (!empty($this->_title))
			echo '
						<h1 class="mb-4">Press #RU to continue</h1>';

		if (!empty($this->_subtemplates))
		{
			foreach ($this->_subtemplates as $template)
				$template->html_main();
		}

		echo '
						<form class="mt-4" action="', BASEURL, '/login/" method="post">
							<div class="row">
								<label class="col-sm-3 col-form-label" for="field_emailaddress">E-mail address:</label>
								<div class="col-sm">
									<input type="text" class="form-control" id="field_emailaddress" name="emailaddress" value="', $this->emailaddress, '">
								</div>
							</div>
							<div class="row mt-3">
								<label class="col-sm-3 col-form-label" for="field_password">Password:</label>
								<div class="col-sm">
									<input type="password" class="form-control" id="field_password" name="password">
								</div>
							</div>';

		// Throw in a redirect url if asked for.
		if (!empty($this->redirect_url))
			echo '
							<input type="hidden" name="redirect_url" value="', base64_encode($this->redirect_url), '">';

		echo '
							<div class="mt-4">
								<div class="offset-sm-3 col-sm-9">
									<button type="submit" class="btn btn-primary">Sign in</button>
									<a class="btn btn-light" href="', BASEURL, '/resetpassword/" style="margin-left: 1em">Forgotten your password?</a>
								</div>
							</div>
						</form>';
	}
}