<?php
	//*******************************************************************
	// INCLUDES
    //*******************************************************************
	include "includes/library.php";
	//include "includes/ibase_common.php";

    //*******************************************************************
	// SOURCE
    //*******************************************************************
	
	$user = request("user");
	$pass = strtoupper( md5( request("pass")));
	
	
	$ERRORS = "";
	if ( (!empty($user)  ) && ( !empty($pass) )  ){
				
				/******************************************************************
				* Dá um include no arquivo base_dados.php
				* e coloca todos os SQL
				******************************************************************/
				//include "base_dados.php";
				/******************************************************************
				* Dá um include no arquivo base_dados.php
				* e coloca todos os SQL
				******************************************************************/
				
				/******************************************************************
				/validar usuario e senha
				******************************************************************/
				$sql = "select * from USUARIO where USUARIO = '$user'";
				$USUARIO = new QUERY( $DATABASE,$sql);
				$USUARIO->NEXT();
				if(    ($USUARIO->BYNAME("SENHA") == $pass)   ){
					$login = true;
				} else {
					$login = false;
				}

				if($login) {
					
					//inicialização login
					$net_id =  md5(rand(0,9999999));

					session_name("net_id");
					session_id($net_id);
					session_start();

					set_session("USER", $user);
					set_session("USER_NOME", $USUARIO->BYNAME("PRIMEIRO_NOME")  . $USUARIO->BYNAME("ULTIMO_NOME") );
					set_session("USER_EMAIL", $USUARIO->BYNAME("EMAIL") );
					
					set_session("last_access", time() );
					
					set_session("USER_NIVEL", 1 );
					$USUARIO->FREE();

					do_redirect("area_usuario_controle.php?net_id=$net_id");
				} else {
					if ( $USUARIO->BYNAME("ID") <= 0 ) {
						$message = "Usuário inválido.";
						$field = "user";
					} elseif($hora_nao_permitida) {
						$message = "Horário não permitido.";
						$field = "pass";
					} else {
						$message = "Senha inválida.";
						$field = "pass";
					}

					$ERRORS = LoadErrorsServidor_add($message,"document.formlogin." . $field);
				}
				$USUARIO->FREE();
			//---

	} 
