Exemplo n.º 1
0
 public function lastWeekImageVisited($imageId)
 {
     $NUM_OF_DAYS = 7;
     $result = [];
     $query = \db\DAO::getInstance()->prepare("SELECT COUNT(*) AS timeVisited FROM Visits WHERE image_id = {$imageId} AND time = CURDATE() - ?");
     for ($i = 0; $i < $NUM_OF_DAYS; $i++) {
         $query->execute([$i]);
         $result[date("Y-m-d", strtotime("-{$i} days"))] = $query->fetch()->timeVisited;
     }
     return $result = array_reverse($result);
 }
Exemplo n.º 2
0
$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);
Exemplo n.º 3
0
 public function loadAll($where = null)
 {
     $sql = "SELECT * FROM " . $this->getTable() . " " . $where;
     $statement = DAO::getInstance()->prepare($sql);
     $statement->execute();
     if (1 > $statement->rowCount()) {
         return null;
     }
     $resources = $statement->fetchAll();
     $collection = array();
     $className = get_class($this);
     //$attributes = $this->getColumns();
     foreach ($resources as $singleRow) {
         $model = new $className();
         $model->pk = $singleRow->{$this->getPrimaryKeyColumn()};
         $model->data = $singleRow;
         /*foreach ($attributes as $prop) {
               $model->$prop = $singleRow->{$prop};
           }*/
         $collection[] = $model;
     }
     return $collection;
 }
Exemplo n.º 4
0
 * Date: 10/03/16
 * Time: 10:26
 */
require_once 'Autoloader.php';
session_start();
if (isset($_SESSION['user_id'])) {
    header('Location: index.php');
}
if (!empty($_POST['submitted'])) {
    $formValidation = new \validation_library\FormValidation();
    $rules = array();
    $rules['username'] = '******';
    $rules['password'] = '******';
    $formValidation->set_rules($rules);
    if ($formValidation->validate()) {
        $query = \db\DAO::getInstance()->prepare("SELECT id FROM Users WHERE username = ? AND password = ?");
        try {
            $query->execute([htmlentities($_POST["username"]), sha1($_POST["password"])]);
            //ako je upit djelovao na neki redak
            if ($query->rowCount() > 0) {
                $row = $query->fetch();
                $_SESSION["user_id"] = $row->id;
                header('Location: index.php');
            } else {
                echo "Wrong email or password.";
            }
        } catch (PDOException $e) {
            $errorMessage = "Please, try again or contact admin.";
        }
    } else {
        $formValidation->display_validation_errors();
Exemplo n.º 5
0
$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());
Exemplo n.º 6
0
 * Time: 14:38
 */
require_once 'Autoloader.php';
session_start();
if (!isset($_SESSION['user_id'])) {
    header('Location: index.php');
    exit;
}
if (!empty($_POST['submitted'])) {
    $rules = array();
    $rules['name'] = 'required|length[100]';
    $rules['description'] = 'length[500]';
    $formValidation = new \validation_library\FormValidation();
    $formValidation->set_rules($rules);
    if ($formValidation->validate()) {
        $query = \db\DAO::getInstance()->prepare("INSERT INTO Galleries(title, user_id,\n        description) VALUES (?,?,?)");
        $query->execute([htmlentities($_POST['name']), $_SESSION['user_id'], htmlentities($_POST['description'])]);
        header('Location: upload.php');
        exit;
    } else {
        $formValidation->display_validation_errors();
    }
}
//page rendering
$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('id', 'new_gallery'));
Exemplo n.º 7
0
    $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', ''));
Exemplo n.º 8
0
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 {
Exemplo n.º 9
0
$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;
Exemplo n.º 10
0
$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);
Exemplo n.º 11
0
if (!empty($_POST['submitted'])) {
    $rules = array();
    $rules['name'] = 'length[40]';
    $rules['surname'] = 'length[40]';
    $rules['username'] = '******';
    $rules['email'] = 'required|email|length[50]';
    $rules['password'] = '******';
    $rules['confirm_password'] = '******';
    $validation = new \validation_library\FormValidation();
    $validation->set_rules($rules);
    $allGood = $validation->validate();
    if (strcmp($_POST['password'], $_POST['confirm_password']) != 0) {
        $allGood = false;
    }
    if ($allGood) {
        $query = \db\DAO::getInstance()->prepare("INSERT INTO Users(username, name,\n        surname, email, password) VALUES (?,?,?,?,?)");
        if ($query->execute([htmlentities($_POST['username']), htmlentities($_POST['name']), htmlentities($_POST['surname']), htmlentities($_POST['email']), sha1($_POST['password'])])) {
            header('Location: login.php');
            echo "Sve ok";
        } else {
            echo "Username must be unique";
        }
        //  exit;
    } else {
        if (empty($validation->validation_errors())) {
            echo "Password doesn't match";
        } else {
            $validation->display_validation_errors();
        }
    }
}