Example #1
0
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'bootstrap.php';
$bookSelector = new BookSelect();
// find out how many results will be displayed on one page
$results = Config::get('pagination/results_per_page');
// find out how many records there are for given context
if (Input::exists('get') && Input::found('author')) {
    $records = $bookSelector->countBooks('author', Input::get('author'));
} else {
    if (Input::exists('get') && Input::found('genre')) {
        $records = $bookSelector->countBooks('genre', Input::get('genre'));
    } else {
        if (Input::exists('get') && Input::found('title')) {
            $records = $bookSelector->countBooks('title', Input::get('title'));
        } else {
            $records = $bookSelector->countBooks();
        }
    }
}
// calculate the last page of results
$last = ceil($records / $results);
// make sure $last cannot be less than 1
$last = $last >= 1 ? $last : 1;
// define the number of current page
$page = Input::exists('get') && Input::found('page') ? Input::get('page') : 1;
// change initial $page value if it's bigger than that of the $last page or less than 1
if ($page < 1) {
    $page = 1;
} else {
    if ($page > $last) {
Example #2
0
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'bootstrap.php';
// we should include header before other PHP logic because of it's search functionality
$pageTitle = 'BkShp| Описание';
include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'header.php';
// check if there is query string with book id and if it's valid. Load book data.
if (Input::exists('get') && Input::found('id')) {
    $bookManager = new BookSelect();
    $id = Input::get('id');
    $book = $bookManager->getBook($id);
    if ($book === false) {
        Session::flash('home', 'Книги с указанным id(' . Input::get('id') . ') не существует');
        Redirect::to('index.php');
    }
} else {
    Session::flash('home', 'Книга не указана');
    Redirect::to('index.php');
}
// we will check this confuguration in a few places across the page so it's better to call it once
$recaptchaEnabled = Config::get('google_recaptcha/enabled') === '1' ? true : null;
if ($recaptchaEnabled) {
    // include reCAPTCHA API
    echo '<script src="https://www.google.com/recaptcha/api.js?hl=ru"></script>';
    // include a library that handles calling Google reCAPTCHA
    require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'recaptcha.php';
}
/**
* establish error handler outside the following if block because
* of a need to output error information to the user
**/
Example #3
0
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'bootstrap.php';
// we need to include header first because of search functionality
$pageTitle = 'BkShp| Изменить';
include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'header.php';
// check if there is query string with book id and if it's valid. Load book data.
if (Input::exists('get') && Input::found('id')) {
    $bookSelector = new BookSelect();
    $id = Input::get('id');
    $book = $bookSelector->getBook($id, true);
    if ($book === false) {
        Session::flash('home', 'Книги с указанным id(' . Input::get('id') . ') не существует');
        Redirect::to('manage.php');
    }
} else {
    Session::flash('home', 'Не указана книга для редактирования');
    Redirect::to('manage.php');
}
/**
* There isn't a way to properly check if uploaded file exceeds post_max_size
* limit in php.ini, so we validate $_SERVER['CONTENT_LENGTH'] to avoid unnecessary
* warnings and to make overall experience a bit more user friendly
**/
$postMaxSize = Info::convertToBytes(ini_get('post_max_size'));
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $postMaxSize) {
    Session::flash('home', 'Вы пытаетесь загрузить слишком большой файл.');
    Redirect::to();
}
$errorHandler = new ErrorHandler();
if (Input::exists()) {