Пример #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', 'Неправильный токен');