<?php
require_once('../Connections/EVENTS.php');
ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL);

// Función de escape usando mysqli
if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
    global $EVENTS;
    if (PHP_VERSION < 6) {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }
    switch ($theType) {
      case "text":
        $theValue = ($theValue !== "") ? "'" . $EVENTS->real_escape_string($theValue) . "'" : "NULL";
        break;
      case "int": case "long":
        $theValue = ($theValue !== "") ? intval($theValue) : "NULL";
        break;
      case "double":
        $theValue = ($theValue !== "") ? doubleval($theValue) : "NULL";
        break;
      case "date":
        $theValue = ($theValue !== "") ? "'" . $EVENTS->real_escape_string($theValue) . "'" : "NULL";
        break;
      case "defined":
        $theValue = ($theValue !== "") ? $theDefinedValue : $theNotDefinedValue;
        break;
    }
    return $theValue;
  }
}

if (isset($_GET['recordID']) && $_GET['recordID'] !== '') {
  $id = intval($_GET['recordID']);
  $sql = sprintf("DELETE FROM montajes WHERE id_montaje=%s", GetSQLValueString($id, "int"));
  if (!$EVENTS->query($sql)) {
    die("Error al eliminar: " . $EVENTS->error);
  }
  $redirect = 'elimina_montaje_correcto.php' . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
  header("Location: $redirect");
  exit;
} else {
  header('Location: index.php');
  exit;
}
?>
<!DOCTYPE html>
<html><head><meta charset="utf-8"></head><body>



<div class="cuerpo_inserta">

<div class="anuncia_pagina_inserta">
  <strong> MANCOMERAL</strong>
</div>
    
<div class="anuncia_inserta">
    <form action="index.php" method="get" name="form1" target="_self" id="form1">
        <label for="datepicker">SU MONTAJE SE HA ELIMINADO CON ÉXITO</label> 
        ...
    </form>
</div>

</div> <!--FIN DE DIV CUERPO---> 
</body>
</html>