Example #1
0
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'bootstrap.php';
// check if there is query string with book id. If not, redirect.
if (Input::exists('get') === false || Input::found('id') === false) {
    Redirect::to('index.php');
}
if (Token::check(Input::get('token'))) {
    //delete book from database
    $bookManager = new BookManage();
    $bookManager->delete(Input::get('id'));
    /**
     *
     * The following block of code if responsible for deleting book cover
     *
     **/
    $destination = dirname(__DIR__) . DIRECTORY_SEPARATOR . Config::get('upload_book_cover/default_folder');
    // adding trailing slash if there isn't one
    if ($destination[strlen($destination) - 1] != '/') {
        $destination .= '/';
    }
    // find the file by given name no mater what extension it has and delete it
    $pattern = $destination . Input::get('id') . '.*';
    $file = glob($pattern)[0];
    unlink($file);
    $logMessage = 'Книга удалена (' . Input::get('id') . ')';
    Log::getInstance()->message($logMessage, 'book_manage');
    Session::flash('home', 'Товар удален из каталога');
    Redirect::to('manage.php');
} else {
    Session::flash('home', 'Неправильный токен');
Example #2
0
if (Input::exists()) {
    if (Token::check(Input::get('token'))) {
        /*==================================
          =            Validation            =
          ==================================*/
        if (empty($_FILES) === false) {
            $fileValidator = new ValidateFile($errorHandler);
            $fileValidator->check($_FILES, ['cover' => ['sizeAllowed' => Config::get('upload_book_cover/max_file_size'), 'typeAllowed' => Config::csvToArray(Config::get('upload_book_cover/mime_types')), 'extensionAllowed' => Config::csvToArray(Config::get('upload_book_cover/extensions')), 'isImage' => true]]);
        }
        $validator = new Validate($errorHandler);
        $validator->check($_POST, ['author' => ['required' => true, 'minLength' => 3, 'partMinLength' => [3, ','], 'maxLength' => 240, 'partMaxLength' => [60, ',']], 'title' => ['required' => true, 'minLength' => 3, 'maxLength' => 80], 'title_secondary' => ['minLength' => 3, 'maxLength' => 80], 'genre' => ['required' => true, 'minLength' => 4, 'partMinLength' => [4, ','], 'maxLength' => 120, 'partMaxLength' => [30, ',']], 'publisher' => ['minLength' => 3, 'partMinLength' => [3, ','], 'maxLength' => 100, 'partMaxLength' => [50, ',']], 'year' => ['required' => true, 'digit' => true, 'exactLength' => 4], 'isbn' => ['required' => true, 'minLength' => 10, 'partMinLength' => [10, ','], 'maxLength' => 36, 'partMaxLength' => [17, ',']], 'pages' => ['digit' => true, 'minLength' => 2, 'maxLength' => 4], 'dimensions' => ['minLength' => 5, 'maxLength' => 10], 'price' => ['price' => true, 'minLength' => 2, 'maxLength' => 7]]);
        /*=====================================
          =            Book creation            =
          =====================================*/
        if ($errorHandler->hasErrors() === false) {
            $bookManager = new BookManage();
            $data = ['author' => Input::get('author'), 'title' => Input::get('title'), 'title_secondary' => Input::get('title_secondary'), 'description' => Input::get('description'), 'genre' => strtolower(Input::get('genre')), 'publisher' => Input::get('publisher'), 'year' => Input::get('year'), 'isbn' => Input::get('isbn'), 'pages' => Input::get('pages'), 'dimensions' => Input::get('dimensions'), 'price' => Input::get('price')];
            $bookManager->update($data, $book->id);
            $message = 'Информация о книге(' . $book->title . ', ' . $book->id . ') была отредактирована.';
            Log::getInstance()->message($message, 'book_manage');
            if (empty($_FILES) === false) {
                $upload = new UploadBookCover($fileValidator, $book->id);
                $uploaded = $upload->to(Config::get('upload_book_cover/default_folder'));
            }
            Session::flash('home', $message);
            Redirect::to('manage.php');
        }
    } else {
        Redirect::to();
    }
}