CCanDo::checkEdit();
$date = CValue::getOrSession("date", CMbDT::date());
$typerepas_id = CValue::getOrSession("typerepas_id", null);
$affectation_id = CValue::getOrSession("affectation_id", null);
$affectation = new CAffectation();
$listRepas = new CMenu();
$typeRepas = new CTypeRepas();
$repas = new CRepas();
if (!$affectation->load($affectation_id) || !$typeRepas->load($typerepas_id)) {
    // Pas d'affectation
    CValue::setSession("affectation_id", null);
    CAppUI::setMsg("Veuillez sélectionner une affectation", UI_MSG_ALERT);
    CAppUI::redirect("m=dPrepas&tab=vw_planning_repas");
} else {
    $affectation->loadRefSejour();
    $affectation->loadRefLit();
    $affectation->_ref_lit->loadCompleteView();
    $canAffectation = $affectation->canDo();
    if (!$canAffectation->read || !$affectation->_ref_sejour->sejour_id || $affectation->_ref_sejour->type == "ambu") {
        // Droit Interdit ou Ambulatoire
        CValue::setSession("affectation_id", null);
        $affectation_id = null;
        if (!$affectation->_canRead) {
            $msg = "Vous n'avez pas les droit suffisant pour cette affectation";
        } else {
            $msg = "Vous ne pouvez pas plannifier de repas pour cette affectation";
        }
        CAppUI::setMsg($msg, UI_MSG_ALERT);
        CAppUI::redirect("m=dPrepas&tab=vw_planning_repas");
    }
    // Chargement des Repas
 /**
  * Ajout de l'emplacement du mouvement
  *
  * @param DOMNode      $elParent    Node
  * @param CAffectation $affectation Affectation
  *
  * @return void
  */
 function addEmplacement(DOMNode $elParent, CAffectation $affectation)
 {
     $receiver = $this->_ref_receiver;
     if (!$receiver->_configs["send_movement_location"]) {
         return;
     }
     $emplacement = $this->addElement($elParent, "emplacement");
     $affectation->loadRefLit()->loadRefChambre()->loadRefService();
     // Chambre
     $lit = $affectation->_ref_lit;
     $chambre = $lit->_ref_chambre;
     $idex = CIdSante400::getMatchFor($chambre, $receiver->_tag_chambre);
     $code = $idex->_id ? $idex->id400 : $chambre->_id;
     $this->addCodeLibelleCommentaire($emplacement, "chambre", $code, $chambre->nom, null, $chambre->caracteristiques);
     // Lit
     $idex = CIdSante400::getMatchFor($lit, $receiver->_tag_lit);
     $code = $idex->_id ? $idex->id400 : $lit->_id;
     $this->addCodeLibelleCommentaire($emplacement, "lit", $code, $lit->nom, null, $lit->nom_complet);
     // Chambre seul
     $this->addAttribute($emplacement, "chambreSeul", $chambre->_chambre_seule ? "oui" : "non");
 }