<center><H1> ABOGADOS, S.C.</H1></center>

<center><h1>Formulario</h1></center>
<br>
</br>
<?php require_once('Connections/AbogadosSC.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE formulario SET empresa=%s, email=%s, mensaje=%s WHERE nombre=%s",
                       GetSQLValueString($_POST['empresa'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['mensaje'], "text"),
                       GetSQLValueString($_POST['nombre'], "text"));

  mysql_select_db($database_AbogadosSC, $AbogadosSC);
  $Result1 = mysql_query($updateSQL, $AbogadosSC) or die(mysql_error());

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

$maxRows_Registros = 10;
$pageNum_Registros = 0;
if (isset($_GET['pageNum_Registros'])) {
  $pageNum_Registros = $_GET['pageNum_Registros'];
}
$startRow_Registros = $pageNum_Registros * $maxRows_Registros;

mysql_select_db($database_AbogadosSC, $AbogadosSC);
$query_Registros = "SELECT * FROM formulario";
$query_limit_Registros = sprintf("%s LIMIT %d, %d", $query_Registros, $startRow_Registros, $maxRows_Registros);
$Registros = mysql_query($query_limit_Registros, $AbogadosSC) or die(mysql_error());
$row_Registros = mysql_fetch_assoc($Registros);

if (isset($_GET['totalRows_Registros'])) {
  $totalRows_Registros = $_GET['totalRows_Registros'];
} else {
  $all_Registros = mysql_query($query_Registros);
  $totalRows_Registros = mysql_num_rows($all_Registros);
}
$totalPages_Registros = ceil($totalRows_Registros/$maxRows_Registros)-1;
?>
<!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>Documento sin título</title>
</head>

<body>
<table width="731" height="53" border="1">
  <tr>
    <td width="172" height="23">Nombre</td>
    <td width="140">Empresa</td>
    <td width="147">Email</td>
    <td width="244">Mensaje</td>
    <td width="140">Modificar</td>
    <td width="140">Eliminar</td>
  </tr>
  <?php do { ?>
  <tr>
    <td height="22"><?php echo $row_Registros['nombre']; ?></td>
    <td><?php echo $row_Registros['empresa']; ?></td>
    <td><?php echo $row_Registros['email']; ?></td>
    <td><?php echo $row_Registros['mensaje']; ?></td>
    
    <td><a href="Modificar.php?nombre=<?php echo $row_Registros['nombre'];?>">modificar</a></td>
    
    <td><a href="Eliminar.php?nombre=<?php echo $row_Registros['nombre'];?>">eliminar</a></td>
  </tr>
  <?php } while ($row_Registros = mysql_fetch_assoc($Registros)); ?>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Registros);
?>
