Ver Mensaje Individual
  #10 (permalink)  
Antiguo 07/09/2008, 10:44
locoxchacho
 
Fecha de Ingreso: septiembre-2008
Ubicación: Nuñez, Capital Federal
Mensajes: 423
Antigüedad: 15 años, 7 meses
Puntos: 1
Respuesta: Consulta en PHP segun Usuario

sigo aca porque no me entraba todo :S

Principal.php
Código:
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php require_once('Connections/conntrio.php'); ?>
<?php require_once('Connections/conntrio.php'); ?>
<?php
//initialize the session
session_start();

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  session_unregister('MM_Username');
  session_unregister('MM_UserGroup');
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO jobs (USER_ID, NOMBRE, FECHA, DESCRIPCION) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['USER_ID'], "int"),
                       GetSQLValueString($_POST['NOMBRE'], "text"),
                       GetSQLValueString($_POST['FECHA'], "date"),
                       GetSQLValueString($_POST['DESCRIPCION'], "text"));

  mysql_select_db($database_conntrio, $conntrio);
  $Result1 = mysql_query($insertSQL, $conntrio) or die(mysql_error());

  $insertGoTo = "principal.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_conntrio, $conntrio);
$query_laburos = "SELECT trabajos.clientes, trabajos.NOMBRE, trabajos.FECHA, trabajos.DESCRIPCION FROM trabajos WHERE trabajos.clientes='MM_Username'";
$laburos = mysql_query($query_laburos, $conntrio) or die(mysql_error());
$row_laburos = mysql_fetch_assoc($laburos);
$totalRows_laburos = mysql_num_rows($laburos);
?>
<html>
<head>
<title>Autentificación PHP</title>
<style type="text/css">
<!--
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.style6 {font-size: 11px}
.style11 {font-family: verdana; font-size: 12px; font-weight: bold; }
-->
</style>
</head>
<body>
<table width="100%"  border="0" cellspacing="10" cellpadding="10">
  <tr>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td><span class="style11">Trabajo</span></td>
        <td><span class="style11">Fecha de Entrega</span></td>
        <td><span class="style11">Descripcion</span></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <?php do { ?>
      <tr>
        <td><?php echo $row_laburos['NOMBRE']; ?></td>
        <td><?php echo $row_laburos['FECHA']; ?></td>
        <td><?php echo $row_laburos['DESCRIPCION']; ?></td>
        <td><span class="style6"></span></td>
        <td><span class="style6"></span></td>
      </tr>
      <?php } while ($row_trabajos = mysql_fetch_assoc($trabajos)); ?>
    </table></td>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<p>
<p><a href="<?php echo $logoutAction ?>">Logout</a></p>
</body>
</html>
<?php
mysql_free_result($laburos);

mysql_free_result($trabajos);
?>
Este es el codigo importante.... aqui, en principal.php, lo primero que hace es verificar que el usuario este logueado. En caso de no estarlo, lo redireccion a la pagina de logueo, en este caso, index.php Si esta logueado, lo deja acceder a la pagina. Una vez en la pagina, automaticamente se ejecuta la consulta
(mysql_select_db($database_conntrio, $conntrio);
$query_laburos = "SELECT trabajos.clientes, trabajos.NOMBRE, trabajos.FECHA, trabajos.DESCRIPCION FROM trabajos WHERE trabajos.clientes=2";
$laburos = mysql_query($query_laburos, $conntrio) or die(mysql_error());
$row_laburos = mysql_fetch_assoc($laburos);
$totalRows_laburos = mysql_num_rows($laburos);)... ahora bien, yo quiero que lo que está pintado de rojo sea automatico, y en vez de poner yo un 2 (dos), se ponga según el ID de usuario que logueo..

Explico un poco mas detalladamente las estructuras de mis tablas, para entender un poco que es lo que quiero hacer..

TABLA USUARIOS: consta de ID_USUARIO, USUARIO, CONTRASEÑA...
TABLA TRABAJOS: consta de ID_TRABAJO, ID_USUARIO, NOMBRE, FECHA, ETC...

como puedes ver, ambos comparten el ID_USUARIO... por tanto, si puedo obtener el ID del usuario que se logueo, por ejemplo, con el nombre "admin", y utilizarlo en la consulta donde esta coloreado de rojo, entonces me dara como resultado las consultas efectivamente del usuario logueado... eso es precisamente lo que quiero hacer...

ahora, vos me decis de utilizar la variable php ID_USUARIO.. eso como lo hago? donde la pongo, en que parte del codigo, etc???

Y por otro lado... cambiando en la URL el ID del usuario, te permitiria ver otra consulta? asi de vulnerable es el sistema que prentedo hacer? loguear cada vez a cada usuario seria una perdida de tiempo para el usuario, por lo que no es una opcion lamentablemente... :S

alguna otra opcion en ese caso??? porque, por ejemplo, como hacen otros sitios que muestra los datos de sus clientes y que los demas no puedan modificar la url para ver otras cosas? ejemplo, E-roche.com

desde ya, muchas gracias...!!!! un saludo enorme,

gracias totales por la ayuda!!!

pablo.