$lit->load($affectation->lit_id);
if ($urgence) {
    $service_urgence = CGroups::loadCurrent()->service_urgences_id;
    $affectation->function_id = $service_urgence;
}
$sejour_maman = null;
if (CModule::getActive("maternite") && $affectation->sejour_id) {
    $naissance = new CNaissance();
    $naissance->sejour_enfant_id = $affectation->sejour_id;
    $naissance->loadMatchingObject();
    if ($naissance->_id) {
        $sejour_maman = $naissance->loadRefSejourMaman();
        $sejour_maman->loadRefPatient();
    }
}
if ($affectation->_id) {
    $affectation->loadRefSejour()->loadRefPatient();
} else {
    $affectation->lit_id = $lit_id;
    $lit->load($lit_id);
    $lit->loadRefChambre()->loadRefService();
    $affectation->entree = CMbDT::dateTime();
}
$smarty = new CSmartyDP();
$smarty->assign("affectation", $affectation);
$smarty->assign("lit", $lit);
$smarty->assign("lit_id", $lit_id);
$smarty->assign("sejour_maman", $sejour_maman);
$smarty->assign("urgence", $urgence);
$smarty->assign("from_tempo", $from_tempo);
$smarty->display("inc_edit_affectation.tpl");
        $date_before = CMbDT::date("-4 week", $date);
        $date_after = CMbDT::date("+4 week", $date);
}
$current = CMbDate::dirac("hour", CMbDT::dateTime());
$offset = $nb_ticks * $nb_unite;
$date_max = CMbDT::dateTime("+ {$offset} {$unite}", $date_min);
$temp_datetime = CMbDT::dateTime(null, $date_min);
for ($i = 0; $i < $nb_ticks; $i++) {
    $offset = $i * $nb_unite;
    $datetime = CMbDT::dateTime("+ {$offset} {$unite}", $date_min);
    $datetimes[] = $datetime;
}
$lit = new C**t();
$lit->load($lit_id);
$lit->_ref_affectations = array();
$chambre = $lit->loadRefChambre();
$chambre->_ref_lits[$lit->_id] = $lit;
$lits = array($lit_id => $lit);
$liaisons_items = $lit->loadBackRefs("liaisons_items");
$items_prestations = CStoredObject::massLoadFwdRef($liaisons_items, "item_prestation_id");
$prestations_ids = CMbArray::pluck($items_prestations, "object_id");
if (in_array($prestation_id, $prestations_ids)) {
    $inverse = array_flip($prestations_ids);
    $item_prestation = $items_prestations[$inverse[$prestation_id]];
    if ($item_prestation->_id) {
        $lit->_selected_item = $item_prestation;
    } else {
        $lit->_selected_item = new CItemPrestation();
    }
} else {
    $lit->_selected_item = new CItemPrestation();