include_once("inc/conexion.php"); include_once("inc/conexion_notis.php"); $referencia = $_GET['s'] ?? ''; $selected_cat = $_GET['cat'] ?? ''; $fecha_inicio = $_GET['fecha_inicio'] ?? ''; $fecha_fin = $_GET['fecha_fin'] ?? ''; // Construir condiciones dinámicas $conditions = []; if ($referencia != "") { $date_query = ""; if (preg_match('/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})$/', $referencia, $matches)) { $day = intval($matches[1]); $month = intval($matches[2]); $year = intval($matches[3]); if ($year < 100) { $year += 2000; } if (checkdate($month, $day, $year)) { $mysql_date = sprintf("%04d-%02d-%02d", $year, $month, $day); $date_query = " OR fecha like '%" . $mysql_date . "%'"; } } $conditions[] = "(titulo like '%" . $referencia . "%' OR fecha like '%" . $referencia . "%'" . $date_query . ")"; } if ($selected_cat != "") { $conditions[] = "categoria = '" . intval($selected_cat) . "'"; } if ($fecha_inicio != "") { $conditions[] = "fecha >= '" . $mysqli->real_escape_string($fecha_inicio) . " 00:00:00'"; } if ($fecha_fin != "") { $conditions[] = "fecha <= '" . $mysqli->real_escape_string($fecha_fin) . " 23:59:59'"; } $cond_sql = ""; if (count($conditions) > 0) { $cond_sql = implode(" AND ", $conditions); } // Paginación $por_pagina = 12; $pagina_actual = isset($_GET['pagina']) ? intval($_GET['pagina']) : 1; if ($pagina_actual < 1) $pagina_actual = 1; $offset = ($pagina_actual - 1) * $por_pagina; // Contar registros totales $count_cond = $cond_sql != "" ? "WHERE $cond_sql AND mostrar = 1" : "WHERE mostrar = 1"; $count_res = $mysqli->query("SELECT COUNT(*) as total FROM noticias $count_cond"); $total_records = 0; if ($count_res) { $count_row = $count_res->fetch_assoc(); $total_records = intval($count_row['total']); } $limit_sql = "desc limit $offset, $por_pagina"; if ($cond_sql != "") { $not = tomarRegistrosCondicion($mysqli, "noticias", "id", $limit_sql, $cond_sql . " AND mostrar = 1"); } else { $not = tomarRegistrosCondicion($mysqli, "noticias", "id", $limit_sql, "mostrar = 1"); } $categorias_filtro = tomarRegistros($mysqli, "categorias", "nombre", "asc"); $params = $_GET; $params['pagina'] = $pagina_actual; $base_url = 'buscar.php?' . http_build_query($params); ?>
include("parts/head.php"); ?> include("parts/headerMovil.php"); ?>