How to leave the options menu different according to profile

0

What would be the code so that according to the user's profile, they may or may not access an option in the menu.

I have the profile table 1-admin , 2-secretaria and 3-gestionhumana . The menu is as follows

!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/stylemenu.css">
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface" rel="stylesheet"> 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="navegacion ">   
<nav class=" menu navegacion-principal navbar navbar-expand-lg navbar-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown active text-light">
<a class="nav-link dropdown-toggle text-light" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-users"></i>Usuarios</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<div class="dropdown-divider"></div>
<span><h5 style="color: black;">Sistema Usuarios</h5></span>
<a class="dropdown-item" href="index2.php?pag=insertarRol">Agregar </a>
<a class="dropdown-item" href="index2.php?pag=consultarRol">Consultar </a>
<a class="dropdown-item" href="index2.php?pag=actualizarRol">Actualizar </a> 
<a class="dropdown-item" href="index2.php?pag=eliminarRol">Eliminar</a>  
</div>
</li>

<li class="nav-item dropdown active text-light">
<a class="nav-link dropdown-toggle text-light" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-calendar"> </i> Citas</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="index2.php?pag=insertarCita">Agregar</a>
<a class="dropdown-item" href="index2.php?pag=consultarCita">Consultar</a>
<a class="dropdown-item" href="index2.php?pag=cancelarCita">Actualizar</a>
</div>
</li>

<li class="nav-item dropdown active text-light">
<a class="nav-link dropdown-toggle text-light" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-book"></i>Reportes</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="index2.php?pag=listarusuarioTabla">Reporte Usuarios</a>
<a class="dropdown-item" href="index2.php?pag=listarafiliacionTabla">Reporte Afiliaciones</a>
<a class="dropdown-item" href="index2.php?pag=listarcitaTabla">Reporte Citas</a>
<a class="dropdown-item" href="index2.php?pag=listarcarteraTabla">Reporte Cartera</a>
</div>
</li>

<ul class="nav-item navbar-nav navbar-right">
<li><a class="text-light" href="salir.php"><span class="glyphicon glyphicon-log-in text-light"></span>Cerrar </a></li>
</ul>
</ul>
</div>
</nav>
</div>
<script type="text/javascript" src="js/jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</body>
</html>

iniciarsesion.php

<?php
session_start();
extract ($_POST);
require "../Modelo/conexionBasesDatos.php";
/* los variables que viene del formulario son: $login, $password */

/*asigno a la variable password el valor encriptado de lo que colocaron
en el password del formulario, ya que así esta en la base de datos */

$pass = md5($_POST['pass']);
$login = $_POST['login'];

$objConexion=Conectarse();
// Vamos a realizar el proceso para consultar los pacientes
//Guardamos en una variable la sentencia sql
$sql="select * from tblusuarios where idUsuario = '$login' and usuPassword = '$pass'";
//Asignar a una variable el resultado de la consulta
$resultado=$objConexion->query($sql);
//verifico si existe el usuario
$existe = $resultado->num_rows;

if ($existe==1)   //quiere decir que los datos estan bien
{
	$usuario=$resultado->fetch_object() or die ("Error");
	$_SESSION['user']= $usuario->idUsuario;	
	header("location:../Vista/index2.php?pag=contenido");
	
}
else 
{
	header("location:../Vista/index2.php?pag=iniciarSesion&x=1");  //x=1, quiere decir que el usuario no esta registrado
}




?>
    
asked by Valentina 28.12.2018 в 16:23
source

2 answers

1

I'm going to give you an example of how you can do it. What I did was create two types of menu.

menuAdmin.php

<p>Menu admin</p>
<p>
<a href="">Ver listado</a>
<a href="">Borrar usuarios</a>
</p>

menuUser.php

<p>Menu usuario</p>
<p>
<a href="">Ver listado</a>
</p>

In the index.php I do the following

<?php
$usuarioNivel = 1;

if($usuarioNivel == 1) {
    include 'menuAdmin.php';
    } else {
        include 'menuUser.php';
}
?>

I use a conditional to say that if the user level is equal to 1 , I include the admin menu, otherwise it will include the user menu. As a result I will get the Admin menu, of course.

What you have to do is replace the data of the variable $usuarioNivel that you will bring it from the database.

This is one way to do it, there can be many more. This is in example mode to guide you. Then you can use features or what you think is right for your app.

    
answered by 28.12.2018 / 20:32
source
1

You must create a sign-in function, in which you define which menu or template the user can see; You could also define session closures with the function and you can not visualize a template without first logging in. With PHP it is an easy way to do it.

Validate some data of the tables ... for example that a certain template or menu appears to a user only if a certain field of the record has certain data.

You can add conditionals to your code ... for example:

if ($tipoUsuario == 1){
## código HTML de la plantilla o menú ##
}

The variable $tipoUsuario must bring a value from the database by means of SQL statements, and according to this variable the menu or template appears.

    
answered by 28.12.2018 в 16:49