Ver Mensaje Individual
  #27 (permalink)  
Antiguo 09/05/2008, 09:06
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 2 meses
Puntos: 20
Re: Limite en un user

aca tenes un script con un contador y todo bien completito...

Tabla: controlborrar
campos: (UserID, Fecha)
----------
Tabla: registros
campos: (idregistro, titulo, texto)

Código PHP:
<?php require_once('Connections/testsite.php'); ?>
<?php
$USERID
="1"// reemplazar por la variable que trae el id puede ser de sesion..
$hoy=date("Y-m-d H:i:s");

// comando anti inyeccion sql que genera dreamweaver
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

$hoyini=date("Y-m-d")." 00:00:00";
$hoyfin=date("Y-m-d")." 23:59:59";
mysql_select_db($database_testsite$testsite);
$query_contolborra "SELECT count(*) as total FROM controlborrar WHERE UserID = '$USERID' AND Fecha >= '$hoyini' AND Fecha <= '$hoyfin' ";
$contolborra mysql_query($query_contolborra$testsite) or die(mysql_error());
$row_contolborra mysql_fetch_assoc($contolborra);
$totalRows_contolborra mysql_num_rows($contolborra);
$borrar="";
if(
$row_contolborra['total'] < "3"){
$borrar="SI";
}else{
$borrar="NO";
}

mysql_free_result($contolborra);
if ((isset(
$_GET['idregistro'])) && ($_GET['idregistro'] != "")) {
if (
$borrar == "SI") {

 
// aca borra
  
$deleteSQL sprintf("DELETE FROM registros WHERE idregistro=%s",
                       
GetSQLValueString($_GET['idregistro'], "int"));

  
mysql_select_db($database_testsite$testsite);
  
$Result1 mysql_query($deleteSQL$testsite) or die(mysql_error());
  
  
// aca inserta quien borro y la fecha
  
$insertSQL sprintf("INSERT INTO controlborrar (UserID, Fecha) VALUES (%s, %s)",
                       
GetSQLValueString($USERID"int"),
                       
GetSQLValueString($hoy"date"));

  
mysql_select_db($database_testsite$testsite);
  
$Result2 mysql_query($insertSQL$testsite) or die(mysql_error());
  
$msg="";
}else{
 
$msg="?msg=Solo puedes borrar 3 registros por dia";
}  
// direcciona a index
  
$deleteGoTo "index.php".$msg;

  
header(sprintf("Location: %s"$deleteGoTo));
}


$USERID="1"// reemplazar por la variable que trae el id puede ser de sesion..
mysql_select_db($database_testsite$testsite);
$query_registros "SELECT idregistro, titulo, texto FROM registros";
$registros mysql_query($query_registros$testsite) or die(mysql_error());
$row_registros mysql_fetch_assoc($registros);
$totalRows_registros mysql_num_rows($registros);

$hoyini=date("Y-m-d")." 00:00:00";
$hoyfin=date("Y-m-d")." 23:59:59";
mysql_select_db($database_testsite$testsite);
$query_contolborra "SELECT count(*) as total FROM controlborrar WHERE UserID = '$USERID' AND Fecha >= '$hoyini' AND Fecha <= '$hoyfin' ";
$contolborra mysql_query($query_contolborra$testsite) or die(mysql_error());
$row_contolborra mysql_fetch_assoc($contolborra);
$totalRows_contolborra mysql_num_rows($contolborra);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Borraste hasta ahora: <strong><?php echo $row_contolborra['total']; ?></strong> registro<br /><br />
<?php if (($_GET['msg'] != "") && ($row_contolborra['total'] >= "3")){ ?>Acceso Denegado: <?php echo $_GET['msg']; ?><?php ?><br /><br />
<?php do { ?>
  <?php echo $row_registros['titulo']; ?> - <a href="index.php?idregistro=<?php echo $row_registros['idregistro']; ?>">Borrar</a><br />
  <?php } while ($row_registros mysql_fetch_assoc($registros)); ?>
</body>
</html>
<?php
mysql_free_result
($registros);
?>

hace casi lo mismo que lo que posteo misko.. con 1 diferencia...

este en ves de update hace insert... entonces podes llevar un registro de borrados anteriores de los usuarios incluso tener un top 10 de los mas borradores...

ejemplo: si mas adelante queres ver quien es el que todos los dias borra minimo 3...
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)