require_once __DIR__ . "/../../../Backend/RectorManager.php";
if (!isset($_POST) || $_POST["idChild"] === NULL) {
    echo "KO";
    die;
}
$church = ChurchManager::getSingleChurch('name', $_POST["celebrationChurch"]);
$child = new Person();
if ($_POST["idChild"] !== '0' && $_POST["idChild"] !== '') {
    $child = PersonManager::getSinglePerson('id', $_POST["idChild"]);
}
$child->setId($_POST["idChild"]);
$child->setNames($_POST["nameChild"]);
$child->setLastname1($_POST["lastname1Child"]);
$child->setLastname2($_POST["lastname2Child"]);
$confirmation = new Confirmation();
$confirmation->setId($_POST["idConfirmation"]);
$celb = DatabaseManager::singleDateToDatabaseDate($_POST["celebrationDate"]);
$confirmation->setCelebrationDate($celb);
$confirmation->setIdChurch($church->getId());
$confirmation->setIdRector($_POST["rectorId"]);
//Data Process for the Father
$father = new Person();
if ($_POST["idFather"] !== '0' && $_POST["idFather"] !== '') {
    $father = PersonManager::getSinglePerson('id', $_POST["idFather"]);
    $father->setId($_POST["idFather"]);
    $father->setNames($_POST["nameFather"]);
    $father->setLastname1($_POST["lastname1Father"]);
    $father->setLastname2($_POST["lastname2Father"]);
    $father->setGender('M');
    PersonManager::updatePerson($father);
} else {
        $kbornp = $_GET["kbornp"];
        $kbornd = DatabaseManager::singleDateToDatabaseDate($_GET["kbornd"]);
        $knamec = $_GET["knamec"];
        $klastname1c = $_GET["klastname1c"];
        $klastname2c = $_GET["klastname2c"];
        $knamef = $_GET["knamef"];
        $klastname1f = $_GET["klastname1f"];
        $klastname2f = $_GET["klastname2f"];
        $knamem = $_GET["knamem"];
        $klastname1m = $_GET["klastname1m"];
        $klastname2m = $_GET["klastname2m"];
        $kchurch = $_GET["kchurch"];
        $kbook = $_GET["kbook"];
        $knumber = $_GET["knumber"];
        $kpape = $_GET["kpape"];
        $confirmationSearch->setId($kid);
        $confirmationSearch->setCelebrationDate($kcelebration);
        $posibleNames[0] = PersonManager::searchPersonsByNames($knamec, $klastname1c, $klastname2c, false);
        $posibleNames[1] = PersonManager::searchPersonsByNames($knamef, $klastname1f, $klastname2f, false);
        $posibleNames[2] = PersonManager::searchPersonsByNames($knamem, $klastname1m, $klastname2m, false);
        $confirmationSearch->setIdOwner($posibleNames);
        $posibleChurch = ChurchManager::simpleSearchChurch($kchurch, 'id', -1);
        $confirmationSearch->setIdChurch($posibleChurch);
        $confirmationRegistry = ConfirmationManager::getSingleConfirmationRegistry('book', $kbook, 'page', $kpape, 'number', $knumber);
        $confirmationSearch->setIdBookRegistry($confirmationRegistry);
        $confirmationRegistries = ConfirmationManager::advancedSearchConfirmation($confirmationSearch, 'AND', $sortType, $numberPage);
    } else {
        $confirmationRegistries = ConfirmationManager::getAllConfirmations($sortType, $numberPage);
    }
}
//Get the total of registries