Exemplo n.º 1
0
 /**
  * Render the Pet page
  */
 public function renderPet()
 {
     $view_data['page_title'] = $this->pet->getName();
     $view_data['pet'] = $this->pet;
     // Check if pet can be edited
     if (isset($this->logged_in_user) && PetUtils::userCanEditPet($this->logged_in_user, $this->pet)) {
         $view_data['edit_mode'] = true;
     }
     $this->renderTemplate('templates/header.php', $view_data);
     $this->renderTemplate('templates/pet_viewer_view.php', $view_data);
     $this->renderTemplate('templates/footer.php', $view_data);
 }
Exemplo n.º 2
0
    HTTPUtils::my_http_redirect('index.php');
}
// POST keys
$pet_id_key = 'pet_id';
// Form inputs
$form_pet_id = empty($_POST[$pet_id_key]) ? null : intval(StringUtils::sanitize($_POST[$pet_id_key]));
$data = MorpheusPetsData::getInstance();
// Get logged in user
$logged_in_user = $session->getLoggedInUser();
// Get pet to edit
$pet_to_edit = $form_pet_id === null ? null : $data->getPet($form_pet_id);
// Check if pet was found
if ($pet_to_edit === null) {
    // Pet does not exist
    $view_model = new Error_ViewModel();
    $view_model->renderPetNotExist($form_pet_id);
} elseif (!PetUtils::userCanEditPet($logged_in_user, $pet_to_edit)) {
    // Pet does not belong to logged in user
    $view_model = new Error_ViewModel();
    $view_model->renderEditPetNotAllowed($pet_to_edit);
} else {
    // Delete pet
    if ($data->deletePet($pet_to_edit->getId())) {
        // Redirect to profile page
        HTTPUtils::my_http_redirect("my_profile.php?profileId=" . $logged_in_user->getId());
    } else {
        // Pet could not be deleted
        $view_model = new Error_ViewModel();
        $view_model->renderDeletePetFailed($pet_to_edit);
    }
}