Code: Select all
// Fields of Main from
$actDateStart = "#act_start#";
$actDateEnd = "#act_eind#";
$actTimeStart = "#act_uur_start#";
$actTimeEnd = "#act_uur_end#";
$actLocation = "#act_lokaal#";
// Get all dates from start to end
$dates = dateRange($actDateStart, $actDateEnd);
$msg = "";
// Loop through dates
foreach ($dates as $date) {
// Check in reservaties if there's already a row with the same date, "lookal" etc.
$sql = "
SELECT * FROM
reservaties
WHERE
res_datum = :act_date AND
res_lokaal = :act_location
-- add other criterias here
";
// sql arguments
$arg = array(
"act_date" => $date,
"act_lokaal" => $actLocation,
"act_uur_start" => $actTimeStart,
"act_uur_end" => $actTimeEnd
);
$r = nuRunQuery($sql, $arg);
if (db_num_rows($r) != 0) {
$mgs .= "Not available on $date";
}
}
if ($msg != '') {
nuDisplayError($msg);
} else {
nuDisplayError("Free.");
foreach ($dates as $date){
addReservation($date, $actTimeStart, $actTimeEnd , $res_lokaal);
}
}
function dateRange( $first, $last, $step = '+1 day', $format = 'Y-m-d' ) {
$dates = [];
$current = strtotime( $first );
$last = strtotime( $last );
while( $current <= $last ) {
$dates[] = date( $format, $current );
$current = strtotime( $step, $current );
}
return $dates;
}
function addReservation($res_datum, $actTimeStart,$actTimeEnd, $res_lokaal) {
$q = "
INSERT INTO reservaties (res_id, res_datum, actTimeStart, actTimeEnd, res_lokaal)
VALUES(?,?,?,?,?)
";
$t = nuRunQuery($q, [nuID(), $res_datum, $actTimeStart, $actTimeEnd, $res_lokaal]);
}