<?php

session_start();

if(isset($_SESSION['Usuario'])){
    //Valido si es Admin para dejarlo en Registro
    if($_SESSION['Admin'] == 'S') {

    //Si es admin lo dejo
    }else{


   header("Location: /MauricioCorrea/Noadmin.html");
    }


 
}else{

    //Si no le muestro otra página, puede ser la de Login
    header("Location: /MauricioCorrea/incorrecto.html");
}


?>

<!DOCTYPE html>





<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Registro Vendedor</title>
                         <link rel="icon" type="image/png" href="imagenes/compra.png" />
          
        <script type="text/javascript" src="Js/jquery.min.js" ></script>
        <link rel="stylesheet" type="text/css" href="estilos.css">
        <link rel="stylesheet" type="text/css" href="fonts.css">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="menu.js"></script>
        
    </head>
    <body>
        
        <header>
<?php
if(isset($_SESSION['Usuario'])){

echo '<a class="datosusuario icon-exit" href="/MauricioCorrea/Cerrar.php"> - Salir</a>';
echo '<span class="datosusuario icon-users"> - Bienvenido '.$_SESSION['Nombre'].'</span>';


}else{
    header("Location: /MauricioCorrea/incorrecto.html");
}


?>


       <div class="menu_bar">
        <a href="#" class="bt-menu"><span class="icon-newspaper"></span>Menu</a>
        </div>
            <nav>
                <ul>
                    <li><a href="inicio.php"><span class="icon-home"> </span>Inicio</a></li>  
                    <li class="submenu">
                    <a href="#"><span class="icon-user-tie"></span>Admin<span class="caret icon-circle-down"></span></a>    
                    <ul class="children">
                        <li><a href="Registro.php" ><span class="icon-user-plus"></span>Crea Vendedor</a></li>
                        <li><a href="ModificaVendedor.php" ><span class="icon-pencil"></span>Modifica Vendedor</a></li>
                        <li><a href="RegistroCliente.php" ><span class="icon-user-plus"></span>Crea Cliente <span class="user-plus"></a></li>
                        <li><a href="RegistroProveedor.php" ><span class="icon-user-plus"></span>Crea Proveedor <span class="user-plus"></a></li>
                       

                    </ul>
                    </li>


                    <li class="submenu">
                     <a href="#"><span class="icon-cart"> </span>Vend<span class="caret icon-circle-down"></span></a>
                      <ul class="children">
                        <li><a href="RegistroCliente.php" ><span class="icon-user-plus"></span>Crea Cliente <span class=""></a></li>
                        <li><a href="RegistroVenta.php" ><span class="icon-cart"></span>Crea Factura <span class=""></a></li>
                        <li><a href="RegistroRemision.php" ><span class="icon-file-text2"></span>Crea Remision <span class=""></a></li>
                        <li><a href="RegistroNota.php" ><span class="icon-files-empty"></span>Crea Nota <span class=""></a></li>
                    </ul>
                    </li>    





                     <li class="submenu">
                    <a href="#.php"><span class="icon-users"> </span>Clientes<span class="caret icon-circle-down"></span></a>    
                   <ul class="children">  
                    
                    <li><a href="RegistraCongelador.php"><span class="icon-credit-card"> </span>Registra Congelador</a></li>  
                    <li><a href="ModificaCliente.php"><span class="icon-user-check"> </span>Modificar Cliente</a></li>  
                    <li><a href="InformesClientes.php"><span class="icon-profile"> </span>Informe Clientes</a></li> 
                    <li><a href="InformesVentas.php"><span class="icon-calculator"> </span>Informe Ventas</a></li> 
                    </ul> 
                     </li>        

                       <li class="submenu">
                    <a href="#"><span class="icon-user-tie"></span>Proveedores<span class="caret icon-circle-down"></span></a>    
                    <ul class="children">
                    <li><a href="RegistroCompra.php" ><span class="icon-plus"></span>Carga Compra <span class="plus"></a></li>
                        <li><a href="ModificaProveedor.php" ><span class="icon-user-plus"></span>Modificar Proveedor</a></li>
                        
                        <li><a href="InformesCompras.php" ><span class="icon-stats-bars2"></span>Informe Compras <span class="plus"></a></li>

                    </ul>
                    </li>



                                        
                    <li class="submenu">
                    <a href="#.php"><span class="icon-droplet"> </span>Prod<span class="caret icon-circle-down"></span></a>    
                   <ul class="children">
                        <li><a href="CrearProducto.php" ><span class="icon-barcode"></span>Crea Producto <span class=""></a></li>
                        <li><a href="ModificarProducto.php" ><span class="icon-qrcode"></span>Modifica Producto <span class=""></a></li>
                        <li><a href="InformesInventarios.php" ><span class="icon-files-empty"></span>Informe Inventario <span class=""></a></li>
                    </ul> 
                     </li>    
                    <li><a href="Cerrar.php"><span class="icon-exit"> </span>Salir</a></li>                    
                </ul>
            </nav>
        
        </header>
        <section id="TablaLog">
            
            <p>
            <form method="get" name="Registro" action="Registro.php">
                <div><p id="Titulo"> Nuevo vendedor </p></div>
                <br>
              
                     <div class="txtRight mvm"><p class="fss required"><span class="required">*</span> Campos obligatorios</p></div>
        <br>

                <div class="l-row mts">
                <p class="size1of2 mrl unit">Cédula <span class="required">*</span></p>
                <input type="number" name="cedula" min="1000000" max="9999999999" autofocus="autofocus" required="required" style="width:300px; height:30px; "></div>
          
            </div>
                   
          
           
                     <div class="ui-formRow">
            <div class="label hidefirst"><label for="RegistrationForm_first_name" class="required"><font colorr="Silver"> Nombres <span class="required">*</span></font></label></div>
            <input placeholder="" name="nombre" id="RegistrationForm_first_name" required="required" type="text" autofocus="autofocus" maxlength="50" style="width:300px; height:30px; " />        </div>
        <div class="ui-formRow">
            <div class="label hidefirst"><label for="RegistrationForm_last_name" class="required">Apellidos <span class="required">*</span></label></div>
            <input placeholder="" name="apellido" id="RegistrationForm_last_name" required="required" type="text" autofocus="autofocus" maxlength="50" style="width:300px; height:30px; " />        </div>
       

         <div class="l-row mts">
                <p class="size1of2 mrl unit">Correo <span class="required">*</span></p>
                <input type="mail" name="correo" autofocus="autofocus" required="required" style="width:300px; height:30px; "></div>

        
                        


            
          
                     <div class="ui-formRow">
           <div class="label hidefirst"><label for="RegistrationForm_password" class="required">Contraseña <span class="required">*</span></label></div>
            <input placeholder="" name="Contra" id="RegistrationForm_password" type="password" style="width:300px; height:30px; " />        </div>
        <div class="ui-formRow">
            <div class="label hidefirst"><label for="RegistrationForm_password2" class="required">Confirmar contraseña <span class="required">*</span></label></div>
            <input placeholder="" name="Contra2" id="RegistrationForm_password2" type="password" style="width:300px; height:30px; " />        </div>
        <div class="ui-formRow">
            
                     
                
            <div class="size1of2 mrl unit">
                
       
      
                <div class="ui-formRow">
                    <br>
                        
            <input type="submit" name="Registrar" Value="Registrar" style="width:300px; height:40px; " >
