$link1->add_attribute(new html_library\HTMLAttribute('href', 'index.php')); $link1->add_child(new html_library\HTMLTextNode('Home page')); $body->add_child($link1); $body->add_child(new \html_library\HTMLBrElement()); $link2 = new html_library\HTMLAElement(); $link2->add_attribute(new html_library\HTMLAttribute('href', 'upload.php')); $link2->add_child(new html_library\HTMLTextNode('Upload a new photo')); $body->add_child($link2); $body->add_child(new \html_library\HTMLBrElement()); $link1 = new html_library\HTMLAElement(); $link1->add_attribute(new html_library\HTMLAttribute('href', 'new_gallery.php')); $link1->add_child(new html_library\HTMLTextNode('Create a new gallery')); $body->add_child($link1); $body->add_child(new \html_library\HTMLBrElement()); $gallery = new \models\Galerija(); $images = \db\DAO::getConnection()->getAllImagesInGallery($_GET['id']); $gallery->load($_GET['id']); $title = new \html_library\HTMLTitleElement(); $title->add_child(new \html_library\HTMLTextNode($gallery->__get('title') . ' (' . count($images) . ')')); $body->add_child($title); $body->add_child(new \html_library\HTMLBrElement()); $listElements = new \html_library\HTMLUlElement(); foreach ($images as $image) { $values = get_object_vars($image); $listElement = new \html_library\HTMLLiElement(); $picLink = new \html_library\HTMLAElement(); $picLink->add_attribute(new \html_library\HTMLAttribute('href', "aboutPicture.php?id=" . $values['ID'])); $imgContent = new \html_library\HTMLImageElement(); $imgContent->add_attribute(new \html_library\HTMLAttribute('src', "picture.php?id=" . $values['ID'] . "&size=small")); $picLink->add_child($imgContent); $imgTitle = new \html_library\HTMLTitleElement(3);
$link2 = new html_library\HTMLAElement(); $link2->add_attribute(new html_library\HTMLAttribute('href', 'upload.php')); $link2->add_child(new html_library\HTMLTextNode('Upload a new photo')); $body->add_child($link2); $body->add_child(new \html_library\HTMLBrElement()); $link1 = new html_library\HTMLAElement(); $link1->add_attribute(new html_library\HTMLAttribute('href', 'new_gallery.php')); $link1->add_child(new html_library\HTMLTextNode('Create a new gallery')); $body->add_child($link1); $body->add_child(new \html_library\HTMLBrElement()); $title = new \html_library\HTMLTitleElement(); $title->add_child(new \html_library\HTMLTextNode('Your galleries: ')); $body->add_child($title); $body->add_child(new \html_library\HTMLBrElement()); $listElements = new \html_library\HTMLUlElement(); $galleries = \db\DAO::getConnection()->getGalleriesByUserId($_SESSION['user_id']); foreach ($galleries as $gallery) { $values = get_object_vars($gallery); $listElement = new \html_library\HTMLLiElement(); $galleryTitle = new \html_library\HTMLTitleElement(3); $galleryTitle->add_child(new \html_library\HTMLTextNode($values['title'])); $galleryDescription = new \html_library\HTMLTitleElement(5); $galleryDescription->add_child(new \html_library\HTMLTextNode($values['description'])); $visitLink = new \html_library\HTMLAElement(); $visitLink->add_attribute(new \html_library\HTMLAttribute('href', "picturesInGallery.php?id=" . $values['ID'])); $visitLink->add_child(new \html_library\HTMLTextNode('Open gallery')); $editLink = new \html_library\HTMLAElement(); $editLink->add_attribute(new \html_library\HTMLAttribute('href', "editgallery.php?id=" . $values['ID'])); $editLink->add_child(new \html_library\HTMLTextNode('Edit gallery')); $listElement->add_child($galleryTitle); $listElement->add_child(new \html_library\HTMLBrElement());
$formValidation = new \validation_library\FormValidation(); $rules = array(); $rules['tags'] = 'required|length[500]'; $formValidation->set_rules($rules); if ($formValidation->validate()) { $tags = \models\ImgTag::validateTags($_POST['tags']); if ($tags === false) { echo "Every tag must be <= 50 characters"; header("Refresh: 1"); exit; } $searchTags = []; foreach ($tags as $tag) { array_push($searchTags, strtolower($tag)); } $results = \db\DAO::getConnection()->getImagesByTags($searchTags); if (empty($results)) { echo "No results for those tags"; } } else { $formValidation->display_validation_errors(); } } $page = new html_library\HTMLHtmlElement(); $page->add_child(new html_library\HTMLHeadElement()); $body = new html_library\HTMLBodyElement(); $page->add_child($body); $form = new \html_library\HTMLFormElement(); $body->add_child($form); $form->add_attribute(new \html_library\HTMLAttribute('name', 'search')); $form->add_attribute(new \html_library\HTMLAttribute('action', ''));
session_start(); // not logged in or id of photo not set if (!isset($_SESSION['user_id']) || !isset($_GET['id'])) { header('Location: index.php'); } //not his gallery $gallery = new \models\Galerija(); $gallery->load($_GET['id']); if ($gallery->__get('user_id') !== $_SESSION['user_id']) { header('Location: index.php'); } if (!empty($_POST['submitted'])) { if (isset($_POST['btnDelete'])) { $gallery->delete(); //TODO: Obrisati i slike iz te galerije \db\DAO::getConnection()->removeImagesInGallery($_GET['id']); header('Location: mygalleries.php'); exit; } $formValidation = new \validation_library\FormValidation(); $rules = array(); $rules['title'] = 'required|length[100]'; $rules['description'] = 'length[500]'; $formValidation->set_rules($rules); if ($formValidation->validate()) { $gallery->__set('title', htmlentities($_POST['title'])); $gallery->__set('description', htmlentities($_POST['description'])); $gallery->save(); header('Location: mypictures.php'); exit; } else {
$body->add_child($title); $body->add_child(new \html_library\HTMLBrElement()); $listElements = new \html_library\HTMLUlElement(); $images = \db\DAO::getConnection()->getImagesByUser($_SESSION['user_id']); foreach ($images as $image) { $values = get_object_vars($image); $listElement = new \html_library\HTMLLiElement(); $picLink = new \html_library\HTMLAElement(); $picLink->add_attribute(new \html_library\HTMLAttribute('href', "aboutPicture.php?id=" . $values['ID'])); $imgContent = new \html_library\HTMLImageElement(); $imgContent->add_attribute(new \html_library\HTMLAttribute('src', "picture.php?id=" . $values['ID'] . "&size=small")); $picLink->add_child($imgContent); $imgTitle = new \html_library\HTMLTitleElement(3); $imgTitle->add_child(new \html_library\HTMLTextNode($values['title'])); $galleryTitle = new \html_library\HTMLTitleElement(5); $galleryTitle->add_child(new \html_library\HTMLTextNode(\db\DAO::getConnection()->getGallery($values['gallery_id'])->title)); $editLink = new \html_library\HTMLAElement(); $editLink->add_attribute(new \html_library\HTMLAttribute('href', "editphoto.php?id=" . $values['ID'])); $editLink->add_child(new \html_library\HTMLTextNode('Edit photo')); $listElement->add_child($imgTitle); $listElement->add_child(new \html_library\HTMLBrElement()); $listElement->add_child($picLink); $listElement->add_child(new \html_library\HTMLBrElement()); $listElement->add_child($galleryTitle); $listElement->add_child(new \html_library\HTMLBrElement()); $listElement->add_child($editLink); $listElement->add_child(new \html_library\HTMLBrElement()); $listElements->add_child($listElement); } $body->add_child($listElements); echo $page;
$body->add_child(new \html_library\HTMLTextNode("Total times visited: " . \db\DAO::getConnection()->totalCountImageVisited($_GET['id']))); $body->add_child(new \html_library\HTMLBrElement()); $lastWeek = \db\DAO::getConnection()->lastWeekImageVisited($_GET['id']); foreach ($lastWeek as $key => $value) { $body->add_child(new \html_library\HTMLTextNode($key . ': ' . $value)); $body->add_child(new \html_library\HTMLBrElement()); } ////graph rendering $data = implode('&', array_map(function ($v, $k) { return $k . '=' . $v; }, $lastWeek, array_keys($lastWeek))); $imageTag = new \html_library\HTMLImageElement(); $imageTag->add_attribute(new \html_library\HTMLAttribute('src', 'renderGraph.php?' . $data)); $body->add_child($imageTag); $listElements = new \html_library\HTMLUlElement(); $comments = \db\DAO::getConnection()->getCommentsForImage($_GET['id']); foreach ($comments as $comment) { $values = get_object_vars($comment); $listElement = new \html_library\HTMLLiElement(); $username = new \html_library\HTMLTitleElement(3); $username->add_child(new \html_library\HTMLTextNode($values['username'])); $commentData = new \html_library\HTMLTitleElement(5); $commentData->add_child(new \html_library\HTMLTextNode($values['comment_data'])); $listElement->add_child($username); $listElement->add_child($commentData); $listElements->add_child($listElement); } $body->add_child($listElements); $form = new \html_library\HTMLFormElement(); if (isset($_SESSION['user_id'])) { $body->add_child($form);