<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 4/26/2010	ELL
// Added warning message about system requiring JavaScript.
// Revised: 11/16/2012	ELL
// Added sending of passwords as SHA-256 hashed.  Set focus on user ID upon body load.  Capture enter key for submitting form.
// Revised: 2/11/2013	ELL
// Added override to allow saving of password in browser.
//
	
	session_start();
	session_regenerate_id(true);
	
	include ("../connect/config.php");
	
	$server_name = $_SERVER['SERVER_NAME'];
	$script_filename = $_SERVER['SCRIPT_NAME'];
	$url = "https://" . $server_name . $script_filename;
	if (BWB_REQUIRE_SSL == 1)
	{
		//if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' || $_SERVER['SERVER_PORT'] !== 443)
		if ($_SERVER['HTTPS'] !== 'on')
			header("Location: $url");
	}
	
?>
<html>
<head>
<title>Breeze Website Builder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="manager.css" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<style type="text/css">
#login_btn	{
	width:80px;
	margin-top:5px;
}
</style>
<script language="javascript" src="js/hash.js" type="text/javascript"> </script>
<script language="javascript" type="text/javascript" src="js/browser_detect.js"></script>
<script language="javascript" type="text/javascript" src="js/mouse_position.js"></script>
<script language="javascript" type="text/javascript" src="js/popup_msg.js"></script>

<script language="javascript" type="text/javascript">
var browser = BrowserDetect.browser;
var browser_version = BrowserDetect.version;

var param_array = {'popup_msg_type' : 1, 'status_msg' : '', 'popup_timeout' : -1};
var popup_msg = new PopupMsg(param_array);

function SubmitLogin()
{
	var password = document.getElementById("password_input").value;
	var hash = Sha256.hash(password);
	document.getElementById("password").value = hash;
	if (!document.getElementById("browser_save_password").checked)
		document.getElementById("password_input").value = '';
	document.forms["formLogin"].submit();
}

function checkForEnter(e) {
	if (e.keyCode == 13) {
		SubmitLogin();	
	}
}

function WarnAboutSSL(show_warning)	{
	if (show_warning)
	{
		popup_msg.top_offset = 50;
		popup_msg.left_offset = 320;
		popup_msg.popup_msg_type = 2;
		popup_msg.popup_timeout = 30000;
		popup_msg.msg_width = 500;
		popup_msg.status_msg = "Note: For your browser to save the password, it will need to send it unencrypted this time.  To avoid this problem, try using an SSL encrypted connection (<?php echo $url; ?>).  Be sure to tell your browser to store/update your password after logging in.";
		popup_msg.ShowPopupMsg();
	}
}
</script>
</head>

<body onLoad="document.getElementById('userid').focus();">
<div align="center" id="login_logo"><img src="images/Breeze_header_logo.png" alt="Breeze Website Builder"></div>
<div id="header_divider_login">&nbsp;</div>
<form name="formLogin" method="post" action="login_verify.php">
<div align="center">
  <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="2" class="sub_title">Please enter your User ID and Password:</td>
      </tr>
      <tr>
        <td>User ID:</td>
        <td><input type="text" name="userid" id="userid" /></td>
      </tr>
      <tr>
        <td>Password:</td>
        <td>
        	<input type="password" name="password_input" id="password_input" onKeyDown="checkForEnter(event);" />
            <input type="hidden" name="password" id="password" />
        </td>
      </tr>
      <tr>
        <td>
        	<input type="checkbox" name="browser_save_password" id="browser_save_password" <?php if ($_SERVER['HTTPS'] !== 'on') echo "onChange=\"WarnAboutSSL(this.checked);\""; ?> />
        	<span class="small_message">Save log in</span>
        </td>
        <td align="right">
        <!--<input type="button" name="Submit" value="Login" onClick="SubmitLogin();" />-->
        <div class='button_console' id="login_btn" onClick="SubmitLogin();"><span class='button_console_text'>Login</span></div>
        </td>
      </tr>
  </table>
</div>
</form>

<div id="javascript_warning" align="center" class="warning_text">
WARNING: JavaScript must be enabled to use this system.  Please turn on JavaScipt in your browser.
</div>

<?php include("lib/popup_msg.html"); ?>

<script language="javascript" type="text/javascript">
	document.getElementById("javascript_warning").innerHTML = "";
	HidePopupMsg();
</script>
</body>
</html>