</div>
                <br>
                                          
                
        </form>
        
         <script type="text/javascript"> 
            function controltag(e) {
                tecla = (document.all) ? e.keyCode : e.which;
                if (tecla==8) return true;
                else if (tecla==0||tecla==9)  return true;
                patron =/[0-9\s]/;
                te = String.fromCharCode(tecla);
                return patron.test(te);
            }
	</script>    
                        </p>
        </section>
           
            
        
           
        </section> 
        <?php
       error_reporting(E_ERROR || E_WARNING);
       
       
       if(isset($_GET['Registrar'])){  

           
           
          include './ConexionII.php';
          include './GestionDB.php';

         //Para comparar que ambas contraseñas coincidan
            $Contra = $_GET['Contra']; 
            $Contra2 = $_GET['Contra2']; 
         //Para encriptar contraseña
           
            $hash = sha1($Contra);

         
//Necesario para encriptar el password del usuario: http://www.arumeinformatica.es/blog/encriptar-y-guardar-contrasenas-en-base-de-datos/
            
            if(strcmp ($Contra, $Contra2) == 0) {



                $Conexion = new Conexion();
           //Para eliminar contraseña sin encriptar
            unset($Contra);
                $DB = new GestionDBVendedor();
           
           $Con = $Conexion->conect();
           
           $DB->ingresarVendedor(($DB->arregloVendedor($_GET['cedula'], $_GET['nombre'], $_GET['apellido'], $_GET['correo'], $hash, "N")), $Con);
        print '<script language="JavaScript">'; 
        print 'alert("El vendedor ha sido registrado correctamente." )'; 
        print '</script>'; 

        //$DB -> imprimirVendedor();
           
           $Conexion->Cerrar($C);
            }else{
              
print '<script language="JavaScript">'; 
print 'alert("Las contraseñas no conciden!!!")'; 
print '</script>'; 

                //http://www.desarrolloweb.com/articulos/880.php
            }
                    
          
          
       }
        ?>
    </body>
</html>