<?php
// Display demo user name and password within login form if $AllowDemoMode is true

//include ('LanguageSetup.php');
if ((isset($AllowDemoMode)) AND ($AllowDemoMode == True) AND (!isset($demo_text))) {
	$demo_text = _('Login as user') .': <i>' . _('admin') . '</i><br />' ._('with password') . ': <i>' . _('EMP') . '</i>' .
		'<br /><a href="../">' . _('Return') . '</a>';// This line is to add a return link.
} elseif (!isset($demo_text)) {
	$demo_text = '';
}


if (!isset($PathPrefix)) {
	$PathPrefix='../';
}

$http =  (!empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
$dir = (dirname($_SERVER['PHP_SELF'], 1) == "/" ? '' : dirname($_SERVER['PHP_SELF'], 1));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>Login</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<meta name="title" content="Perfect Connection" />
	<meta property="og:title" content="Perfect Connection" />
	<meta property="og:type" content="website" />
	<meta property="og:url" content="<?php echo  $http . $_SERVER['SERVER_NAME'] . $dir . '/css/logo.jpg'; ?>" />
	<meta property="og:image" content="<?php echo $http . $_SERVER['SERVER_NAME'] . $dir . '/css/logo.jpg'; ?>" />

</head>
<body>
<?php

if (get_magic_quotes_gpc()){
	echo '<p style="background:white">';
	echo _('Your webserver is configured to enable Magic Quotes. This may cause problems if you use punctuation (such as quotes) when doing data entry. You should contact your webmaster to disable Magic Quotes');
	echo '</p>';
}

?>
<div class="container">
	<div class="row">
		<div class="col-sm-4"></div>
		<div class="col-sm-4">
			<img class="img-responsive" src="css/logo.jpg" alt="">
		</div>
		<div class="col-sm-4"></div>
	</div>
	<div class="row">
		<div class="col-sm-4"></div>
		<div class="col-sm-4">

			<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8');?>" method="post">
			<h2>Login</h2>
				<div class="form-group">
					<label><?php echo _('User name'); ?>:</label>
					<input type="text" class="form-control" name="UserNameEntryField" maxlength="20" required />
				</div>
				<div class="form-group">
					<label><?php echo _('Password'); ?>:</label>
					<input type="password" class="form-control" name="Password" />
				</div>
				<div class="form-group">
					<label for="CompanyNameField"><?php echo _('Company'); ?>:</label>

				<?php
				if (isset($CompanyList) AND is_array($CompanyList)) {
					foreach ($CompanyList as $key => $CompanyEntry){
						if ($DefaultDatabase == $CompanyEntry['database']) {
							$CompanyNameField = "$key";
							$DefaultCompany = $CompanyEntry['company'];
						}
					}
					if ($AllowCompanySelectionBox === 'Hide'){
						// do not show input or selection box
						echo '<input type="hiden" class="form-control" name="CompanyNameField"  value="' . $CompanyNameField . '" />';
					} elseif ($AllowCompanySelectionBox === 'ShowInputBox'){
						// show input box
						echo '<input type="text" class="form-control" name="DefaultCompany" value="' .  htmlspecialchars($DefaultCompany ,ENT_QUOTES,'UTF-8') . '" required disabled="disabled"/>';//use disabled input for display consistency
						echo '<input type="hiden" class="form-control" name="CompanyNameField"  value="' . $CompanyNameField . '" />';
					} else {
						// Show selection box ($AllowCompanySelectionBox == 'ShowSelectionBox')
						echo '<select class="form-control" id="CompanyNameField" name="CompanyNameField">';
						foreach ($CompanyList as $key => $CompanyEntry){
							if (is_dir($PathPrefix . 'companies/' . $CompanyEntry['database']) ){
								if ($CompanyEntry['database'] == $DefaultDatabase) {
									echo '<option selected="selected" label="'.htmlspecialchars($CompanyEntry['company'],ENT_QUOTES,'UTF-8').'" value="'.$key.'">' . htmlspecialchars($CompanyEntry['company'],ENT_QUOTES,'UTF-8') . '</option>';
								} else {
									echo '<option label="'.htmlspecialchars($CompanyEntry['company'],ENT_QUOTES,'UTF-8').'" value="'.$key.'">' . htmlspecialchars($CompanyEntry['company'],ENT_QUOTES,'UTF-8') . '</option>';
								}
							}
						}
						echo '</select>';
					}
				}
				  else { //provision for backward compat - remove when we have a reliable upgrade for config.php
					if ($AllowCompanySelectionBox === 'Hide'){
						// do not show input or selection box
						echo '<input type="hiden" class="form-control" name="CompanyNameField"  value="' . $DefaultCompany . '" />';
					} else if ($AllowCompanySelectionBox === 'ShowInputBox'){
						// show input box
						echo '<input type="text" class="form-control" name="CompanyNameField"  value="' . $DefaultCompany . '" required />';
					} else {
						  // Show selection box ($AllowCompanySelectionBox == 'ShowSelectionBox')
						  echo '<select class="form-control" id="CompanyNameField" name="CompanyNameField">';
						  $Companies = scandir($PathPrefix . 'companies/', 0);
						  foreach ($Companies as $CompanyEntry){
							  if (is_dir($PathPrefix . 'companies/' . $CompanyEntry) AND $CompanyEntry != '..' AND $CompanyEntry != '' AND $CompanyEntry!='.svn' AND $CompanyEntry!='.'){
								  if ($CompanyEntry==$DefaultCompany) {
									  echo '<option selected="selected" label="'.$CompanyEntry.'" value="'.$CompanyEntry.'">'.$CompanyEntry.'</option>';
								  } else {
									  echo '<option label="'.$CompanyEntry.'" value="'.$CompanyEntry.'">'.$CompanyEntry.'</option>';
								  }
							  }
						  }
						  echo '</select>';
					}
				} //end provision for backward compat
				?>
				</div>
				<input type="hidden" name="FormID" value="<?php echo $_SESSION['FormID']; ?>" />
				<button type="submit" class="btn btn-info btn-block btn-default" value="<?php echo _('Login'); ?>" name="SubmitUser" >Login <span class="glyphicon glyphicon-log-in"></span></button>
			</form>
		    </div>
		    <div class="col-sm-4"></div>
		</div>
	</div>
	<script type="text/javascript">
		document.forms[0].UserNameEntryField.focus();
	</script>
	
</body>
</html>