<?php
	//aktifkan session
	if(!isset($_SESSION)){session_start();}

	session_write_close();
	if ((!isset($_SESSION['f_user']) ) && (!isset($_SESSION['f_pass']))){
		//header("location:index.php");
		//die();
		}
	else
	{header("location:menuUtama.php");}
?>


<!doctype html>
<html>
<!-- sumber => http://stackoverflow.com/questions/10964966/detect-ie-version-prior-to-v9-in-javascript -->
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
<head>
	<meta charset="UTF-8">
	<title>Program Web - Stock and inventory</title>

	<!-- Mengisi Icon Logo Sritex di browser cek juga header.php  -->
	<!-- 16x16 and 32x32 ico-->
	<link rel="shortcut icon" href="gambar/IconBrowser.ico" type="image/x-icon"/>
	<!-- A 192x192 PNG icon for Android Chrome -->
	<link rel="icon" type="image/png" href="gambar/IconBrowser.png" sizes="192x192">
	<!-- A 180x180 Apple Touch icon -->
	<link rel="apple-touch-icon"      href="gambar/IconBrowser.png" sizes="180x180" >

	<link rel="stylesheet" type="text/css" href="./easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="./easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="./easyui/demo/demo.css">
	<script type="text/javascript" src="./easyui/jquery.min.js"></script>
	<script type="text/javascript" src="./easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="./easyui/plugins/filter/datagrid-filter.js"></script>
</head>

<script language="JavaScript">
  function aksesLogin(){
		if ($('#f_user').val()!=""){
			if ($('#f_pass').val()!=""){
				$('#kunci').val('kirim');
				$('#frm_index').submit();
			}else {
				alert("Err.. Isi Pass dulu!!!");
				$('#f_pass').focus();
			}
		}else {
			alert("Err.. Isi User dulu!!!");
			$('#f_user').focus();
		}
	}

	//sumber => http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
	(function ($) {
			"use strict";
			// Detecting IE
			var oldIE;
			//if ($('html').is('.ie6, .ie7, .ie8')) {
		if ($('html').is('.ie6')) {
			//oldIE = true;
			alert("BROWSER IE6 TIDAK MENDUKUNG, GANTI FIREFOX/CHROME/IE8!!");
			document.location="gantibrowser.php";
		}

		//cek tombol back browser ==> https://stackoverflow.com/questions/26505204/call-php-function-when-browser-back-button-clicked
		//jQuery(document).ready(function($) {
		if (window.history && window.history.pushState) {
			//window.history.pushState('forward', null, './#forward');
			window.history.pushState('forward', null, '');
			$(window).on('popstate', function() {
				//alert('Back button was pressed.'); //here you know that the back button is pressed
				//diset keluar karena ini menu pertama saat login jadi stlh itu harus di keluarkan ato kembali kemenunya sndiri
				window.location = 'index.php';//'keluar.php';
			});
		}

		//do anything that needs to be done on document.ready
		//alert("OK");
		//=== cara submit lewat ajax
		$('#kirimx').on('click', function(e){
			//e.preventDefault();				
			if ($('#f_user').val()!=""){
				if ($('#f_pass').val()!=""){
					$('#kunci').val('kirim');
					$('#frm_index').submit();
				}else {
					alert("Err.. Isi Pass dulu!!!");
				}
			}else {
				alert("Err.. Isi User dulu!!!");
			}
		});
		//=== cara register lewat ajax
		$('#new').on('click', function(e){
			//e.preventDefault();
			//$('#f_user').val("");
			//$('#f_pass').val("");
			//$('#kunci').val('new');
			//$('#frm_index').submit();     		
			//$("<a href='regis.php'></a>").click(); 
		});	//=== cara forgot pass lewat ajax
		$('#repas').on('click', function(e){
			//e.preventDefault();
			//$('#f_user').val("");
			//$('#f_pass').val("");
			//$('#kunci').val('repas');
			//$('#frm_index').submit();     		
		});

	} (jQuery));


	function validate_form() {
	  validity = true; // assume valid
//	  if (!check_empty(document.form.f_pass.value)){ 
//			validity = false; 
//			msg='Password field is empty!\n\n'; 
//			document.form.f_pass.focus();}
	  if (!check_empty(document.form.f_user.value))
			{ 
			validity = false; 
			msg='User field is empty!\n\n'; 
			document.form.f_user.focus();
			}
	  if (!validity)
			{alert(msg)};
	  return validity;
	}

	function check_empty(text) 
	  {return (text.length > 0);} // returns false if empty

