Reserva Red Beans

Desde:   Hasta:

Cabaña
Desde
Hasta ( días)
Apellido
Dirección
Teléfono
E-Mail
$/Día (Total: $)
Agencia
Comentarios
  >  
"); print(""); print(""); for ($d = $from; $d <= $to;) { $date = getdate($d); $month = month_name($date["mon"]); $days = cal_days_in_month(CAL_GREGORIAN, $date["mon"], $date["year"]); $remdays = $days - $date["mday"] + 1; print("$month"); $d += $remdays * 86400; } print(""); print(""); print(""); for ($d = $from; $d <= $to; $d += 86400) { $date = getdate($d); print("" . weekday_name($date["wday"]) . "
" . $date["mday"] . ""); } print(""); $result = mysql_query("select * from Building", $conn) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { show_reserve_map_row($row["Id"], $row["Name"]); } mysql_close(); print(""); } function show_reserve_map_row($buildingid, $buildingname) { global $from, $to, $reserveid; $sqlfrom = date("Y/m/d", $from); $sqlto = date("Y/m/d", $to); print(""); print("$buildingname"); $result = mysql_query("SELECT * FROM Reserve WHERE BuildingId = $buildingid " . "AND Reserve.EndDate >= '$sqlfrom' AND Reserve.StartDate <= '$sqlto' ORDER BY StartDate") or die(mysql_error()); $current = $from; while ($row = mysql_fetch_array($result)) { $rowfrom = parse_mysql_date($row["StartDate"]); $rowto = parse_mysql_date($row["EndDate"]); if ($current < $rowfrom) { $emptydays = ($rowfrom - $current) / 86400; print(" "); $current = $rowfrom; } $tooltip = $row["FullName"] . " (" . date("d/m/Y", $rowfrom) . " al " . date("d/m/Y", $rowto) . ")"; if ($rowto > $to) $rowto = $to; $reserveddays = ($rowto - $current) / 86400 + 1; $id = $row["Id"]; $color = '#cc0000'; if ($id == $reserveid) $color = '#ff0000'; print(" "); $current = $rowto + 86400; } if ($current <= $to) { $emptydays = ($to - $current) / 86400 + 1; print(" "); } print(""); } function show_building_combo_contents() { global $conn; global $buildingid; $result = mysql_query("SELECT * FROM Building", $conn) or die(mysql_error()); print(""); while ($row = mysql_fetch_array($result)) { $id = $row["Id"]; $name = $row["Name"]; print(""); } } function show_agency_combo_contents() { global $conn; global $agencyid; $result = mysql_query("SELECT * FROM Agency", $conn) or die(mysql_error()); print(""); while ($row = mysql_fetch_array($result)) { $id = $row["Id"]; $name = $row["Name"]; print(""); } } function load_reserve() { global $reserveid; global $buildingid, $startdate, $enddate, $fullname, $address, $telephone, $email, $agencyid, $comments, $dailyprice, $totaldays; $result = mysql_query("SELECT * FROM Reserve WHERE Id = $reserveid"); $reserve = mysql_fetch_array($result); $start = parse_mysql_date($reserve["StartDate"]); $end = parse_mysql_date($reserve["EndDate"]); $buildingid = $reserve["BuildingId"]; $startdate = date("d/m/Y", $start); $enddate = date("d/m/Y", $end); $fullname = $reserve["FullName"]; $address = $reserve["Address"]; $telephone = $reserve["Telephone"]; $email = $reserve["EMail"]; $agencyid = $reserve["AgencyId"]; $comments = $reserve["Comments"]; $dailyprice = $reserve["DailyPrice"]; $totaldays = unixtojd($end) - unixtojd($start) + 1; } function save_reserve() { global $reserveid; global $conn; global $buildingid, $startdate, $enddate, $fullname, $address, $telephone, $email,$agencyid, $dailyprice, $comments; global $error_building, $error_startdate, $error_enddate, $error_agency, $error, $error_dailyprice; $datefrom = parse_date($startdate); if ($datefrom != null) $from = date("Y-m-d", $datefrom); else $error_startdate = "Fecha inválida"; $dateto = parse_date($enddate); if ($dateto != null) $to = date("Y-m-d", $dateto); else $error_enddate = "Fecha inválida"; $dailyprice = str_replace(",", ".", $dailyprice); if (!is_numeric($dailyprice)) $error_dailyprice = "Valor inválido"; if (!is_numeric($buildingid)) $error_building = "Campo requerido"; else { if ($datefrom != null && $dateto != null) { if ($datefrom > $dateto) $error = "La fecha de inicio no puede ser mayor a la fecha final"; else if (!is_available($buildingid, $datefrom, $dateto, $reserveid)) $error = "La unidad ya se encuentra reservada en las fechas seleccionadas"; } } if (!is_numeric($agencyid)) { $error_agency = "Campo requerido"; } if (empty($error_building) && empty($error_startdate) && empty($error_enddate) && empty($error_agency) && empty($error_dailyprice) && empty($error)) { if (($reserveid == null)) { mysql_query("INSERT INTO Reserve(BuildingId, StartDate, EndDate, FullName, Address, Telephone, EMail, AgencyId, DailyPrice, Comments) VALUES" . "($buildingid, '$from', '$to', '$fullname', '$address', '$telephone', '$email', $agencyid, $dailyprice, '$comments')", $conn) or die(mysql_error()); } else { mysql_query("UPDATE Reserve SET BuildingId = '$buildingid', StartDate = '$from', EndDate = '$to', FullName = '$fullname'," . "Address = '$address', Telephone = '$telephone', EMail = '$email', AgencyId = $agencyid, DailyPrice = $dailyprice, Comments = '$comments' WHERE Id = $reserveid", $conn) or die(mysql_error()); } clear_form(); } } function delete_reserve() { global $reserveid; global $conn; mysql_query("DELETE FROM Reserve WHERE Id = $reserveid", $conn) or die(mysql_error()); clear_form(); } function is_available($buildingid, $startdate, $enddate, $reserveid) { global $conn; $from = date("Y-m-d", $startdate); $to = date("Y-m-d", $enddate); if (!is_numeric($reserveid)) $reserveid = 0; $result = mysql_query("SELECT COUNT(*) FROM Reserve WHERE BuildingId = $buildingid AND Id <> $reserveid AND EndDate >= '$from' AND StartDate <= '$to'", $conn); $row = mysql_fetch_array($result); return $row[0] == 0; } function month_name($i) { switch ($i) { case 1: return "Enero"; case 2: return "Febrero"; case 3: return "Marzo"; case 4: return "Abril"; case 5: return "Mayo"; case 6: return "Junio"; case 7: return "Julio"; case 8: return "Agosto"; case 9: return "Septiembre"; case 10: return "Octubre"; case 11: return "Noviembre"; case 12: return "Diciembre"; } } function weekday_name($i) { switch ($i) { case 0: return "D"; case 1: return "L"; case 2: return "M"; case 3: return "M"; case 4: return "J"; case 5: return "V"; case 6: return "S"; } } function clear_form() { global $reserveid; global $buildingid, $startdate, $enddate, $fullname, $address, $telephone, $email, $agencyid, $dailyprice, $totaldays, $comments; $reserveid = $buildingid = $startdate = $enddate = $fullname = $dailyprice = $totaldays = $address = $telephone = $email = $agencyid = $comments = null; } ?>