mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 18:01:27 +00:00
98 lines
2.9 KiB
PHP
98 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use Blacklight\Books;
|
|
use App\Models\BookInfo;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use App\Http\Controllers\BasePageController;
|
|
|
|
class BookController extends BasePageController
|
|
{
|
|
/**
|
|
* @throws \Exception
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->setAdminPrefs();
|
|
|
|
$title = 'Book List';
|
|
|
|
$bookList = BookInfo::query()->orderByDesc('created_at')->paginate(config('nntmux.items_per_page'));
|
|
|
|
$this->smarty->assign('booklist', $bookList);
|
|
|
|
$content = $this->smarty->fetch('book-list.tpl');
|
|
|
|
$this->smarty->assign(
|
|
[
|
|
'title' => $title,
|
|
'content' => $content,
|
|
]
|
|
);
|
|
|
|
$this->adminrender();
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Http\Request $request
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
* @throws \Exception
|
|
*/
|
|
public function edit(Request $request)
|
|
{
|
|
$this->setAdminPrefs();
|
|
$book = new Books();
|
|
|
|
// set the current action
|
|
$action = $request->input('action') ?? 'view';
|
|
|
|
if ($request->has('id')) {
|
|
$id = $request->input('id');
|
|
$b = $book->getBookInfo($id);
|
|
|
|
if (! $b) {
|
|
$this->show404();
|
|
}
|
|
|
|
switch ($action) {
|
|
case 'submit':
|
|
$coverLoc = resource_path().'/covers/book/'.$id.'.jpg';
|
|
|
|
if ($_FILES['cover']['size'] > 0) {
|
|
$tmpName = $_FILES['cover']['tmp_name'];
|
|
$file_info = getimagesize($tmpName);
|
|
if (! empty($file_info)) {
|
|
move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
|
|
}
|
|
}
|
|
|
|
$request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
|
|
$request->merge(['publishdate' => (empty($request->input('publishdate')) || ! strtotime($request->input('publishdate'))) ? $con['publishdate'] : Carbon::parse($request->input('publishdate'))->timestamp]);
|
|
$book->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('author'), $request->input('publisher'), $request->input('publishdate'), $request->input('cover'));
|
|
|
|
return redirect('admin/book-list');
|
|
break;
|
|
case 'view':
|
|
default:
|
|
$title = 'Book Edit';
|
|
$this->smarty->assign('book', $b);
|
|
break;
|
|
}
|
|
}
|
|
|
|
$content = $this->smarty->fetch('book-edit.tpl');
|
|
|
|
$this->smarty->assign(
|
|
[
|
|
'title' => $title,
|
|
'content' => $content,
|
|
]
|
|
);
|
|
|
|
$this->adminrender();
|
|
}
|
|
}
|