$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']);
    }
} else {
}
?>
    <link id="bootstrap-style" href="css/images.css" rel="stylesheet">
<?php 
require_once 'common/sidebar.php';
?>
    <!-- start: Content -->
    <div id="content" class="span10" xmlns="http://www.w3.org/1999/html">
 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);
 }