/**
  * Run method with main page logic
  * 
  * Read in list of albums and the latest photos for each album. Pagination enabled.
  * Populate template with data and display results in the page.
  * @access public
  */
 public function run()
 {
     $PAGINATION_LIMIT = 10;
     $session = Session::getInstance();
     $user = $session->getUser();
     $albumDAO = AlbumDAO::getInstance();
     $photoDAO = PhotoDAO::getInstance();
     $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $count = $paginator = $paginator_page = null;
     $album = $photo_info_array = null;
     $title = "";
     $count = $albumDAO->count();
     $paginator = new Paginator($count, $PAGINATION_LIMIT);
     $paginator_page = $paginator->getPage($page);
     $album_array = $albumDAO->all(array("limit" => $paginator_page));
     $photo_info_array = array();
     foreach ($album_array as $album) {
         $count = $photoDAO->countByAlbum($album);
         if ($count > 0) {
             $tmp_paginator = new Paginator($count, 1);
             $tmp_paginator_page = $paginator->getPage($page);
             // Only get latest item
             list($latest_photo) = $photoDAO->allByAlbum($album, array("order" => "id DESC", "limit" => $tmp_paginator_page));
             $photo_info_array[] = array($count, $latest_photo);
         }
     }
     $this->template->render(array("title" => "Album List", "main_page" => "album_list_tpl.php", "session" => $session, "album_array" => $album_array, "photo_info_array" => $photo_info_array, "paginator_page" => $paginator_page));
 }
 /**
  * Run method with main page logic
  * 
  * Read in album information and photos associated with an album from the database.
  * Populate template and display results in the page. Pagination possible
  * @access public
  */
 public function run()
 {
     $PAGINATION_LIMIT = 10;
     $session = Session::getInstance();
     $user = $session->getUser();
     $albumDAO = AlbumDAO::getInstance();
     $photoDAO = PhotoDAO::getInstance();
     $album = $photo_array = $photo_count = $paginator_page = $queryVars = null;
     $title = "";
     $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $id = isset($_GET["id"]) && is_numeric($_GET["id"]) ? intval($_GET["id"]) : 0;
     if ($id <= 0) {
         header("Location: " . BASE_URL);
         return;
     }
     $album = $albumDAO->load($id, array("joins" => true));
     if ($album) {
         $title = $album->getTitle();
         $count = $photoDAO->countByAlbum($album);
         $paginator = new Paginator($count, $PAGINATION_LIMIT);
         $paginator_page = $paginator->getPage($page);
         $photo_array = $photoDAO->allByAlbum($album, array("limit" => $paginator_page));
         $queryVars = array("id" => $id);
     }
     $this->template->render(array("title" => "View Album - {$title}", "session" => $session, "album" => $album, "photo_array" => $photo_array, "paginator_page" => $paginator_page, "queryVars" => $queryVars, "main_page" => "view_album_tpl.php"));
 }
 /**
  * Run method with main page logic
  * 
  * Populate template and display confirmation for photo deletion. For POST requests,
  * check user credentials, check if photo exists and then delete entry from database.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if ($user == null || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $photoDAO = PhotoDAO::getInstance();
     $delete_photo = null;
     $form_errors = array();
     $form_values = array("id" => "");
     if (!empty($_POST)) {
         $id = isset($_POST["id"]) ? trim($_POST["id"]) : "";
         if (empty($id)) {
             header("Location: " . BASE_URL);
             return;
         } else {
             if (is_numeric($id)) {
                 $delete_photo = $photoDAO->load($id);
                 if ($delete_photo) {
                     if ($photoDAO->delete($delete_photo)) {
                         unlink($delete_photo->getFileLoc());
                         if ($delete_photo->getThumbLoc()) {
                             unlink($delete_photo->getThumbLoc());
                         }
                         $session->setMessage("Photo deleted");
                         header("Location: " . BASE_URL);
                         return;
                     } else {
                         $session->setMessage("Could not delete photo", Session::MESSAGE_ERROR);
                     }
                 }
             }
         }
     } else {
         if (!empty($_GET)) {
             $id = isset($_GET["id"]) ? trim($_GET["id"]) : "";
             if (empty($id)) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 if (is_numeric($id)) {
                     $delete_photo = $photoDAO->load($id);
                     if ($delete_photo) {
                         $form_values["id"] = $delete_photo->getId();
                     }
                 }
             }
         } else {
             header("Location: " . BASE_URL);
             return;
         }
     }
     $this->template->render(array("title" => "Delete Profile", "main_page" => "delete_photo_tpl.php", "session" => $session, "delete_photo" => $delete_photo, "form_errors" => $form_errors, "form_values" => $form_values));
 }
Example #4
0
 public static function uploadPhotoModel($uploadedPhoto, $albumId, $formType, $latitude = NULL, $longitude = NULL)
 {
     $responseDTO = new ResponseDTO($formType);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $fileName = $uploadedPhoto["name"];
         $fileType = $uploadedPhoto["type"];
         $tmpFileName = $uploadedPhoto["tmp_name"];
         $rawImage = FileUtils::getRawImage($fileType, $tmpFileName);
         $fileName = FileUtils::getFileName($fileName, $userLogged->getUserId(), $albumId);
         $redimImage = FileUtils::getRedimensionedImage($tmpFileName, $rawImage);
         if (imagejpeg($redimImage, $fileName, 100)) {
             $photoDAO = new PhotoDAO();
             $newPhotoDTO = new PhotoDTO(NULL, $fileName, $latitude, $longitude);
             $newPhotoDTO = $photoDAO->insertNewPhoto($newPhotoDTO);
             if ($newPhotoDTO->getPhotoId() == 0) {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto [" . $newPhotoDTO->getPhotoUrl() . "]");
             } else {
                 $albumDAO = new AlbumDAO();
                 if (is_null($albumId)) {
                     $albumId = $albumDAO->getDefaultAlbumId($userLogged->getUserId());
                 }
                 if ($formType !== ADD_ALBUM_FORM) {
                     $photoInAlbumId = $albumDAO->insertNewUserPhotoAlbum($userLogged->getUserId(), $albumId, $newPhotoDTO->getPhotoId());
                 }
                 if (!is_null($latitude) && !is_null($longitude)) {
                     $uploadedAddress = FileUtils::saveAddressModel($latitude, $longitude, $formType);
                 }
                 return $newPhotoDTO;
             }
         } else {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante la copia del file sul server PHP");
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $userAuth) {
         throw $userAuth;
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * Run method with main page logic
  * 
  * Read in the specified photo from the database. Read in album data as well.
  * Populate template and display photo in the page.
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     $photoDAO = PhotoDAO::getInstance();
     $photo = $next_photo = $prev_photo = $photo_index = $photo_count = null;
     $title = "";
     if (!empty($_GET["id"]) && is_numeric($_GET["id"])) {
         $photo_id = intval($_GET["id"]);
         $photo = $photoDAO->load($photo_id, array("joins" => true));
         if ($photo) {
             $title .= " - {$photo->getTitle()}";
             // Load next and previous photos as well as position of current photo in album
             $next_photo = $photoDAO->loadNext($photo);
             $prev_photo = $photoDAO->loadPrevious($photo);
             $photo_index = $photoDAO->countPosition($photo, $photo->getAlbum());
             $photo_count = $photoDAO->countByAlbum($photo->getAlbum());
         }
     }
     $this->template->render(array("title" => "View Photo" . $title, "main_page" => "view_photo_tpl.php", "session" => $session, "photo" => $photo, "next_photo" => $next_photo, "prev_photo" => $prev_photo, "photo_index" => $photo_index, "photo_count" => $photo_count));
 }
Example #6
0
<?php

include "header.php";
include "connection/DbConnection.php";
include "class/PhotoDAO.php";
include "class/Photo.php";
$photoDao = new PhotoDAO();
$showPhotos = $photoDao->showPhotos();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $photoObj = new Photo();
    if (isset($_POST['is_item'])) {
        $is_item = '1';
    } else {
        $is_item = '0';
    }
    if (isset($_POST['is_photo'])) {
        $is_photo = '1';
    } else {
        $is_photo = '0';
    }
    $photoObj->setID($_POST['id']);
    $photoObj->setDescription($_POST['description']);
    $photoObj->setIsItem($is_item);
    $photoObj->setIsPhoto($is_photo);
    $rowphoto = $photoDao->editOne($photoObj->getId(), $photoObj->getDescription(), $photoObj->getIsItem(), $photoObj->getIsPhoto());
}
?>

<div class="main container-fluid">
    <!--div class="section"-->
        <?php 
Example #7
0
 /**
  * Retrieve instance of an PhotoDAO or create one if it does
  * not exist.
  *
  * @access public
  * @static
  * @return PhotoDAO
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
<?php

include "header.php";
include "connection/DbConnection.php";
include "class/PhotoDAO.php";
include "class/Photo.php";
$photoDao = new PhotoDAO();
$showPhotos = $photoDao->showPhotoUsers();
?>

<div class="main container-fluid">
    <!--div class="section"-->
        <?php 
while ($row = $showPhotos->fetch_assoc()) {
    ?>
            <div class="secolPhoto">
                <table class="table datagrid" style="width: 25%">
                    <tr style="background-color: chocolate">
                        <th style="width: 25%"><?php 
    echo "<a style='color:darkred' href='showPhoto.php?photoid={$row['id']}'> " . $row['id'] . "</a>";
    ?>
</th>
                        <th style="width: 75%"><?php 
    echo $row['title'];
    ?>
</th>
                        <th></th>
                    </tr>
                     <tr>
                         <td style="width: 50%"><?php 
    echo $row['description'];
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for editing an photo entry. For POST requests,
  * check user credentials, check if photo exists and then update entry in database.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $photoDAO = PhotoDAO::getInstance();
     $albumDAO = AlbumDAO::getInstance();
     $photo = null;
     $form_errors = array();
     $form_values = array("id" => "", "albumid" => "", "title" => "", "description" => "");
     if (!empty($_POST)) {
         $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
         $form_values["albumid"] = isset($_POST["albumid"]) && is_numeric($_POST["albumid"]) ? intval($_POST["albumid"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : "";
         if (empty($form_values["id"])) {
             $form_errors["id"] = "No id specified";
         }
         $photo = $photoDAO->load($form_values["id"]);
         if (!$photo) {
             $form_errors["id"] = "Photo does not exist";
         }
         if (empty($form_values["albumid"])) {
             $form_errors["albumid"] = "No albumid specified";
         } else {
             if (!$albumDAO->load($form_values["albumid"])) {
                 $form_errors["albumid"] = "Album does not exist";
             }
         }
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["description"])) {
             $form_errors["description"] = "No description specified";
         }
         // Check if image will be changed
         $upload_path = "";
         if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
             if ($_FILES["imagefile"]["error"] != UPLOAD_ERR_OK) {
                 $form_errors["imagefile"] = "File upload failed";
             } else {
                 $info = getimagesize($_FILES["imagefile"]["tmp_name"]);
                 $path = pathinfo($_FILES["imagefile"]["name"]);
                 $upload_path = joinPath(Photo::UPLOAD_DIR, strftime("%Y_%m"), basename($_FILES['imagefile']['name']));
                 $thumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb.jpg");
                 $smallThumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb_small.jpg");
                 if (!$info || !(strtolower($path["extension"]) != ".png" && strtolower($path["extension"]) != ".jpg" && strtolower($path["extension"]) != ".jpeg")) {
                     $form_errors["imagefile"] = "An invalid file was uploaded";
                 } else {
                     if (file_exists($upload_path)) {
                         unlink($upload_path);
                         if (file_exists($thumbLoc)) {
                             unlink($thumbLoc);
                         }
                         if (file_exists($smallThumbLoc)) {
                             unlink($smallThumbLoc);
                         }
                         //$form_errors["imagefile"] = "Filename already exists.  Please choose different name or delete file first";
                     }
                 }
             }
         }
         if (empty($form_errors)) {
             $photo->setAlbumId($form_values["albumid"]);
             $photo->setTitle($form_values["title"]);
             $photo->setDescription($form_values["description"]);
             // New image has been uploaded
             if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
                 if (!file_exists(dirname($upload_path))) {
                     mkdir(dirname($upload_path));
                 }
                 if (move_uploaded_file($_FILES["imagefile"]["tmp_name"], $upload_path)) {
                     $photo->setFileLoc($upload_path);
                     // Reset thumbnail location in case new image does not need a thumbnail
                     $photo->setThumbLoc("");
                     // Create thumbnail
                     if ($info[0] > Photo::MAX_WIDTH) {
                         $phpThumb = new phpThumb();
                         $phpThumb->setSourceFilename($photo->getFileLoc());
                         $phpThumb->setParameter('w', Photo::MAX_WIDTH);
                         $phpThumb->setParameter('config_output_format', 'jpeg');
                         if (!file_exists(dirname($thumbLoc))) {
                             mkdir(dirname($thumbLoc));
                         }
                         if ($phpThumb->GenerateThumbnail() && $phpThumb->RenderToFile($thumbLoc)) {
                             $photo->setThumbLoc($thumbLoc);
                             $phpThumb = new phpThumb();
                             $phpThumb->setSourceFilename($photo->getFileLoc());
                             $phpThumb->setParameter('h', Photo::SMALL_THUMB_HEIGHT);
                             $phpThumb->setParameter('config_output_format', 'jpeg');
                             $phpThumb->GenerateThumbnail();
                         } else {
                             if (file_exists($photo->getFileLoc())) {
                                 unlink($photo->getFileLoc());
                             }
                             $form_errors["imagefile"] = "Image larger than " . Photo::MAX_WIDTH . "x" . Photo::MAX_HEIGHT . " and thumbnail generation failed";
                         }
                     }
                 } else {
                     $form_errors["imagefile"] = "File could not be moved";
                 }
             }
             if (empty($form_errors["imagefile"])) {
                 if ($photoDAO->save($photo)) {
                     $session->setMessage("Photo saved");
                     header("Location: edit_photo.php?id={$photo->getId()}");
                     return;
                 } else {
                     $session->setMessage("Photo not saved");
                 }
             }
         } else {
             if (empty($form_errors["id"])) {
                 $photo = $photoDAO->load($form_values["id"]);
             }
         }
     } else {
         if (!empty($_GET)) {
             $form_values["id"] = isset($_GET["id"]) ? $_GET["id"] : "";
             if (empty($form_values["id"])) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 $photo = $photoDAO->load($form_values["id"]);
                 if ($photo) {
                     $form_values["id"] = $photo->getId();
                     $form_values["albumid"] = $photo->getAlbumId();
                     $form_values["title"] = $photo->getTitle();
                     $form_values["description"] = $photo->getDescription();
                 }
             }
         }
     }
     $album_array = $albumDAO->all();
     $this->template->render(array("title" => "Edit Photo", "session" => $session, "main_page" => "edit_photo_tpl.php", "photo" => $photo, "form_values" => $form_values, "form_errors" => $form_errors, "album_array" => $album_array));
 }
Example #10
0
 public function saveNewPost(PhotoDTO $photoDTO, $otherData)
 {
     $responseDTO = new ResponseDTO(WRITE_POST_FORM);
     $text = $otherData[WRITE_POST_FORM . TEXT];
     $dashboardid = $otherData[WRITE_POST_FORM . DASHBOARDID];
     $timestamp = date(DATE_FORMAT);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $photoDAO = new PhotoDAO();
         $authorProfilePhoto = $photoDAO->getUserProfilePhoto($userLogged->getUserId());
         $dashboardProfilePhoto = $photoDAO->getUserProfilePhoto($dashboardid);
         $userDAO = new UserDAO();
         $authorUser = $userDAO->getUserByUserId($userLogged->getUserId());
         $dashboardUser = $userDAO->getUserByUserId($dashboardid);
         $postDTO = new PostDTO(NULL, $dashboardUser, $authorUser, $text, $timestamp, $photoDTO);
         $postDAO = new PostDAO();
         $newPostDTO = $postDAO->insertNewPost($postDTO);
         if ($newPostDTO->getPostId() != 0) {
             DataModelUtils::notifyAction($newPostDTO->getPostId() . SEPARATOR . $authorUser->getUserId() . SEPARATOR . $dashboardUser->getUserId() . SEPARATOR . $dashboardUser->getUserName(), WRITE_POST_FORM);
             return $newPostDTO;
         } else {
             $responseDTO->setErrField(POST, "Non รจ stato possibile inserire il post");
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #11
0
<?php

include "header2.php";
include_once "connection/DbConnection.php";
include "class/Photo.php";
include "class/PhotoDAO.php";
$photoDao = new PhotoDAO();
if (isset($_GET['photoid'])) {
    $photoid = $_GET['photoid'];
    $rowphoto = $photoDao->showPhoto($photoid);
}
?>

<br />

<?php 
if ($is_admin == 1) {
    // prikazuje formu ako je ulogovan admin korisnik
    ?>

<form method="post" action="showPhotos.php">
    <input type="hidden" name="id" value="<?php 
    if (isset($photoid)) {
        echo $photoid;
    }
    ?>
">
    <h3>Title: <!--input type="text" name="title" value="<!--?php echo $rowphoto['title']; ?>"-->
    <?php 
    echo $rowphoto['title'];
    ?>
Example #12
0
 function updateProfilePhotoModel($photoId, $filename)
 {
     $responseDTO = new ResponseDTO(UPDATE_PROFILE_PHOTO_FORM);
     try {
         $photoDAO = new PhotoDAO();
         $photoDTO = new PhotoDTO($photoId, $filename);
         $updateProfilePhoto = $photoDAO->updateProfilePhoto($photoDTO);
         $userLogged = SessionUtils::getUserLogged();
         $userLogged->setProfilePhoto($photoDTO);
         SessionUtils::setUserLogged($userLogged);
         $responseDTO->setResponseSucc("Foto profilo aggiornata con successo!");
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
<?php

include "header.php";
include "connection/DbConnection.php";
include "class/PhotoDAO.php";
include "class/Photo.php";
$photoDao = new PhotoDAO();
$showPhotos = $photoDao->showPhotoItems();
?>

<div class="main container-fluid">
    <!--div class="section"-->
        <?php 
while ($row = $showPhotos->fetch_assoc()) {
    ?>
            <div class="secolPhoto">
                <table class="table datagrid" style="width: 25%">
                    <tr style="background-color: chocolate">
                        <th style="width: 25%"><?php 
    echo "<a style='color:darkred' href='showPhoto.php?photoid={$row['id']}'> " . $row['id'] . "</a>";
    ?>
</th>
                        <th style="width: 75%"><?php 
    echo $row['title'];
    ?>
</th>
                        <th></th>
                    </tr>
                     <tr>
                         <td style="width: 50%"><?php 
    echo $row['description'];
Example #14
-1
 function changeUserProfilePhoto($photoForm)
 {
     $formObjRaw = new FormDTO(PROFILE_SETTINGS_PHOTO_FORM, $photoForm);
     $responseDTO = new ResponseDTO(PROFILE_SETTINGS_PHOTO_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(PROFILE_SETTINGS_PHOTO_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[PROFILE_SETTINGS_PHOTO_FORM . PHOTO], $userLogged->getDefaultAlbumId(), PROFILE_SETTINGS_PHOTO_FORM);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 $photoDAO = new PhotoDAO();
                 $updateProfilePhoto = $photoDAO->updateProfilePhoto($uploadedPhoto);
                 $userLogged = SessionUtils::getUserLogged();
                 $userLogged->setProfilePhoto($uploadedPhoto);
                 SessionUtils::setUserLogged($userLogged);
                 return $uploadedPhoto;
             } else {
                 $responseDTO->setResponseSucc("Errore durante l'inserimento della foto profilo");
             }
         } else {
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(PHOTO, $validationError[PHOTO]);
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }