if ($typeBien == "maison") {
                    $maisonManager = new MaisonManager($pdo);
                    $maisonManager->updateStatus("Vendu", $idBien);
                    $maisonManager->updateStatus("Disponible", $contrat->idBien());
                } else {
                    if ($typeBien == "terrain") {
                        $terrainManager = new TerrainManager($pdo);
                        $terrainManager->updateStatus("Vendu", $idBien);
                        $terrainManager->updateStatus("Disponible", $contrat->idBien());
                    }
                }
            }
        }
    }
    $newContrat = new Contrat(array('nomClient' => $nomClient, 'cin' => $cin, 'adresse' => $adresse, 'telephone' => $telephone, 'dateCreation' => $dateCreation, 'dateRetour' => $dateRetour, 'prixVente' => $prixNegocie, 'avance' => $avance, 'note' => $note, 'taille' => $taille, 'modePaiement' => $modePaiement, 'id' => $idContrat, 'idBien' => $idBien, 'typeBien' => $typeBien, 'numeroCheque' => $numeroCheque));
    $contratManager->update($newContrat);
    //add history data to db
    $projetManager = new ProjetManager($pdo);
    $historyManager = new HistoryManager($pdo);
    $projet = $projetManager->getProjetById($idProjet);
    $createdBy = $_SESSION['userMerlaTrav']->login();
    $created = date('Y-m-d h:i:s');
    $history = new History(array('action' => "Modification", 'target' => "Table des contrats clients", 'description' => "Modification contrat - Client :  " . $nomClient . " - CIN : " . $cin . " - ID Contrat : " . $idContrat . " - Type bien : " . $typeBien . " - ID Bien : " . $idBien . " - Projet : " . $projet->nom(), 'created' => $created, 'createdBy' => $createdBy));
    //add it to db
    $historyManager->add($history);
    $_SESSION['contrat-update-success'] = "<strong>Opération Valide : </strong>Contrat Modifié avec succès.";
    //print_r($newContrat);
    header('Location:../contrats-list.php?idProjet=' . $idProjet . '&idSociete=' . $idSociete);
} else {
    $_SESSION['contrat-update-error'] = "<strong>Erreur Modification Contrat : </strong>Vous devez remplir au moins les champs 'Nom Client' et 'Prix Négocié'.";
    header('Location:../contrats-update.php?idContrat=' . $idContrat . '&idProjet=' . $idProjet . '&idSociete=' . $idSociete);
function classLoad($myClass)
{
    if (file_exists('../model/' . $myClass . '.php')) {
        include '../model/' . $myClass . '.php';
    } elseif (file_exists('../controller/' . $myClass . '.php')) {
        include '../controller/' . $myClass . '.php';
    }
}
spl_autoload_register("classLoad");
include '../config.php';
//classes loading end
session_start();
//post input processing
$idContrat = $_POST['id_contrat'];
if (!empty($_POST['dateCreation']) && !empty($_POST['prixVente']) && !empty($_POST['avance'])) {
    $dateCreation = htmlentities($_POST['dateCreation']);
    $prixVente = htmlentities($_POST['prixVente']);
    $avance = htmlentities($_POST['avance']);
    $dateEcheance = htmlentities($_POST['dateEcheance']);
    $nb = htmlentities($_POST['nb']);
    //update a Contract object
    $contract = new Contrat(array('id' => $idContrat, 'dateCreation' => $dateCreation, 'prixVente' => $prixVente, 'avance' => $avance, 'dateEcheanceMois' => $dateEcheance, 'nb' => $nb));
    $contratsManager = new ContratManager($pdo);
    $contratsManager->update($contract);
    $_SESSION['success']['contract-update'] = 'Les données du contrat sont modifié avec succès !';
    $contrat = $contratsManager->getContratById($idContrat);
    header('Location:../contract-list.php?id=' . $contrat->idClient());
} else {
    $_SESSION['error']['contract-update'] = "Vous devez remplir au moins les champs 'Date du contrat', 'Avance' et 'Prix de vente' !";
    header('Location:../update-contract.php?id=' . $idContrat);
}