</script>

<!-- utk membunuh klik kanan tambahakan perintah => oncontextmenu="return true;" -->
<body  style="height:100%;width:100%;overflow:hidden;border:none;">
  <?php

		//utk bisa ganti2 versi easyui maka harus di clear dulu history and cookies, sumber =>http://stackoverflow.com/questions/1037249/how-to-clear-browser-cache-with-php
		//header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
		//header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		//header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
		//header("Cache-Control: post-check=0, pre-check=0", false);
		//header("Pragma: no-cache");

		//utk cek apakah link penghubung nya sdh bner
		//if(!isset($_SESSION)){session_start();}
		//echo $_SESSION['actual_link'];

		//cetak logo
		$logox ="";
		$logox .="<img src=\"./gambar/LogoHeader.gif\" width=90% />";
		$logox .="<hr align=left width=900px>";
		$logox .="<div align=\"left\"> <button onclick=javascript:$('#win').window('open')>Login</button> </div>";
		echo $logox;
	?>

	<div id="win" class="easyui-window" title="Login" style="position=absolute;top:200px;width:300px;height:180px;"	data-options="modal:true">  
		<!-- <form style="padding:10px 20px 10px 40px;" method="post" action="login.php" name="form" onSubmit="return validate_form()" > -->
		<form style="padding:10px 20px 10px 40px;" method="post" action="login.php" id="frm_index" name="frm_index" >
			<table width="100%">
				<tr>
					<td width="55px">USERS</td>
					<td>:</td>
					<td>
					<!-- input type="text" id="f_user" name="f_user" size="20" maxlength="20" value="'|| '1=1" required="required" style="width:90%"  />			</td -->
					<input type="text" id="f_user" name="f_user" size="20" maxlength="20" value="" required="required" style="width:90%"  />			</td>
				</tr>
				<tr>
					<td>PASSWORD</td>
					<td>:</td>
					<td>
					<!-- input type="password" id="f_pass" name="f_pass" size="20" maxlength="20" value="'|| '1=1" required="required" style="width:90%"  / -->
					<input type="password" id="f_pass" name="f_pass" size="20" maxlength="20" value="" required="required" style="width:90%"  />			</td>
				</tr>
				<tr>
					<td></td>
					<td></td>

					<br/>
				</tr>
			</table>
			<div style="padding:5px;text-align:center;">
				<!-- <input type="submit" value="Login" name="submit">
				<input type="button" value="New User" onClick="javascript : location.href='register.php'" name="button3" disabled>  -->
			  <input type="hidden" id="kunci" name="kunci">
				<input type="button" id="kirim" name="kirim" value="Login" onClick="aksesLogin();">
				<!-- <input type="button" id="new" name="new" value="New User" disabled> -->
				<!--
				<input type="button" id="new" name="new" value="New User" onclick="location.href='regis.php';">
				<input type="button" id="repas" name="repas" value="Forgot" onclick="location.href='regisForgot.php';"> 
				-->
			</div>

		</form>
	</div>

<!--  <hr>
  <u>Created : 25 July 2014 - v1.01</u>
  <br> -->
</body>
</html>

<script type="text/javascript">  
	//jika grid di click (focus) maka lakukan berikut ini:
	$(function(){	
		$( "input#f_pass" ).keyup(function(e){
		  //tombol enter ditekan
		  if(e.keyCode == 13){
			  //doSearch();
			  $('#kunci').val('kirim');
			  
			  //setfocus button, sumber => http://www.kolodvor.net/2008/01/17/set-focus-on-first-field-with-jquery/
			  //$("input:text:visible:first").focus();
			  $('#kirim').focus();

			  //alert($("#frm_index").serialize());
			  $('#frm_index').submit();  
		  } else {
			  //tombol2, sumber => http://stackoverflow.com/questions/3781142/jquery-or-javascript-how-determine-if-shift-key-being-pressed-while-clicking-an
			  //hurufbesar(e,this);
			  //atau cara manual
			  //if (e.keyCode!=9 && e.keyCode!=36 && e.keyCode!=16 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=38 && e.keyCode!=40){
				////alert(e.keyCode); //utk checking
				////alert(e.which);	//utk checking
				// this.value = this.value.toUpperCase();
			  //}
		  }
		});
	});



</script>