<?php session_start();
	include_once("functions/init.php"); 
	include_once ($thisUrl."adm1n/functions/koneksi.php");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<?php
		$tmp = $thisUrl."adm1n/functions/head_section.php";
		include ($tmp);
		?>		
    </head>	
	<body>
		<div class="se-pre-con"></div>
        <center>
			<table width="238">
				<tr valign="top">
					<td align="center">
						<br><br><br><br>
						<?php 
						$tmp = $thisUrl."adm1n/functions/logo.php";
						include ($tmp);
						
						$err = 1;		
						$aksi = (isset($_REQUEST["aksi"]) ? $_REQUEST["aksi"] : null);	
						if($aksi=="Log in") {
							echo '
							<img src="'.$thisPage.'adm1n/images/loading.gif" border="0">
							';
							$username = $_POST["username"];
							$pass = $_POST["pass"];
							$strSQL="select * from user where username='".$username."'";
							if ($hasil = mysqli_query($conn, $strSQL)) {
								while ($data = mysqli_fetch_array($hasil)) {
									if($data["username"] != $username || $data["password"] != $pass ) {
										$err=1;
									} else {
										$err=0;
										$_SESSION["username"] = $data["username"];
										$_SESSION["iduser"]   = $data["admin_id"];
										$_SESSION["thisPage"] = $thisPage;
										$_SESSION["thisUrl"]  = $thisPage;
									}
								}
							}
							$_SESSION["err"] = $err;
							
							echo "<script language=JavaScript>";
							echo "	location.href = '".$thisPage."adm1n/';";
							echo "</script>";
						} else {
							?>
                            <form method="post" action="" enctype="multipart/form-data" name="form1">
                                <table width="33%" cellpadding="3" cellspacing="1" border="0" bgcolor="#cccccc">
                                    <tr height="25" bgcolor="#006666">
                                        <td align="left" colspan="2">
                                            <font color="#FFFFFF">&nbsp;<strong>Login Form</strong></font>
                                        </td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF" height="30">
                                        <td width="18%" align="left">Username</td>
                                        <td align="left"><input type="text" name="username" size="25"></td>
                                    </tr>
                                    <tr bgcolor="#FFFFFF" height="30">
                                        <td align="left">Password</td>
                                        <td align="left"><input type="password" name="pass" size="25"></td>
                                    </tr>
                                    <?php 
									$err = (isset($_SESSION["err"]) ? $_SESSION["err"] : null);
                                    if($err == 1){
                                        ?>
                                        <tr bgcolor="#FFFFFF">
                                            <td colspan="2" align="right">
                                                <font color="#990000"><strong>Username dan/atau Password Anda Salah !.</strong></font>
                                            </td>
                                        </tr>								
                                        <?php
                                    }
                                    ?>
                                    <tr bgcolor="#FFFFFF">
                                        <td colspan="2" align="right">
                                            <input type="submit" name="aksi" id="aksi" value="Log in">
                                        </td>
                                    </tr>
                                </table>
                            </form>
                            <?php						
						}
						?>
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>	
