public function show() { $data = array(); $tourId = isset($_GET['id']) ? (int) $_GET['id'] : 0; if ($tourId == 0) { header("Location: index.php?c=tours"); } $toursCollection = new ToursCollection(); $tour = $toursCollection->getOne($tourId); if ($tour === null) { header("Location: index.php?c=tours"); } $tourImagesCollection = new ToursImagesCollection(); $tourImages = $tourImagesCollection->getAll(array('tours_id' => $tour->getId())); $data['tour'] = $tour; $data['tourImages'] = $tourImages; $this->loadFrontView('tours/show', $data); }
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: tours.php'); } $tourCollection = new ToursCollection(); $tour = $tourCollection->getOne($_GET['id']); if (is_null($tour)) { header('Location: tours.php'); } $tourImagesCollection = new ToursImagesCollection(); $images = $tourImagesCollection->getAll(array('tours_id' => $_GET['id'])); $fileUpload = new fileUpload('image'); $file = $fileUpload->getFilename(); $fileExtention = $fileUpload->getFileExtention(); $imageErrors = array(); if ($file != '') { $imageErrors = $fileUpload->validate(); $newName = sha1(time()) . '.' . $fileExtention; $insertInfo = array('tours_id' => $_GET['id'], 'image' => $newName); if (empty($imageErrors)) { $imageEntity = new ToursImagesEntity(); $obj = $imageEntity->init($insertInfo); $tourImagesCollection->save($obj); $fileUpload->upload('uploads/tours/' . $newName); header("Location: tourImages.php?id=" . $_GET['id']); }
public function deleteTourImage() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } if (!isset($_GET['id'])) { header('Location: index.php?c=tour&m=index'); } $imageCollection = new ToursImagesCollection(); $image = $imageCollection->getOne($_GET['id']); if (is_null($image)) { header('Location: index.php?c=tour&m=index'); } $tourId = $image->getToursId(); unlink('uploads/tours/' . $image->getImage()); $imageCollection->delete($_GET['id']); header("Location: index.php?c=tour&m=tourImages&id=" . $tourId); }
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: users.php'); } $imageCollection = new ToursImagesCollection(); $image = $imageCollection->getOne($_GET['id']); if (is_null($image)) { header('Location: tours.php'); } $tourId = $image->getToursId(); unlink('uploads/tours/' . $image->getImage()); $imageCollection->delete($_GET['id']); header("Location: tourImages.php?id=" . $tourId);