Esempio n. 1
0
function is_available($room_id, $checkin, $checkout)
{
    if (check_availability($room_id, $checkin, $checkout) == 0) {
        return true;
    } else {
        return false;
    }
}
/**
 * Function that is called when form is submitted, central hub function.
 *
 * @param int $room id of room @link get_room_id()
 * @param int $fromTime start of reservation (UNIX timstamp)
 * @param int $toTime end of reservation (UNIX timestamp)
 * @param string $subject subject of meeting
 * @param string $category category of meeting
 * @param string $description description of meeting
 * @param int $allday 1=allday 0=no
 * @param string $recurrence_type different keywords TBD
 * @param string $params javascript array (comma delimited)
 *
 * @return boolean $success
 */
function recurrence_check($room, $fromTime, $toTime, $recurrence_type, $parameters)
{
    //Take parameters and convert to array
    $parameters = urldecode($parameters);
    $params = explode(';', $parameters);
    $CHECK_BOOL = true;
    //No recursion
    if ($recurrence_type == 'none') {
        if ($params[0] == 'id') {
            $CHECK_BOOL = check_availability_excluding_id($room, $fromTime, $toTime, $params[1]);
            if ($CHECK_BOOL) {
                return $CHECK_BOOL;
            }
        } else {
            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
            if ($CHECK_BOOL) {
                return $CHECK_BOOL;
            }
        }
    } else {
        if ($recurrence_type == 'everyxdays') {
            $endtype = $params[0];
            $endtype_param = $params[1];
            $xdays = $params[2];
            if ($xdays <= 0 || $endtype_param < 0) {
            } else {
                if ($endtype == 'endby') {
                    while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                        $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                        if ($CHECK_BOOL) {
                            return $CHECK_BOOL;
                        }
                        $fromTime += $xdays * (24 * 60 * 60);
                        $toTime += $xdays * (24 * 60 * 60);
                    }
                } else {
                    if ($endtype == 'endafter') {
                        for ($occurences = 1; $occurences <= $endtype_param; $occurences++) {
                            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                            if ($CHECK_BOOL) {
                                return $CHECK_BOOL;
                            }
                            $fromTime += $xdays * (24 * 60 * 60);
                            $toTime += $xdays * (24 * 60 * 60);
                        }
                    }
                }
            }
        } else {
            if ($recurrence_type == 'everyweekday') {
                $endtype = $params[0];
                $endtype_param = $params[1];
                //Condition 1: End by
                if ($endtype == 'endby') {
                    while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                        $dayofweek = strftime_dayofweek_compatible($fromTime);
                        if ($dayofweek == 6 || $dayofweek == 7) {
                        } else {
                            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                            if ($CHECK_BOOL) {
                                return $CHECK_BOOL;
                            }
                        }
                        $fromTime += 1 * (24 * 60 * 60);
                        $toTime += 1 * (24 * 60 * 60);
                    }
                } else {
                    if ($endtype == 'endafter') {
                        $occurences = 0;
                        while ($occurences < $endtype_param) {
                            $dayofweek = strftime_dayofweek_compatible($fromTime);
                            if ($dayofweek == 6 || $dayofweek == 7) {
                            } else {
                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                if ($CHECK_BOOL) {
                                    return $CHECK_BOOL;
                                }
                                $occurences++;
                            }
                            $fromTime += 1 * (24 * 60 * 60);
                            $toTime += 1 * (24 * 60 * 60);
                        }
                    }
                }
            } else {
                if ($recurrence_type == 'everyxweeks') {
                    $endtype = $params[0];
                    $endtype_param = $params[1];
                    $xweeks = $params[2];
                    $dayofweek = explode('?', $params[3]);
                    if ($xweeks <= 0 || $xweeks > 48 || $endtype_param < 0) {
                    } else {
                        if ($endtype == 'endby') {
                            $counter = 0;
                            while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                                if ($counter == 0) {
                                    for ($day = 1; $day <= 7; $day++) {
                                        $dayofweek_temp = strftime_dayofweek_compatible($fromTime);
                                        if (in_array($dayofweek_temp, $dayofweek)) {
                                            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                            if ($CHECK_BOOL) {
                                                return $CHECK_BOOL;
                                            }
                                        }
                                        $fromTime += 1 * (24 * 60 * 60);
                                        $toTime += 1 * (24 * 60 * 60);
                                    }
                                    $counter++;
                                } else {
                                    if ($counter == $xweeks) {
                                        $counter = 0;
                                    } else {
                                        if ($counter != 0) {
                                            for ($day = 1; $day <= 7; $day++) {
                                                $fromTime += 1 * (24 * 60 * 60);
                                                $toTime += 1 * (24 * 60 * 60);
                                            }
                                            $counter++;
                                        }
                                    }
                                }
                            }
                        } else {
                            if ($endtype == 'endafter') {
                                $occurences = 0;
                                $counter = 0;
                                while ($occurences < $endtype_param) {
                                    if ($counter == 0) {
                                        for ($day = 1; $day <= 7; $day++) {
                                            $dayofweek_temp = strftime_dayofweek_compatible($fromTime);
                                            if (in_array($dayofweek_temp, $dayofweek)) {
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                            }
                                            $fromTime += 1 * (24 * 60 * 60);
                                            $toTime += 1 * (24 * 60 * 60);
                                        }
                                        $counter++;
                                        $occurences++;
                                    } else {
                                        if ($counter == $xweeks) {
                                            $counter = 0;
                                        } else {
                                            if ($counter != 0) {
                                                for ($day = 1; $day <= 7; $day++) {
                                                    $fromTime += 1 * (24 * 60 * 60);
                                                    $toTime += 1 * (24 * 60 * 60);
                                                }
                                                $counter++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if ($recurrence_type == 'everyxmonthxday') {
                        $endtype = $params[0];
                        $endtype_param = $params[1];
                        $xmonths_param = $params[3];
                        $dayofmonth_param = $params[2];
                        if ($dayofmonth_param <= 0 || $dayofmonth_param > 31 || $xmonths_param <= 0 || $endtype_param < 0) {
                        }
                        //Condition 1: End by
                        if ($endtype == 'endby') {
                            $counter = 0;
                            while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                                $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                while ($firstmatch == 0) {
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    if ($dayofmonth == $dayofmonth_param) {
                                        $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                        if ($CHECK_BOOL) {
                                            return $CHECK_BOOL;
                                        }
                                        $firstmatch = 1;
                                    }
                                    $fromTime += 24 * 60 * 60;
                                    $toTime += 24 * 60 * 60;
                                }
                                if ($dayofmonth == $dayofmonth_param && $counter == 0) {
                                    $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                    if ($CHECK_BOOL) {
                                        return $CHECK_BOOL;
                                    }
                                    $fromTime += 24 * 60 * 60;
                                    $toTime += 24 * 60 * 60;
                                } else {
                                    $fromTime += 24 * 60 * 60;
                                    $toTime += 24 * 60 * 60;
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                }
                                $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                if ($dayofmonth == 01) {
                                    $counter++;
                                }
                                if ($dayofmonth_param == 29) {
                                    if ($dayofmonth == 28) {
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        if ($dayofmonth == 01) {
                                            $counter--;
                                        }
                                        $fromTime -= 24 * 60 * 60;
                                        $toTime -= 24 * 60 * 60;
                                    }
                                }
                                if ($dayofmonth_param == 30) {
                                    if ($dayofmonth == 29) {
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        if ($dayofmonth == 01) {
                                            $counter--;
                                        }
                                        $fromTime -= 24 * 60 * 60;
                                        $toTime -= 24 * 60 * 60;
                                    }
                                }
                                if ($dayofmonth_param == 31) {
                                    if ($dayofmonth == 30) {
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        if ($dayofmonth == 01) {
                                            $counter--;
                                        }
                                        $fromTime -= 24 * 60 * 60;
                                        $toTime -= 24 * 60 * 60;
                                    }
                                }
                                if ($counter == $xmonths_param) {
                                    $counter = 0;
                                    $occurences++;
                                }
                            }
                        } else {
                            if ($endtype == 'endafter') {
                                $counter = 0;
                                $occurences = 0;
                                $firstmatch = 0;
                                while ($occurences < $endtype_param) {
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    while ($firstmatch == 0) {
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        if ($dayofmonth == $dayofmonth_param) {
                                            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                            if ($CHECK_BOOL) {
                                                return $CHECK_BOOL;
                                            }
                                            $firstmatch = 1;
                                            $occurences++;
                                        }
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                    }
                                    if ($dayofmonth == $dayofmonth_param && $counter == 0) {
                                        $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                        if ($CHECK_BOOL) {
                                            return $CHECK_BOOL;
                                        }
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                    } else {
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    }
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    if ($dayofmonth == 01) {
                                        $counter++;
                                    }
                                    if ($dayofmonth_param == 29) {
                                        if ($dayofmonth == 28) {
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                            $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                            if ($dayofmonth == 01) {
                                                $counter--;
                                            }
                                            $fromTime -= 24 * 60 * 60;
                                            $toTime -= 24 * 60 * 60;
                                        }
                                    }
                                    if ($dayofmonth_param == 30) {
                                        if ($dayofmonth == 29) {
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                            $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                            if ($dayofmonth == 01) {
                                                $counter--;
                                            }
                                            $fromTime -= 24 * 60 * 60;
                                            $toTime -= 24 * 60 * 60;
                                        }
                                    }
                                    if ($dayofmonth_param == 31) {
                                        if ($dayofmonth == 30) {
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                            $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                            if ($dayofmonth == 01) {
                                                $counter--;
                                            }
                                            $fromTime -= 24 * 60 * 60;
                                            $toTime -= 24 * 60 * 60;
                                        }
                                    }
                                    if ($counter == $xmonths_param) {
                                        $counter = 0;
                                        $occurences++;
                                    }
                                }
                            }
                        }
                    } else {
                        if ($recurrence_type == 'thexyofeveryzmonths') {
                            $endtype = $params[0];
                            $endtype_param = $params[1];
                            $numberdate_param = $params[2];
                            $dayofweek_param = $params[3];
                            $xmonths_param = $params[4];
                            if ($xmonths_param <= 0 || $endtype_param < 0) {
                            }
                            //Condition 1: End by
                            if ($endtype == 'endby') {
                                $numberdatecounter = 0;
                                $xmonthscounter = 0;
                                $firstmatch = 0;
                                while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                                    $dayofweek = strftime_dayofweek_compatible($fromTime);
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    while ($firstmatch == 0) {
                                        if ($dayofweek == $dayofweek_param) {
                                            $numberdatecounter++;
                                            if ($numberdatecounter == $numberdate_param && $xmonthscounter == 0) {
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                                //$xmonthscounter++;
                                                $firstmatch = 1;
                                            }
                                        }
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        $dayofweek = strftime_dayofweek_compatible($fromTime);
                                        if ($dayofmonth == 01) {
                                            $numberdatecounter = 0;
                                        }
                                    }
                                    if ($dayofweek == $dayofweek_param) {
                                        $numberdatecounter++;
                                        if ($numberdatecounter == $numberdate_param) {
                                            $xmonthscounter++;
                                            if ($xmonthscounter == $xmonths_param) {
                                                $xmonthscounter = 0;
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                            }
                                        }
                                    }
                                    $fromTime += 24 * 60 * 60;
                                    $toTime += 24 * 60 * 60;
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    $dayofweek = strftime_dayofweek_compatible($fromTime);
                                    if ($dayofmonth == 01) {
                                        $numberdatecounter = 0;
                                    }
                                }
                            }
                            //Condition 2: End after
                            if ($endtype == 'endafter') {
                                $numberdatecounter = 0;
                                $xmonthscounter = 0;
                                $occurences = 0;
                                $firstmatch = 0;
                                while ($occurences < $endtype_param) {
                                    $dayofweek = strftime_dayofweek_compatible($fromTime);
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    while ($firstmatch == 0) {
                                        if ($dayofweek == $dayofweek_param) {
                                            $numberdatecounter++;
                                            if ($numberdatecounter == $numberdate_param && $xmonthscounter == 0) {
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                                //$xmonthscounter++;
                                                $occurences++;
                                                $firstmatch = 1;
                                            }
                                        }
                                        $fromTime += 24 * 60 * 60;
                                        $toTime += 24 * 60 * 60;
                                        $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                        $dayofweek = strftime_dayofweek_compatible($fromTime);
                                        if ($dayofmonth == 01) {
                                            $numberdatecounter = 0;
                                        }
                                    }
                                    if ($dayofweek == $dayofweek_param) {
                                        $numberdatecounter++;
                                        if ($numberdatecounter == $numberdate_param) {
                                            $xmonthscounter++;
                                            if ($xmonthscounter == $xmonths_param) {
                                                $xmonthscounter = 0;
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                                $occurences++;
                                            }
                                        }
                                    }
                                    $fromTime += 24 * 60 * 60;
                                    $toTime += 24 * 60 * 60;
                                    $dayofmonth = strftime_dayofmonth_compatible($fromTime);
                                    $dayofweek = strftime_dayofweek_compatible($fromTime);
                                    if ($dayofmonth == 01) {
                                        $numberdatecounter = 0;
                                    }
                                }
                            }
                        } else {
                            if ($recurrence_type == 'everyxmonthxdayyear') {
                                $endtype = $params[0];
                                $endtype_param = $params[1];
                                $xmonth_param = $params[2];
                                $xday_param = $params[3];
                                if ($xday_param <= 0 || $xday_param > 31 || $endtype_param < 0) {
                                }
                                //Condition1: End by
                                if ($endtype == 'endby') {
                                    while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                                        $xmonth = strftime('%m', $fromTime);
                                        $xday = strftime_dayofmonth_compatible($fromTime);
                                        if ($xmonth == $xmonth_param && $xday == $xday_param) {
                                            $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                            if ($CHECK_BOOL) {
                                                return $CHECK_BOOL;
                                            }
                                            $fromTime += 150 * 24 * 60 * 60;
                                            $toTime += 150 * 24 * 60 * 60;
                                        } else {
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                        }
                                    }
                                } else {
                                    if ($endtype == 'endafter') {
                                        $occurences = 0;
                                        while ($occurences < $endtype_param) {
                                            $xmonth = strftime('%m', $fromTime);
                                            $xday = strftime_dayofmonth_compatible($fromTime);
                                            if ($xmonth == $xmonth_param && $xday == $xday_param) {
                                                $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                if ($CHECK_BOOL) {
                                                    return $CHECK_BOOL;
                                                }
                                                $occurences++;
                                                $fromTime += 150 * 24 * 60 * 60;
                                                $toTime += 150 * 24 * 60 * 60;
                                            } else {
                                                $fromTime += 24 * 60 * 60;
                                                $toTime += 24 * 60 * 60;
                                            }
                                        }
                                    }
                                }
                            } else {
                                if ($recurrence_type == 'thexyofz') {
                                    $endtype = $params[0];
                                    $endtype_param = $params[1];
                                    $numberdate_param = $params[2];
                                    $dayofweek_param = $params[4];
                                    $xmonth_param = $params[3];
                                    //Condition 1: Endby
                                    if ($endtype == 'endby') {
                                        $numberdatecounter = 0;
                                        while ($fromTime < $endtype_param && $toTime < $endtype_param) {
                                            $dayofweek = strftime_dayofweek_compatible($fromTime);
                                            $xmonth = strftime('%m', $fromTime);
                                            if ($dayofweek == $dayofweek_param) {
                                                $numberdatecounter++;
                                                if ($numberdatecounter == $numberdate_param && $xmonth_param == $xmonth) {
                                                    $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                    if ($CHECK_BOOL) {
                                                        return $CHECK_BOOL;
                                                    }
                                                    $fromTime += 150 * 24 * 60 * 60;
                                                    $toTime += 150 * 24 * 60 * 60;
                                                }
                                            }
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                            $dayofthemonth = strftime_dayofmonth_compatible($fromTime);
                                            if ($dayofthemonth == 1) {
                                                $numberdatecounter = 0;
                                            }
                                        }
                                    }
                                    //Condition 2: End after
                                    if ($endtype == 'endafter') {
                                        $occurences = 0;
                                        $numberdatecounter = 0;
                                        while ($occurences < $endtype_param) {
                                            $dayofweek = strftime_dayofweek_compatible($fromTime);
                                            $xmonth = strftime('%m', $fromTime);
                                            $xmonthday = strftime('%d', $fromTime);
                                            $year = strftime('%Y', $fromTime);
                                            if ($dayofweek == $dayofweek_param) {
                                                $numberdatecounter++;
                                                if ($numberdatecounter == $numberdate_param && $xmonth_param == $xmonth) {
                                                    $CHECK_BOOL = check_availability($room, $fromTime, $toTime);
                                                    if ($CHECK_BOOL) {
                                                        return $CHECK_BOOL;
                                                    }
                                                    $occurences++;
                                                    $fromTime += 150 * 24 * 60 * 60;
                                                    $toTime += 150 * 24 * 60 * 60;
                                                }
                                            }
                                            $fromTime += 24 * 60 * 60;
                                            $toTime += 24 * 60 * 60;
                                            $dayofthemonth = strftime_dayofmonth_compatible($fromTime);
                                            if ($dayofthemonth == 1) {
                                                $numberdatecounter = 0;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}