Example #1
0
 public function backup()
 {
     $conexion = new DB();
     $backup = "------------------------------------------------------------------------\n";
     $backup .= "--                         CONFIDENT BACKUP                          \n";
     $backup .= "-- DATABASE: " . strtoupper($conexion->database) . "\n";
     $backup .= "-- HOST: " . $conexion->host . "         PORT: " . $conexion->port . "\n";
     $backup .= "-- MYSQL SERVER " . self::query('SELECT VERSION() as version;')->getFirst()->version . "\n";
     $backup .= "-----------------------------------------------------------------------\n\n";
     $backup .= "CREATE DATABASE IF NOT EXISTS `" . $conexion->database . "` ";
     $backup .= "/*!40100 DEFAULT CHARACTER SET " . self::query('select @@character_set_database as charset;')->getFirst()->charset . "*/;\n";
     $backup .= "USE `" . $conexion->database . "`;\n\n";
     $backup .= "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n";
     $backup .= "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n";
     $backup .= "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n";
     $backup .= "/*!40101 SET NAMES utf8 */;\n";
     $backup .= "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n";
     $backup .= "/*!40103 SET TIME_ZONE='+00:00' */;\n";
     $backup .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n";
     $backup .= "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n";
     $backup .= "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n";
     $backup .= "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n";
     $tablas = $conexion->consultar('SHOW TABLES');
     while ($tabla = $tablas->fetch_array(MYSQLI_NUM)) {
         $create = 'DROP TABLE IF EXISTS `' . $tabla[0] . "`;\n";
         $create .= "/*!40101 SET @saved_cs_client = @@character_set_client */;\n";
         $create .= "/*!40101 SET character_set_client = utf8 */;\n";
         $object = $conexion->consultar('SHOW CREATE TABLE ' . $tabla[0])->fetch_array(MYSQLI_NUM);
         $create .= $object[1] . ";\n";
         $create .= "/*!40101 SET character_set_client = @saved_cs_client */;\n\n";
         $backup .= $create;
         $backup .= "/*!40000 ALTER TABLE `" . $tabla[0] . "` DISABLE KEYS */;\n";
         $query = 'REPLACE INTO `' . $tabla[0] . '`';
         // HACIENDO DUMP DE LOS CAMPOS
         $atributos = '';
         $columnas = $conexion->consultar('DESCRIBE ' . $tabla[0]);
         while ($columna = $columnas->fetch_array(MYSQLI_ASSOC)) {
             $atributos .= $columna['Field'] . ',';
         }
         $query .= '(' . $atributos . ") VALUES \n";
         // HACIENDO DUMP DE LOS DATOS
         $datos = '';
         $insertados = $conexion->consultar('SELECT * FROM ' . $tabla[0]);
         while ($fila = $insertados->fetch_array(MYSQLI_ASSOC)) {
             $datos .= "(";
             foreach ($fila as $key => $value) {
                 $type = self::table($tabla[0])->COLUMN_TYPE($key);
                 if ($type === 'STRING' || $type === 'DATE') {
                     $datos .= '\'' . $value . '\',';
                 } else {
                     $datos .= $value . ',';
                 }
             }
             $datos .= "),\n";
         }
         $query .= $datos . '~';
         // SI NO HAY DATOS, NO SE A√ĎADE EL INSERT
         if (self::count_rows($insertados) > 0) {
             $query = str_replace(',)', ')', $query);
             $query = str_replace('(,', '(', $query);
             $query = str_replace("),\n~", ");", $query);
             $backup .= $query . "\n";
         }
         $backup .= "/*!40000 ALTER TABLE `" . $tabla[0] . "` ENABLE KEYS */;\n\n";
     }
     $backup .= "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n";
     $backup .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n";
     $backup .= "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n";
     $backup .= "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n";
     $backup .= "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n";
     $backup .= "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n";
     $backup .= "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n";
     $backup .= "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n\n";
     $backup .= "------------------------------------------------------------------------\n";
     $backup .= "--                    CONFIDENT BACKUP COMPLETADO                       \n";
     $backup .= "------------------------------------------------------------------------\n";
     file_put_contents(strtoupper($conexion->database) . '_BACKUP_' . date('d-M-Y') . '.sql', $backup);
     return $create . $backup;
 }
