if ($_GET["status"] === 'insert' && ChurchManager::getSingleChurch('name', $_GET["nameChuch"]) !== NULL) {
    echo "KO";
} else {
    $status = $_GET["status"];
    $church = new Church();
    $church->setId(0);
    $church->setName($_GET["nameChuch"]);
    $church->setType($_GET["typeChurch"]);
    $church->setCode($_GET["codeChurch"]);
    $church->setAddress($_GET["addressChurch"]);
    $church->setColony($_GET["colonyChurch"]);
    $church->setPostalCode($_GET["postalCodeChurch"]);
    $church->setPhoneNumber($_GET["phoneNumberChurch"]);
    $church->setIdVicar(ChurchManager::getSingleVicar('name', $_GET["vicar"])->getId());
    $church->setIdDean(ChurchManager::getSingleDean('name', $_GET["dean"])->getId());
    $church->setIdCity(CityManager::getSingleCity('name', $_GET["city"])->getId());
    $niches = $_GET["niche"];
    if ($niches == 'true') {
        $niche = new Niche();
        $niche->setMaxCol($_GET["maxCol"]);
        $niche->setMaxRow($_GET["maxRow"]);
        $niche->setSize($_GET["size"]);
        $nicheT = ChurchManager::getSingleNiche('maxCol', $niche->getMaxCol(), 'maxRow', $niche->getMaxRow(), 'size', $niche->getSize());
        if ($nicheT === NULL) {
            ChurchManager::addNiche($niche);
            $nicheT = ChurchManager::getSingleNiche('maxCol', $niche->getMaxCol(), 'maxRow', $niche->getMaxRow(), 'size', $niche->getSize());
            $church->setIdNiche($nicheT->getId());
        } else {
            $church->setIdNiche($nicheT->getId());
        }
    } else {
        $kPhonenumber = $_GET["kPhonenumber"];
        $kDean = $_GET["kDean"];
        $kVicar = $_GET["kVicar"];
        $kCity = $_GET["kCity"];
        $church = new Church();
        $church->setId($kid);
        $church->setName($kName);
        $church->setType($kType);
        $church->setCode($kCode);
        $church->setAddress($kAddress);
        $church->setColony($kColony);
        $church->setPostalCode($kPostalCode);
        $church->setPhoneNumber($kPhonenumber);
        $church->setIdDean($kDean);
        $church->setIdVicar($kVicar);
        $church->setIdCity($kCity);
        $churchRegistries = ChurchManager::advancedSearchChurch($church, $sortType, $numberPage, 'AND');
    } else {
        $churchRegistries = ChurchManager::getAllChurchs($sortType, $numberPage);
    }
}
//Get the total of registries
$totalRegistries = DatabaseManager::getAffectedRows();
$affectedRegistries = DatabaseManager::registriesAffectedLastQuery();
$lastPage = floor($affectedRegistries / 10);
if ($affectedRegistries % 10 === 0) {
    $lastPage = floor($affectedRegistries / 10) - 1;
}
if ($totalRegistries === 0 && $numberPage !== 0) {
    echo "<script src='../JS/functions.js'></script><script>nextPage('set', '0')</script>";
}