I want to check if a user entered a time (start, end) which already exist or have a conflict with the times out of the foreach.

I tried to put the existing times in an array to check the new user data with the data from the array but it didnt worked :I

if(isset($_POST['submit'])){
    $mitarbeitername = $_POST['mitarbeiter'];
    //echo "Organisator: " .$mitarbeitername;

    $reservierungvon = $_POST['zeitstart'];
    //echo "Von: " .$reservierungvon;

    $reservierungbis = $_POST['zeitende'];
    //echo "Bis: " .$reservierungbis;
}

foreach($value as $value) {
    $startarray[] = $start = $value->Start->DateTime;($value);
}

$checkendtime = array();
foreach($value as $value) {
    $endarray[] = $start = $value->End->DateTime;($value);
}

if ($reservierungvon == $startarray || $reservierungbis == $endarray || $reservierungvon < $startarray && $endarray > $reservierungbis) {
    echo "conflict!";
} else {
    echo "no conflict!";
}

This is the foreach where im getting the existing meeting-times:

foreach ($result->value as & $value) {
                $start = $value->Start->DateTime;
                $start = substr($start, 11, -11);
                $ende = $value->End->DateTime;
                $ende = substr($ende, 11, -11);
                $organisierer = $value->Organizer->EmailAddress->Name;
}

And in this form the user can create new meetings if there isnt some conflicts with existings meetings:

<label for="psw"><br><b>Zeit der Reservierung:</b></label><br>
von <input type="time" name="timestart"> Uhr bis <input type="time" name="timeend"> Uhr <br>

It would be great if I can check the times out of the foreach with the new times from the user.

The user will get a message if there is a conflict or not. So he can correct his times.

Thanks for any help! :)

1 Answers

0
Eriks Klotins On Best Solutions

You need to check in the loop or otherwise the following scenarios:

For each existing interval (B):

  1. The entered interval starts within B
  2. The entered interval ends within B
  3. The entered interval starts before B and ends after B

if any of these are TRUE you have a conflict, otherwise not.