?>
<html lang="pt-br" id="extr-page">
	<head>
		<meta charset="iso-8859-1"> 
		<title>Neo Fatura</title>
		<meta name="description" content="">
		<meta name="author" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		
		<!-- #CSS Links -->
		<!-- Basic Styles -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.min.css">

		<!-- SmartAdmin Styles : Please note (smartadmin-production.css) was created using LESS variables -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.min.css">

		<!-- SmartAdmin RTL Support is under construction
			 This RTL CSS will be released in version 1.5
		<link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.min.css"> -->

		<!-- We recommend you use "your_style.css" to override SmartAdmin
		     specific styles this will also ensure you retrain your customization with each SmartAdmin update.
		<link rel="stylesheet" type="text/css" media="screen" href="css/your_style.css"> -->

		<!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
		<link rel="stylesheet" type="text/css" media="screen" href="css/demo.min.css">

		<!-- #FAVICONS -->
		<link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
		<link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

		<!-- #GOOGLE FONT -->
		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700">

		<!-- #APP SCREEN / ICONS -->
		<!-- Specifying a Webpage Icon for Web Clip 
			 Ref: https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html -->
		<link rel="apple-touch-icon" href="img/splash/sptouch-icon-iphone.png">
		<link rel="apple-touch-icon" sizes="76x76" href="img/splash/touch-icon-ipad.png">
		<link rel="apple-touch-icon" sizes="120x120" href="img/splash/touch-icon-iphone-retina.png">
		<link rel="apple-touch-icon" sizes="152x152" href="img/splash/touch-icon-ipad-retina.png">
		
		<!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		
		<!-- Startup image for web apps -->
		<link rel="apple-touch-startup-image" href="img/splash/ipad-landscape.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
		<link rel="apple-touch-startup-image" href="img/splash/ipad-portrait.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
		<link rel="apple-touch-startup-image" href="img/splash/iphone.png" media="screen and (max-device-width: 320px)">

	</head>
	
	<body class="animated fadeInDown" >
		<div style="backgroud-color:#FFFFFF">
			<script language="javascript">
				function LoadErrorsServidor() {
					<?php echo $ERRORS?>
					ShowListErrors();
				}
			</script>
		</div>

		<header id="header" style="height:90px;">
			<div id="logo-group" >
				<img src="images/logo_neofatura_home.png" alt="Neo Fatura" style="margin-top:5px;">
			</div>
		</header>

		<div id="main" role="main">

			<!-- MAIN CONTENT -->
			<div id="content" class="container">

				<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 hidden-xs hidden-sm" >
						<h1 class="txt-color-blue login-header-big">Neo Fatura</h1>
						
							<div class="pull-left login-desc-box-l">
								<h4 class="paragraph-header">Configuração dos Contratos Iniciais.</h4>
							</div>
						
					</div>
					<div class="col-xs-12 col-sm-12 col-md-8 col-lg-4" >
						<!-- Mensagem de Erro que aparece para quando não digitar o usuário e a senha correto -->
						<!-- Mensagem de Erro que aparece para quando não digitar o usuário e a senha correto -->
						<div>
							<?php include( "includes/mensagem_erro.php" ); ?>
						</div>

						<div class="well no-padding">
							<form name="formlogin" action="user_login.php" id="login-form" class="smart-form client-form" method="post" onsubmit="return consiste(this);">
								<header>
									Entrar
								</header>

								<fieldset>
									
									<section>
										<label class="label">Usuário</label>
										<label class="input"> <i class="icon-append fa fa-user"></i>
											<input type="text" name="user">
											<b class="tooltip tooltip-top-right"><i class="fa fa-user txt-color-teal"></i> Preencha com o usuário</b></label>
									</section>

									<section>
										<label class="label">Senha</label>
										<label class="input"> <i class="icon-append fa fa-lock"></i>
											<input type="password" name="pass">
											<b class="tooltip tooltip-top-right"><i class="fa fa-lock txt-color-teal"></i> Preencha com a senha</b> </label>
										
									</section>

									
								</fieldset>
								<footer>
									<button type="submit" class="btn btn-primary">
										Entrar
									</button>
								</footer>
							</form>

						</div>
						
						
					</div>
				</div>
			</div>

		</div>

		<!--================================================== -->	

		<!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)-->
		<script src="js/plugin/pace/pace.min.js"></script>

	    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->
	    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
		<script> if (!window.jQuery) { document.write('<script src="js/libs/jquery-2.0.2.min.js"><\/script>');} </script>

	    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
		<script> if (!window.jQuery.ui) { document.write('<script src="js/libs/jquery-ui-1.10.3.min.js"><\/script>');} </script>

		<!-- JS TOUCH : include this plugin for mobile drag / drop touch events 		
		<script src="js/plugin/jquery-touch/jquery.ui.touch-punch.min.js"></script> -->

		<!-- BOOTSTRAP JS -->		
		<script src="js/bootstrap/bootstrap.min.js"></script>

		<!-- JQUERY VALIDATE -->
		<script src="js/plugin/jquery-validate/jquery.validate.min.js"></script>
		
		<!-- JQUERY MASKED INPUT -->
		<script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>
		
		<!--[if IE 8]>
			
			<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>
			
		<![endif]-->
		<!-- Scripts do Framework antigo -->
		<!-- Scripts do Framework antigo -->
		<script type="text/javascript" src="scripts/common_scripts.js"></script>
		<script type="text/javascript" src="scripts/robo_lookup.js"></script>
		<script type="text/javascript" src="scripts/user_login.js"></script>


		<script language="JavaScript">
				function encerrar() {
					if(typeof(parent.LeaveControl)=="number") {
						parent.LeaveControl = 0;
						document.location = "user_logout.php?<?php echo show($sid_get)?>&apelido=<?php echo show(request_session('EMP_APELIDO'))?>";
					}
					return false;
				}

				function set_query( form) {
					document.location = 'robo_pesquisa.php?<?php echo $sid_get?>&mod=' + form.mod.value + '&allwords=' + form.allwords.value + '&query=' + form.query.value + '&makesearch=yes';
					return false;
				}	

				$(document).ready(function(){
					LoadErrorsServidor();
				})
		</script>
		<!-- IFRAME UTILIZADO PARA LOOKUP -->
		<iframe name="ifr_lookup" id="ifr_lookup_id" src="" width="0" height="0" frameborder="0" scrolling="no"></iframe>
		<!-- IFRAME UTILIZADO PARA LOOKUP -->
		<table class="topo">
	</body>
</html>