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 tourImages() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } $data = array(); if (!isset($_GET['id'])) { header('Location: index.php?c=tour&m=index'); } $tourCollection = new ToursCollection(); $tour = $tourCollection->getOne($_GET['id']); if (is_null($tour)) { header('Location: index.php?c=tour&m=index'); } $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: index.php?c=tour&m=tourImages&id=" . $_GET['id']); } } else { } $data['imageErrors'] = $imageErrors; $data['images'] = $images; $data['tourId'] = $_GET['id']; $this->loadView('tours/tourImages', $data); }