jueves, 30 de enero de 2014

REGISTRO DE USUARIOS Y DAR PRIVILEGIOS



index.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
        <script languaje='javascript'>
            function actualizar(n,v,x){
                location.href='index.php?pag=3&id='+n+'&v='+v+'&x='+x;
            }
    </script>
    </head>
    <body>
        <center>
            <h1>REGISTRO DE INFORMACIÓN</h1>
            <table width="100%" border="0px" cellpadding="0" cellspacing="0">
                <tr style="text-align: right;">
                    <td colspan=2><a href="index.php?pag=1">INICIO</a>|<a href="index.php?pag=5">CERRAR SESIÓN</a></td>
                </tr>
                <tr>
                    <td width="200px" style="vertical-align: top;  border: 1px solid #FF9900;">
                        <?php
                            include_once('registro.php');
                        ?>
                    </td>
                    <td height="500px" style="border-top: 1px solid #FF9900;vertical-align: top;">
                        <center>
                        <?php
                            if (isset($_GET['pag'])){
                            switch ($_GET['pag']) {
                                case 1:
                                    include_once('inicio.php');
                                    break;
                                case 2:
                                    include_once('usuarios.php');
                                    break;
                                case 3:
                                    include_once('admin.php');
                                    break;
                                case 4:
                                    include_once('user.php');
                                    break;
                                case 5;
                                    unset($_SESSION['user']);
                                    unset($_SESSION['nivel']);
                                    unset($_SESSION['activo']);
                                    echo "<script languaje='javascript'>location.href='index.php?pag=1'</script>";
                                    break;
                                default:
                                    include_once('inicio.php');
                                    break;
                            }
                            }else
                            include_once('inicio.php');
                        ?>
                        </center>
                    </td>
                </tr>
            </table>
            <hr>
            <font size="2" color="blue">TODOS LOS DERECHOS RESERVADOS <br>Alex Maguana @</font>

        </center>
    </body>
</html>
registro.php
 <?php
session_start();
?>
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <?php
            $error="";
            $conexion=mysql_connect("localhost","root","");
            if(!$conexion)
                die('No se establecio la conexion'.mysql_error());
            else
            {
                mysql_select_db("cuentas",$conexion);
                $name=$passw="";
                if (isset($_POST)){
                    if (isset($_POST['user']))
                        $name=$_POST['user'];
                    if (isset($_POST['passw']))
                        $passw=$_POST['passw'];
                    if ($name!="" && $passw!=""){
                        $sql=mysql_query("select * from usuario where nom_usu='$name' and cla_usu='$passw'");
                        if ($fila=mysql_fetch_array($sql)) {
                            $_SESSION['user']=$fila['nom_usu'];
                            $_SESSION['nivel']=$fila['niv_usu'];
                            $_SESSION['activo']=$fila['est_usu'];
                            if ($fila['niv_usu']==1)
                                echo "<script languaje='javascript'>location.href='index.php?pag=3'</script>";
                            else
                                echo "<script languaje='javascript'>location.href='index.php?pag=4'</script>";
                        }else{
                            $error="NO EXISTE USUARIO REGISTRADO";
                        }
                    }
                }
            }
        ?>
        <form method="POST" acction="index.php?pag=2">
            <table width="100%" border="0px" cellpadding="3" cellspacing="3">
                <tr>
                    <td style="" colspan="2"><center><font color=""><h2>REGISTRO</h2></center></font></td>
                </tr>
                <tr>
                    <td><b>USUARIO</b></td>
                    <td><input type="text" id="user" name="user" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CLAVE</b></td>
                    <td><input type="password" id="passw" name="passw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><input onclick="
                    var u=document.getElementById('user').value;
                    var c=document.getElementById('passw').value;
                    if (u=='' || c=='')
                        alert('REGISTRE DATOS EN LOS TEXTOS POR FAVOR');
                    " type="submit" name="registro" value="INGRESAR AL SISTEMA"/></b></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><a href="index.php?pag=2">REGISTRAR AL SISTEMA</a></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><font color="red"><?php if (isset($error)) echo $error;?></font></b></center></td>
                </tr>
            </table>
        </form>
    </body>
