<?php
/* Modern Login Page for e-Business ERP System */
/* Matches newheader.php branding — teal theme with crescent logo */

if ((isset($AllowDemoMode)) AND ($AllowDemoMode == True) AND (!isset($demo_text))) {
	$demo_text = _('Login as user') .': <i>' . _('admin') . '</i><br />' ._('with password') . ': <i>' . _('weberp') . '</i>';
} elseif (!isset($demo_text)) {
	$demo_text = '';
}
?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8"/>
	<title>e-Business ERP — Login</title>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
	<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet"/>
	<style>
		*{margin:0;padding:0;box-sizing:border-box}
		body{
			font-family:'Poppins',-apple-system,BlinkMacSystemFont,sans-serif;
			min-height:100vh;
			display:flex;
			align-items:center;
			justify-content:center;
			background:#F0F4F7;
			position:relative;
			overflow:hidden;
		}

		/* Animated background */
		body::before{
			content:'';position:absolute;top:-40%;right:-20%;
			width:800px;height:800px;
			background:radial-gradient(circle,rgba(43,186,211,0.08) 0%,transparent 70%);
			border-radius:50%;
			animation:floatBg 20s ease-in-out infinite alternate;
		}
		body::after{
			content:'';position:absolute;bottom:-30%;left:-15%;
			width:600px;height:600px;
			background:radial-gradient(circle,rgba(43,186,211,0.06) 0%,transparent 70%);
			border-radius:50%;
			animation:floatBg 15s ease-in-out infinite alternate-reverse;
		}
		@keyframes floatBg{
			0%{transform:translate(0,0) scale(1)}
			100%{transform:translate(40px,-30px) scale(1.1)}
		}

		.login-container{
			position:relative;z-index:1;
			width:100%;max-width:440px;
			padding:20px;
		}

		.login-card{
			background:#fff;
			border-radius:16px;
			box-shadow:0 4px 24px rgba(0,0,0,0.06),0 1px 3px rgba(0,0,0,0.04);
			overflow:hidden;
			animation:cardIn 0.5s ease-out;
		}
		@keyframes cardIn{
			from{opacity:0;transform:translateY(16px)}
			to{opacity:1;transform:translateY(0)}
		}

		/* Header band with logo */
		.login-header{
			background:linear-gradient(135deg,#187278 0%,#1E8F96 30%,#2BBAD3 70%,#38C4CC 100%);
			padding:36px 32px 32px;
			text-align:center;
			position:relative;
			overflow:hidden;
		}
		.login-header::before{
			content:'';position:absolute;top:-60%;right:-10%;
			width:300px;height:300px;
			background:radial-gradient(circle,rgba(255,255,255,0.1) 0%,transparent 70%);
			border-radius:50%;pointer-events:none;
		}
		.login-header::after{
			content:'';position:absolute;bottom:-50%;left:10%;
			width:200px;height:200px;
			background:radial-gradient(circle,rgba(255,255,255,0.06) 0%,transparent 70%);
			border-radius:50%;pointer-events:none;
		}

		.login-logo{
			display:inline-block;
			margin-bottom:16px;
			position:relative;z-index:1;
		}
		.login-logo svg{
			filter:drop-shadow(0 2px 8px rgba(0,0,0,0.15));
		}

		.login-subtitle{
			color:rgba(255,255,255,0.85);
			font-size:13px;
			font-weight:400;
			letter-spacing:0.3px;
			position:relative;z-index:1;
		}

		/* Form body */
		.login-body{
			padding:32px;
		}

		.form-group{
			margin-bottom:20px;
		}
		.form-group label{
			display:block;
			font-size:12.5px;
			font-weight:600;
			color:#374151;
			margin-bottom:7px;
			letter-spacing:0.2px;
			text-transform:uppercase;
		}
		.form-group select,
		.form-group input[type="text"],
		.form-group input[type="password"]{
			width:100%;
			padding:11px 14px;
			border:1.5px solid #E2E8F0;
			border-radius:10px;
			font-family:'Poppins',sans-serif;
			font-size:14px;
			color:#1A2332;
			background:#FAFBFC;
			transition:all 0.2s ease;
			outline:none;
		}
		.form-group select:focus,
		.form-group input[type="text"]:focus,
		.form-group input[type="password"]:focus{
			border-color:#2BBAD3;
			background:#fff;
			box-shadow:0 0 0 3px rgba(43,186,211,0.12);
		}
		.form-group select{
			cursor:pointer;
			-webkit-appearance:none;
			-moz-appearance:none;
			appearance:none;
			background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7B8D' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
			background-repeat:no-repeat;
			background-position:right 14px center;
			padding-right:36px;
		}

		.login-btn{
			width:100%;
			padding:12px;
			border:none;
			border-radius:10px;
			background:linear-gradient(135deg,#1E8F96 0%,#2BBAD3 100%);
			color:#fff;
			font-family:'Poppins',sans-serif;
			font-size:14.5px;
			font-weight:600;
			cursor:pointer;
			transition:all 0.25s ease;
			letter-spacing:0.3px;
			margin-top:4px;
			position:relative;
			overflow:hidden;
		}
		.login-btn::before{
			content:'';position:absolute;top:0;left:-100%;
			width:100%;height:100%;
			background:linear-gradient(90deg,transparent,rgba(255,255,255,0.15),transparent);
			transition:left 0.5s ease;
		}
		.login-btn:hover{
			background:linear-gradient(135deg,#187278 0%,#1E8F96 100%);
			box-shadow:0 4px 16px rgba(43,186,211,0.3);
			transform:translateY(-1px);
		}
		.login-btn:hover::before{
			left:100%;
		}
		.login-btn:active{
			transform:translateY(0);
			box-shadow:0 2px 8px rgba(43,186,211,0.2);
		}

		.demo-text{
			text-align:center;
			font-size:12px;
			color:#6B7B8D;
			margin-top:12px;
			line-height:1.6;
		}
		.demo-text i{
			color:#2BBAD3;
			font-style:normal;
			font-weight:600;
		}

		/* Footer */
		.login-footer{
			text-align:center;
			padding:20px 32px 24px;
			border-top:1px solid #F0F2F5;
		}
		.login-footer p{
			font-size:11px;
			color:#9CA3AF;
			line-height:1.5;
		}
		.login-footer a{
			color:#2BBAD3;
			text-decoration:none;
			font-weight:500;
		}
		.login-footer a:hover{
			text-decoration:underline;
		}

		/* Responsive */
		@media(max-width:480px){
			.login-container{padding:12px}
			.login-header{padding:28px 24px 24px}
			.login-body{padding:24px}
		}
	</style>
</head>
<body>

<div class="login-container">
	<div class="login-card">

		<!-- Header with same SVG logo as newheader.php -->
		<div class="login-header">
			<div class="login-logo">
				<svg width="240" height="62" viewBox="0 0 220 56" xmlns="http://www.w3.org/2000/svg">
					<rect x="0.5" y="0.5" width="219" height="55" rx="8" fill="rgba(255,255,255,0.15)" stroke="rgba(255,255,255,0.2)" stroke-width="1"/>
					<!-- Crescent matching newheader.php -->
					<path d="M 36 5 A 18 24 0 0 0 36 51 A 13 19 0 0 1 36 5 Z" fill="rgba(255,255,255,0.85)"/>
					<path d="M 36 5 A 18 24 0 0 0 36 51 A 13 19 0 0 1 36 5 Z" fill="none" stroke="rgba(255,255,255,0.2)" stroke-width="2"/>
					<text x="42" y="38" font-family="Poppins,sans-serif" font-weight="600" font-size="26" fill="#fff" letter-spacing="-0.3">e-Business</text>
					<circle cx="194" cy="13" r="7" fill="none" stroke="rgba(255,255,255,0.9)" stroke-width="0.8"/>
					<text x="190.8" y="16.8" font-family="Poppins,sans-serif" font-size="10" fill="rgba(255,255,255,0.9)" font-weight="500">R</text>
				</svg>
			</div>
			<div class="login-subtitle">Enterprise Resource Planning System</div>
		</div>

		<!-- Login Form -->
		<div class="login-body">
			<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8');?>" method="post">
				<input type="hidden" name="FormID" value="<?php echo $_SESSION['FormID']; ?>" />

				<?php
				// Company selection — same logic as original
				if (isset($CompanyList) AND is_array($CompanyList)) {
					foreach ($CompanyList as $key => $CompanyEntry){
						if ($DefaultDatabase == $CompanyEntry['database']) {
							$CompanyNameField = "$key";
							$DefaultCompany = $CompanyEntry['company'];
						}
					}
					if ($AllowCompanySelectionBox === 'Hide'){
						echo '<input type="hidden" name="CompanyNameField" value="' . $CompanyNameField . '" />';
					} elseif ($AllowCompanySelectionBox === 'ShowInputBox'){
						echo '<div class="form-group"><label>' . _('Company') . '</label>';
						echo '<input type="text" name="DefaultCompany" autofocus="autofocus" required="required" value="' . htmlspecialchars($DefaultCompany, ENT_QUOTES, 'UTF-8') . '" disabled="disabled"/>';
						echo '<input type="hidden" name="CompanyNameField" value="' . $CompanyNameField . '" />';
						echo '</div>';
					} else {
						echo '<div class="form-group"><label>' . _('Company') . '</label>';
						echo '<select name="CompanyNameField">';
						foreach ($CompanyList as $key => $CompanyEntry){
							if (is_dir('companies/' . $CompanyEntry['database'])){
								if ($CompanyEntry['database'] == $DefaultDatabase) {
									echo '<option selected="selected" value="'.$key.'">' . htmlspecialchars($CompanyEntry['company'], ENT_QUOTES, 'UTF-8') . '</option>';
								} else {
									echo '<option value="'.$key.'">' . htmlspecialchars($CompanyEntry['company'], ENT_QUOTES, 'UTF-8') . '</option>';
								}
							}
						}
						echo '</select></div>';
					}
				} else {
					// Backward compat
					if ($AllowCompanySelectionBox === 'Hide'){
						echo '<input type="hidden" name="CompanyNameField" value="' . $DefaultCompany . '" />';
					} elseif ($AllowCompanySelectionBox === 'ShowInputBox'){
						echo '<div class="form-group"><label>' . _('Company') . '</label>';
						echo '<input type="text" name="CompanyNameField" autofocus="autofocus" required="required" value="' . $DefaultCompany . '" />';
						echo '</div>';
					} else {
						echo '<div class="form-group"><label>' . _('Company') . '</label>';
						echo '<select name="CompanyNameField">';
						$Companies = scandir('companies/', 0);
						foreach ($Companies as $CompanyEntry){
							if (is_dir('companies/' . $CompanyEntry) AND $CompanyEntry != '..' AND $CompanyEntry != '' AND $CompanyEntry != '.svn' AND $CompanyEntry != '.'){
								if ($CompanyEntry == $DefaultDatabase) {
									echo '<option selected="selected" value="'.$CompanyEntry.'">' . $CompanyEntry . '</option>';
								} else {
									echo '<option value="'.$CompanyEntry.'">' . $CompanyEntry . '</option>';
								}
							}
						}
						echo '</select></div>';
					}
				}
				?>

				<div class="form-group">
					<label><?php echo _('User name'); ?></label>
					<input type="text" name="UserNameEntryField" required="required" autofocus maxlength="20" placeholder="<?php echo _('Enter your username'); ?>" />
				</div>

				<div class="form-group">
					<label><?php echo _('Password'); ?></label>
					<input type="password" name="Password" required="required" placeholder="<?php echo _('Enter your password'); ?>" />
				</div>

				<?php if (isset($demo_text) && $demo_text != '') { ?>
					<div class="demo-text"><?php echo $demo_text; ?></div>
				<?php } ?>

				<button type="submit" name="SubmitUser" class="login-btn"><?php echo _('Sign In'); ?></button>
			</form>
		</div>

		<div class="login-footer">
			<p>&copy; <?php echo date('Y'); ?> Evergreen International Ltd. All rights reserved.</p>
		</div>

	</div>
</div>

</body>
</html>
