У меня есть два php файла, и в каждом файле есть код javascript. Я хочу вызвать функцию "fetch_data ()", которая находится в комнатах. php в другом файле verify_booking. php.
Я думал о передаче части скрипта обоих файлов третьей стороне. файл, может быть, это может быть решением или есть способ вызвать fetch_data () непосредственно в файле verify_booking. php?
номеров. php
<?php
include_once 'load_db.php';
$sql = "SELECT * FROM meetingrooms";
$result = mysqli_query($mysqli, $sql);
$rows = mysqli_num_rows($result);
?>
<html>
<head>
<title>[Robos] Raumbuchung</title>
<link rel="stylesheet" href="housekeeping/scripts/bootstrap.min.css" />
<script src="housekeeping/scripts/bootstrap.min.js"></script>
<script src="housekeeping/scripts/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<h4> [Robos] Raumbuchung
<br />
<br />
<div class="table-responsive"> <span id="result"></span>
<div id="mask"></div>
<div id="live_data"></div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
});
// get table
function fetch_data(start_date, end_date, seats, equipment)
{
$.ajax({
url:"rooms_select.php",
method:"POST",
data:{
start_date:start_date,
end_date:end_date,
seats:seats,
equipment:equipment
},
dataType:"text",
success:function(data){
$('#live_data').html(data);
}
});
}
// query mask
function load_engine()
{
$.ajax({
url:"load_engine.php",
method:"POST",
data:{
},
dataType:"text",
success:function(data){
$('#mask').html(data);
}
});
}
load_engine();
$(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
var rows = "<?php echo $rows ?>";
if(keycode == '13'){
fetch_data();
}
});
$(document).on('click', '#btn-apply', function(){
query_request();
});
function logic_check(start_date, end_date, start_time_h, end_time_h, start_time_m, end_time_m)
{
}
function query_request(){
var startdate = document.getElementById("startdate").value;
var enddate = document.getElementById("enddate").value;
var sth_e = document.getElementById("starttime_hour");
var start_time_h = sth_e.options[sth_e.selectedIndex].text;
var eth_e = document.getElementById("endtime_hour");
var end_time_h = eth_e.options[eth_e.selectedIndex].text;
var stm_e = document.getElementById("starttime_min");
var start_time_m = stm_e.options[stm_e.selectedIndex].text;
var etm_e = document.getElementById("endtime_min");
var end_time_m = etm_e.options[etm_e.selectedIndex].text;
var seats_element = document.getElementById("seats");
var seats = seats_element.options[seats_element.selectedIndex].text;
var start_date = startdate + " " + start_time_h + ":" + start_time_m + ":00";
var end_date = enddate + " " + end_time_h + ":" + end_time_m + ":00";
/*
Funktioniert nicht, Mehrfachauswahl wird noch nicht erkannt
auch: später Umsetzung in AJAX Result mehrere Zeilen angeben, for-Schleife?
var equipment = "%";
alert(equipment);
var equipment_element = document.getElementById("equipment");
var equipment = equipment_element.options[equipment_element.selectedIndex].value;
alert(equipment);
if(equipment.text == 'undefined') {equipment = "%";}
alert(equipment);
*/
logic_check(start_date, end_date, start_time_h, end_time_h, start_time_m, end_time_m);
fetch_data(start_date, end_date, seats, "%");
};
function confirm_booking(room_id, start_date, end_date, startdate, enddate, start_time_h, end_time_h, start_time_m, end_time_m, owner){
{
$.ajax({
url:"confirm_booking.php",
method:"POST",
data:{
room_id:room_id,
start_date:start_date,
end_date:end_date,
startdate:startdate,
enddate:enddate,
start_time_h:start_time_h,
end_time_h:end_time_h,
start_time_m:start_time_m,
end_time_m:end_time_m,
owner:owner
},
dataType:"text",
success:function(data){
cb = window.open('confirm_booking.php', '_blank', 'width=600, height=600, location=0, status=1, scrollbars=0, resizable=0, directories=1, toolbar=0, titlebar=0', true);
cb.moveTo(0, 0);
cb.document.write(data);
}
});
}
}
$(document).on('click', '.btn_book', function(){
var room_id = $(this).data("id7");
var startdate = document.getElementById("startdate").value;
var enddate = document.getElementById("enddate").value;
var sth_e = document.getElementById("starttime_hour");
var start_time_h = sth_e.options[sth_e.selectedIndex].text;
var eth_e = document.getElementById("endtime_hour");
var end_time_h = eth_e.options[eth_e.selectedIndex].text;
var stm_e = document.getElementById("starttime_min");
var start_time_m = stm_e.options[stm_e.selectedIndex].text;
var etm_e = document.getElementById("endtime_min");
var end_time_m = etm_e.options[etm_e.selectedIndex].text;
var seats_element = document.getElementById("seats");
var seats = seats_element.options[seats_element.selectedIndex].text;
var owner = "tim@kranz.io";
var start_date = startdate + " " + start_time_h + ":" + start_time_m + ":00";
var end_date = enddate + " " + end_time_h + ":" + (end_time_m - 1) + ":59";
confirm_booking(room_id, start_date, end_date, startdate, enddate, start_time_h, end_time_h, start_time_m, end_time_m, owner);
});
</script>
Подтверждение заказа. php
<?php
include_once 'load_db.php';
$sql = "SELECT * FROM meetingrooms WHERE id = '".$_POST["room_id"]."' ";
$result = mysqli_query($mysqli, $sql);
$result = mysqli_fetch_array($result);
$startdate_f = strtotime($_POST["startdate"]);
$startdate_f = date("d.m.Y", $startdate_f);
$enddate_f = strtotime($_POST["enddate"]);
$enddate_f = date("d.m.Y", $enddate_f);
?>
<html>
<head>
<link rel="stylesheet" href="housekeeping/scripts/bootstrap.min.css" />
<script src="housekeeping/scripts/bootstrap.min.js"></script>
<script src="housekeeping/scripts/jquery.min.js"></script>
<script src="rooms.php" type="text/javascript"></script>
</head>
<body>
<table>
<tr>
<td>
Raumname:
</td>
<td>
<?php echo $result["displayname"]; ?>
</td>
</tr>
<tr>
<td>
Beginn:
</td>
<td>
<?php echo $startdate_f.", ".$_POST["start_time_h"].":".$_POST["start_time_m"] ; ?>
</td>
</tr>
<tr>
<td>
Ende:
</td>
<td>
<?php echo $enddate_f.", ".$_POST["end_time_h"].":".$_POST["end_time_m"] ; ?>
</td>
</tr>
<tr>
<td>
Plätze:
</td>
<td>
<?php echo $result["seats"]; ?>
</td>
</tr>
<tr>
<td>
Etage:
</td>
<td>
<?php echo $result["floor"]; ?>
</td>
</tr>
<tr>
<td>
Bereich:
</td>
<td>
<?php echo $result["floor_area"]; ?>
</td>
</tr>
<tr>
<td>
Raumnummer:
</td>
<td>
<?php echo $result["room_number"]; ?>
</td>
</tr>
</table>
<br><br>
<button type="button" name="booking_btn" id="id_booking_btn" class="btn btn-xs btn-success btn_place_booking">Raum buchen</button>
</body>
</html>
<script>
$(document).ready(function() {
});
function place_booking(room_id, start_date, end_date, owner, catering)
{
$.ajax({
url: "place_booking.php",
method: "POST",
data: {
room_id:room_id,
start_date:start_date,
end_date:end_date,
owner:owner,
catering:catering
},
dataType: "text",
success: function(data) {
document.getElementById("id_booking_btn").disabled = true;
// fetch_data from rooms.php
fetch_data("%", "%", "%", "%");
}
});
}
function prepare_booking() {
var room_id = <?= $_POST["room_id"] ?>;
var startdate = "<?= $_POST["startdate"] ?>";
var enddate = "<?= $_POST["enddate"] ?>";
var start_time_h = <?= $_POST["start_time_h"] ?>;
var end_time_h = <?= $_POST["end_time_h"] ?>;
var start_time_m = <?= $_POST["start_time_m"] ?>;
var end_time_m = <?= $_POST["end_time_m"] ?>;
var start_date = startdate + " " + start_time_h + ":" + start_time_m + ":00";
var end_date = enddate + " " + end_time_h + ":" + (end_time_m - 1) + ":59";
var owner = "<?= $_POST["owner"] ?>";
var catering = 3;
place_booking(room_id, start_date, end_date, owner, catering);
}
$(document).on('click', '.btn_place_booking', function() {
prepare_booking();
});
</script>
Заранее спасибо :)