<?
session_start(); 
require_once('../conf/connection.php');

if ($_SESSION['error_login']=="")
{
$_SESSION['error_login'] = "";
}
if ($_POST['login']=="si")
	{
		$usuario=$_POST['user'];
		$cuenta=$_POST['pass'];
		if (($usuario=="") || ($cuenta==""))
		{		
			$_SESSION['error_login']="¡Datos en blanco!";		
			$url_relativa = "index.php";
			header ("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']). "/" .$url_relativa);
		}
		else
		{	
		$sql = mysql_query("SELECT nombre_user,pass,tipo_user FROM  user_system WHERE nombre_user='$usuario'");
		$row = mysql_fetch_array($sql);
		if($row>0)
		{
			if($row[1] == $cuenta)
			{
			session_start();
			$_SESSION['nombreusuario'];
			$_SESSION['nombreusuario'] = $usuario;
			$_SESSION['id_usuario'];
			$_SESSION['id_usuario'] = $row[0];
			$nivel=$row['tipo_user'];
			$nombreuser=$row['nombre_user'];
		    $_SESSION['usuario']=$nombreuser;	
			switch ($nivel) {
				   //ADMINISTRADOR
                   case 1:
                    $url_relativa = "admin/principal.php?nivel=$nivel&nombreuser=$nombreuser";
			        header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" .$url_relativa);
                   break;		  
				   //CAJERO		   
				   case 2:
                    $url_relativa = "caja/index.php?nivel=$nivel&nombreuser=$nombreuser";
			        header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" .$url_relativa);
                   break;   
				  //GARZON
				  case 3:
                    $url_relativa = "garzon/index.php?nivel=$nivel&nombreuser=$nombreuser";
			        header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" .$url_relativa);
                   break;
				   default:          
			           $url_relativa="index.php";
			           header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) .  "/" .$url_relativa);
            }
			if($row['nivel'] == 'Administrador'){}               
		        else  {} 
			}else{
			}	
			}
			else
			{
			$_SESSION['error_login']="¡Usuario incorrecto!";
			$url_relativa="index.php";
			header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $url_relativa);
			}
		mysql_free_result($sql);
	}
mysql_close();
	}else{
	
session_destroy();
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60745 -->
    <meta charset="utf-8">
    <title>MENU PRINCIPAL</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="../style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="../style.responsive.css" media="all">

    <script src="../jquery.js"></script>
    <script src="../script.js"></script>
    <script src="../script.responsive.js"></script>



<style>.art-content .art-postcontent-0 .layout-item-0 { margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#C4C6BD; padding-right: 10px;padding-left: 10px;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

</style>

<style>
.img_logo {
	
	position:absolute;
	top:10px;
	right:0px;
	left:500px;
        
}


</style>
</head>
<body>
<div id="art-main">
    <div class="art-sheet clearfix">
<nav class="art-nav">
    <ul class="art-hmenu"><li><a href="../index.php" class="active">Volver</a></li></ul> 
    </nav>
<div class="art-layout-wrapper">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                      <div class="art-layout-cell art-content"><article class="art-post art-article">
                                
                                                
                                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
     <img src="../images/logo.png" class="img_logo">
        <h3>Acceso Adminitrativo</h3>
        <p><strong>Para acceder como administrador debes tener las credenciales necesarias ...</strong> </p>
        <div class="image-caption-wrapper" style="width: 100%">
        <form method="post" name="form">
<table  border="0" align="center" class="table">
            <tr>
              <td class="about"><h3>Usuario&nbsp;:&nbsp;</h3></td>
              <td><input type="text" name="user" size="25"  autocomplete="off" id="user" /></td>
            </tr>
           
            <tr>
              <td><h3>Clave:&nbsp;</h3></td>
              <td><input type="password" name="pass" size="25" class="caja" onKeyPress="enter(event)" id="pass" /></td>
            </tr>
            <tr>
              <td colspan="2" height="10">
                <input type="submit" name="Submit" value="Ingresar" class="art-button" style="height:50px; width:120px;"  />
                <input type="reset" name="Submit2" value="Limpiar" class="art-button" style="height:50px; width:120px;" />
                <input name="login" type="hidden" value="si"></td>
            </tr>
            <tr>
              <td colspan="2" align="left"><?php echo ($_SESSION['error_login']); ?></td>
              </tr>
          </table></center>
          </form>
       
        
        </div>
    </div>
    </div>
</div>
</div>
</div>


</article></div>
                    </div>
                </div>
            </div><footer class="art-footer">
<p><br></p>
<p>Copyright © <? echo $ano; ?>. All Rights Reserved.</p>
</footer>

    </div>
    <p class="art-page-footer">
        <span id="art-footnote-links"><a href="http://www.virtualsurchile.cl" target="_blank">Informatica Francisco Arias E.I.R.L.</a></span>
    </p>
</div>


</body></html>