</html>
inicio.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="background: ;heigth:100%" colspan="2"><center><font color="blue"><h1>INICIO DE SISTEMA</h1></center></font></td>
            </tr>
        </table>
    </body>
</html>
usuarios.php
 <?php
    $error="";
    $conexion=mysql_connect("localhost","root","");
    if(!$conexion)
        die('No se establecio la conexion'.mysql_error());
    else
    {
        mysql_select_db("cuentas",$conexion);
        $name=$alias=$passw=$rpassw=$email="";
        if (isset($_POST)){
            if (isset($_POST['name']))
                $name=$_POST['name'];
            if (isset($_POST['alias']))
                $alias=$_POST['alias'];
            if (isset($_POST['passw']))
                $passw=$_POST['passw'];
            if (isset($_POST['rpassw']))
                $rpassw=$_POST['rpassw'];
            if (isset($_POST['email']))
                $email=$_POST['email'];
            if ($name!="" && $alias!="" && $passw!="" && $rpassw!="" && $email!=""){
                if(filter_var($email, FILTER_VALIDATE_EMAIL)){
                    if ($passw==$rpassw){
                        $sql="insert into usuario values('$name','$alias','$passw','$email',3,0)";
                        if (!mysql_query($sql,$conexion))
                            $error="ERROR DE REGISTRO DE USUARIO";
                    }else
                        $error="LAS CLAVES NO COINCIDEN"; 
                }else{
                    $error="ERROR EN REGISTRO DE EMAIL"; 
                }
            }
        }
    }
?>
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <form method="POST" action="index.php?pag=2">
            <table width="300px" border="0px" cellpadding="3" cellspacing="3">
                <tr>
                    <td style="" colspan="2"><center><font color=""><h2>REGISTRO DE USUARIO</h2></center></font></td>
                </tr>
                <tr>
                    <td><b>NOMBRE</b></td>
                    <td><input type="text" id="name" name="name" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>ALIAS</b></td>
                    <td><input type="text" id="alias" name="alias" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CLAVE</b></td>
                    <td><input type="password" id="passw" name="passw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>CONFIRMAR CLAVE</b></td>
                    <td><input type="password" id="rpassw" name="rpassw" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td><b>EMAIL</b></td>
                    <td><input type="text" id="email" name="email" style="width:120px;"/></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><input onclick="
                    var n=document.getElementById('name').value;
                    var a=document.getElementById('alias').value;
                    var p=document.getElementById('passw').value;
                    var r=document.getElementById('rpassw').value;
                    var e=document.getElementById('email').value;
                  
                    if (n=='' || a=='' || e=='')
                        alert('LLENE TODOS LOS REGISTROS PARA ALMACENAR LA INFORMACION DE USUARIO');"
                    type="submit" name="registro" value="REGISTRAR"/></b></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><font color="red"><?php if (isset($error)) echo $error;?></font></b></center></td>
                </tr>
            </table>
        </form>
    </body>