include 'DB.php';
$db = new DB();
if (isset($_POST["fechae"]) == true && $_POST["fechae"] != "" && (isset($_POST["fechas"]) == true && $_POST["fechas"] != "")) {
    if (isset($_POST["cat"]) == true && $_POST["cat"] != "" && (isset($_POST["tip"]) == true && $_POST["tip"] != "")) {
        /* CONSULTA 2
           si el tipo es individual
               -- Habitaciones disponibles dado un rango de fecha, un tipo y una categoria.
               -- Leyenda:
               -- tipo_usuario: este es el tipo de habitacion pedida por el usuario.
               -- categoria_usuario: este es la categoria de la habitacion pedida por el usuario. */
        echo '<br>' . "<div align=\"center\">Consulta Habitaciones Disponibles Desde:     " . $_POST["fechae"] . '<br>';
        echo "<div align=\"center\">Consulta Habitaciones Disponibles Hasta:        " . $_POST["fechas"] . '<br>';
        echo "<div align=\"center\">Categoria de la Habitacion:     " . $_POST["cat"] . '<br>';
        echo "<div align=\"center\">Tipo de la Habitacion:      " . $_POST["tip"] . '<br>' . "<br>";
        $consulta = "(SELECT (numero_habitacion) as Habitacion, (tipo) as Tipo, (categoria) as Categoria FROM habitacion WHERE habitacion.tipo = '" . $_POST["tip"] . "' AND habitacion.categoria = '" . $_POST["cat"] . "' AND habitacion.numero_habitacion NOT IN (SELECT DISTINCT(numero_habitacion) FROM se_reserva UNION SELECT DISTINCT(numero_habitacion) FROM ocupa WHERE ('" . $_POST["fechae"] . "' <= ocupa.fecha_llegada AND '" . $_POST["fechas"] . "' >= ocupa.fecha_llegada) OR ('" . $_POST["fechae"] . "' <= ocupa.fecha_salida AND '" . $_POST["fechas"] . "' >= ocupa.fecha_salida) OR ('" . $_POST["fechae"] . "' >= ocupa.fecha_salida AND '" . $_POST["fechas"] . "' <= ocupa.fecha_salida))) UNION (SELECT se_reserva.numero_habitacion, tipo, categoria FROM se_reserva, reservacion, habitacion WHERE se_reserva.id = reservacion.id AND se_reserva.numero_habitacion = habitacion.numero_habitacion AND habitacion.tipo = '" . $_POST["tip"] . "' AND habitacion.categoria = '" . $_POST["cat"] . "' AND (('" . $_POST["fechae"] . "' < reservacion.fecha_llegada AND '" . $_POST["fechas"] . "' < reservacion.fecha_llegada) OR ('" . $_POST["fechae"] . "' > reservacion.fecha_salida AND '" . $_POST["fechas"] . "' > reservacion.fecha_salida)))";
        $resultados = $db->consultar($consulta);
        $num_rows = mysql_num_rows($resultados);
        if ($_POST["tip"] == 'individual') {
            if ($num_rows != 0) {
                echo "<div align=\"center\"><table border = '1'>";
                echo "<tr> ";
                echo "<td><b>Habitacion</b></td>";
                echo "<td><b>Tipo</b></td> ";
                echo "<td><b>Categoria</b></td>";
                echo "</tr> ";
                while ($row = mysql_fetch_array($resultados)) {
                    echo "<td>" . $row["Habitacion"] . "</td>";
                    echo "<td>" . $row["Tipo"] . "</td> ";
                    echo "<td>" . $row["Categoria"] . "</td> ";
                    echo "</tr> ";
                }