</html>
admin.php
 <!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="heigth:20px" colspan="2">
                    HOLA:
                    <?php
                        if  (isset($_SESSION['user']))
                            echo $_SESSION['user'];
                        else
                            echo "USUARIO SIN REGISTRAR";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            if (isset($_GET['id'])){
                                $user=$_GET['id'];
                                $nivel=$_GET['v'];
                                $estado=$_GET['x'];
                                $sql="update usuario set niv_usu=$nivel, est_usu=$estado where nom_usu='$user'";
                                if (!mysql_query($sql,$conexion))
                                    $error="ERROR DE ACTUALIZACIÓN DE USUARIO";
                                else
                                    echo "<script languaje='javascript'>location.href='index.php?pag=3'</script>";
                            }
                        }
                    ?>  
                </td>
            </tr>
            <tr>
                <td style="heigth:100%" colspan="2">
                    <table border="1px">
                        <tr>
                            <td>NOMBRE</td>
                            <td>ALIAS</td>
                            <td>CLAVE</td>
                            <td>EMAIL</td>
                            <td>NIVEL</td>
                            <td>ESTADO</td>
                            <td>GUARAR</td>
                        </tr>
                        <?php
                        $error="";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            $sql=mysql_query("select * from usuario where niv_usu<>1");
                            $i=0;
                            while ($fila=mysql_fetch_array($sql)) {
                                $nom=$fila['nom_usu'];
                                echo "<tr><td>".$fila['nom_usu']."</td>";
                                echo "<td>".$fila['ali_usu']."</td>";
                                echo "<td>".$fila['cla_usu']."</td>";
                                echo "<td>".$fila['ema_usu']."</td>";
                                $nivel=$fila['niv_usu'];
                                echo "<td><SELECT id='valor$i'>
                                           <OPTION VALUE='2'>2</OPTION>
                                           <OPTION VALUE='3'>3</OPTION>
                                           <OPTION VALUE='4'>4</OPTION>
                                        </SELECT><script>document.getElementById('valor$i').value=$nivel</script></td>";
                                if ($fila['est_usu']==1)
                                    echo "<td><input id='chk$i' type='checkbox' checked='true' /></td>";
                                else
                                    echo "<td><input id='chk$i' type='checkbox'/></td>";
                              
                                echo "<td><a href='#' onclick=\"
                                    actualizar('$nom',document.getElementById('valor$i').value,document.getElementById('chk$i').checked);
                                \">GUARAR</a></td></tr>";
                                $i++;
                            }
                        }
                        ?>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
user.php
<!doctype html>
<html lang="es" id="alex">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>REGISTRO</title>
    </head>
    <body>
        <table width="100%" border="0px" cellpadding="3" cellspacing="3">
            <tr>
                <td style="heigth:20px" colspan="2">
                    HOLA:
                    <?php
                        if  (isset($_SESSION['user']))
                            echo $_SESSION['user'];
                        else
                            echo "USUARIO SIN REGISTRAR";
                    ?>   
                </td>
            </tr>
            <tr>
                <td style="heigth:100%" colspan="2">
                    <table border="1px">
                        <tr>
                            <td>NOMBRE</td>
                            <td>ALIAS</td>
                            <td>CLAVE</td>
                            <td>EMAIL</td>
                            <td>NIVEL</td>
                            <td>ESTADO</td>
                        </tr>
                        <?php
                        $error="";
                        $conexion=mysql_connect("localhost","root","");
                        if(!$conexion)
                            die('No se establecio la conexion'.mysql_error());
                        else
                        {
                            mysql_select_db("cuentas",$conexion);
                            $sql=mysql_query("select * from usuario where niv_usu<>1");
                            while ($fila=mysql_fetch_array($sql)) {
                                $nom=$fila['nom_usu'];
                                echo "<tr><td>".$fila['nom_usu']."</td>";
                                echo "<td>".$fila['ali_usu']."</td>";
                                echo "<td>".$fila['cla_usu']."</td>";
                                echo "<td>".$fila['ema_usu']."</td>";
                                $nivel=$fila['niv_usu'];
                                echo "<td>$nivel</td>";
                                if ($fila['est_usu']==1)
                                    echo "<td>Activado</td>";
                                else
                                    echo "<td>Desactivado</td>";
                            }
                        }
                        ?>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
bbdd.sql
drop TABLE usuario
create TABLE usuario(
nom_usu varchar(50) primary key,
ali_usu varchar(50),
cla_usu varchar(50),
ema_usu varchar(50),
niv_usu int,
est_usu tinyint)
EJECUCION

Al iniciar con el servidor localhost nos muestra la siguiente ventana.

 Al hacer clic en REGISTRAR AL SISTEMA nos muestra la siguiente ventana donde llenamos los siguientes campos y guardamos.


Al entrar como el usuario que ya registramos nos muestra la siguiente tabla con todos los usuarios registrados y sus privilegios  el nivel y estado en que se encuentra.

Al entrar como administrador .


Nos muestra la siguiente tabla donde se puede dar los privilegios el numero de nivel y actibar o desactibar el estado y duardamos.
 Verificamos la cuenta del usuario y vemos que ya tine un nivel 2 y esta activado


No hay comentarios:

Publicar un comentario