Archived
first commit
This commit is contained in:
commit
386ce0b3de
55 files changed
+27107
No files matched your search
Executable
+204
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
use model\books;
|
||||
use model\users;
|
||||
use model\stock;
|
||||
use model\records;
|
||||
use model\template;
|
||||
use model\categories;
|
||||
|
||||
class admin_controller {
|
||||
|
||||
public function books() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
foreach ($books = books::list_books($page) as $k => $v)
|
||||
$books[$k]['stock'] = stock::count_in_stock_by_bid($v['bid']).'/'.stock::count_stock_by_bid($v['bid']);
|
||||
$this->template('书籍管理', 'books', ['books' => $books, 'page' => $page, 'count' => books::count_books(), 'stock' => stock::count_stock()]);
|
||||
}
|
||||
|
||||
public function users() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$users = users::list_users($page);
|
||||
$this->template('用户管理', 'users', ['users' => $users, 'page' => $page, 'count' => users::count_users(), 'stock' => stock::count_out_stock()]);
|
||||
}
|
||||
|
||||
public function stock() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
$books = stock::list_stock_by_bid($_GET['bid'], $page);
|
||||
$count = stock::count_stock_by_bid($_GET['bid']);
|
||||
$stock = stock::count_in_stock_by_bid($_GET['bid']);
|
||||
} else {
|
||||
$books = stock::list_stock($page);
|
||||
$count = stock::count_stock();
|
||||
$stock = stock::count_in_stock();
|
||||
} $this->template('库存管理', 'stock', ['books' => $books, 'page' => $page, 'count' => $count, 'stock' => $stock]);
|
||||
}
|
||||
|
||||
public function categories() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$categories = categories::list_categories($page);
|
||||
$this->template('分类管理', 'categories', ['categories' => $categories, 'page' => $page, 'count' => categories::count_categories(), 'stock' => stock::count_stock()]);
|
||||
}
|
||||
|
||||
public function add_user() {
|
||||
$this->template('添加用户', 'add_user');
|
||||
}
|
||||
|
||||
public function update_user() {
|
||||
if (isset($_GET['uid']) && is_numeric($_GET['uid'])) {
|
||||
$this->template('更新用户', 'update_user', ['user' => users::get_user_by_id($_GET['uid'])]);
|
||||
} else header('Location: /admin/users');
|
||||
}
|
||||
|
||||
public function delete_user() {
|
||||
if (isset($_GET['uid']) && is_numeric($_GET['uid'])) {
|
||||
$this->template('删除用户', 'delete_user', ['user' => users::get_user_by_id($_GET['uid'])]);
|
||||
} else header('Location: /admin/users');
|
||||
}
|
||||
|
||||
public function add_book() {
|
||||
$categories = categories::get_categories();
|
||||
$this->template('添加书籍', 'add_book', ['categories' => $categories]);
|
||||
}
|
||||
|
||||
public function update_book() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
$this->template('更新书籍', 'update_book', ['book' => books::get_book_by_id($_GET['bid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/books');
|
||||
}
|
||||
|
||||
public function delete_book() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
$this->template('删除书籍', 'delete_book', ['book' => books::get_book_by_id($_GET['bid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/books');
|
||||
}
|
||||
|
||||
public function add_stock() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
$this->template('添加库存', 'add_stock', ['book' => books::get_book_by_id($_GET['bid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/stock');
|
||||
}
|
||||
|
||||
public function update_stock() {
|
||||
if (isset($_GET['sid']) && is_numeric($_GET['sid'])) {
|
||||
$this->template('更新库存', 'update_stock', ['book' => stock::get_stock_by_id($_GET['sid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/stock');
|
||||
}
|
||||
|
||||
public function delete_stock() {
|
||||
if (isset($_GET['sid']) && is_numeric($_GET['sid'])) {
|
||||
$this->template('删除库存', 'delete_stock', ['book' => stock::get_stock_by_id($_GET['sid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/stock');
|
||||
}
|
||||
|
||||
public function add_category() {
|
||||
$this->template('添加分类', 'add_category');
|
||||
}
|
||||
|
||||
public function update_category() {
|
||||
if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
|
||||
$this->template('更新分类', 'update_category', ['category' => categories::get_category_by_id($_GET['cid'])]);
|
||||
} else header('Location: /admin/categories');
|
||||
}
|
||||
|
||||
public function delete_category() {
|
||||
if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
|
||||
$this->template('删除分类', 'delete_category', ['category' => categories::get_category_by_id($_GET['cid']), 'categories' => categories::get_categories()]);
|
||||
} else header('Location: /admin/categories');
|
||||
}
|
||||
|
||||
public function do_add_user() {
|
||||
$username = $_POST['username'];
|
||||
if (!(strlen($username) <= 30 && preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/u', $username)))
|
||||
exit(header('Location: /admin/add-user?page='.$_GET['page'].'&error=用户名不合规'));
|
||||
$password = $_POST['password'];
|
||||
if ($password != $_POST['confirm'])
|
||||
exit(header('Location: /admin/add-user?page='.$_GET['page'].'&error=两次输入密码不一致'));
|
||||
|
||||
header('Location: ' . (users::add_user($username, $password, $_POST['sex'], $_POST['birthday'], $_POST['id_card'], $_POST['borrow_num'], $_POST['type']) ?
|
||||
'/admin/users?page='.$_GET['page'] : '/admin/add-user?page='.$_GET['page'].'&error=数据库错误'));
|
||||
}
|
||||
|
||||
public function do_update_user() {
|
||||
if (isset($_GET['uid']) && is_numeric($_GET['uid'])) {
|
||||
if (empty($password = $_POST['password']))
|
||||
$password = null;
|
||||
elseif ($password != $_POST['confirm'])
|
||||
exit(header('Location: /admin/update-user?page='.$_GET['page'].'&uid='.$_GET['uid'].'&error=两次输入密码不一致'));
|
||||
|
||||
header('Location: ' . (users::update_user($_GET['uid'], $password, $_POST['sex'], $_POST['birthday'], $_POST['id_card'], $_POST['borrow_num'], $_POST['type']) ?
|
||||
'/admin/users?page='.$_GET['page'] : '/admin/update-user?page='.$_GET['page'].'&uid='.$_GET['uid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/users?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_delete_user() {
|
||||
if (isset($_GET['uid']) && is_numeric($_GET['uid'])) {
|
||||
header('Location: ' . (users::del_user_by_id($_GET['uid']) ?
|
||||
'/admin/users?page='.$_GET['page'] : '/admin/delete-user?page='.$_GET['page'].'&uid='.$_GET['uid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/users?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_add_book() {
|
||||
header('Location: ' . (books::add_book($_POST['name'], $_POST['author'], $_POST['publish'], $_POST['isbn'], $_POST['cover'], $_POST['type'], $_POST['lang']) ?
|
||||
'/admin/books?page='.$_GET['page'] : '/admin/add-book?page='.$_GET['page'].'&error=数据库错误'));
|
||||
}
|
||||
|
||||
public function do_update_book() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
header('Location: ' . (books::update_book($_GET['bid'], $_POST['name'], $_POST['author'], $_POST['publish'], $_POST['isbn'], $_POST['cover'], $_POST['type'], $_POST['lang']) ?
|
||||
'/admin/books?page='.$_GET['page'] : '/admin/update-book?page='.$_GET['page'].'&bid='.$_GET['bid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/books?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_delete_book() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
header('Location: ' . (books::del_book_by_id($_GET['bid']) ?
|
||||
'/admin/books?page='.$_GET['page'] : '/admin/delete-book?page='.$_GET['page'].'&bid='.$_GET['bid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/books?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_add_stock() {
|
||||
if (isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
header('Location: ' . (stock::add_stock($_GET['bid'], $_POST['place'], $_POST['health'], $_POST['state']) ?
|
||||
'/admin/stock?bid='.$_GET['bid'] : '/admin/add-stock?page='.$_GET['page'].'%bid='.$_GET['bid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/stock?bid='.$_GET['bid'].'&page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_update_stock() {
|
||||
if (isset($_GET['sid']) && isset($_GET['bid']) && is_numeric($_GET['sid']) && is_numeric($_GET['bid'])) {
|
||||
header('Location: ' . (stock::update_stock($_GET['sid'], $_GET['bid'], $_POST['place'], $_POST['health'], $_POST['state']) ?
|
||||
'/admin/stock?page='.$_GET['page'] : '/admin/update-stock?page='.$_GET['page'].'&sid='.$_GET['sid'].'&bid='.$_GET['bid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/stock?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_delete_stock() {
|
||||
if (isset($_GET['sid']) && is_numeric($_GET['sid'])) {
|
||||
header('Location: ' . (stock::del_stock_by_id($_GET['sid']) ?
|
||||
'/admin/stock?page='.$_GET['page'] : '/admin/delete-stock?page='.$_GET['page'].'&sid='.$_GET['sid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/stock?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_add_category() {
|
||||
header('Location: ' . (categories::add_category($_POST['name']) ?
|
||||
'/admin/categories?page='.$_GET['page'] : '/admin/add-categories?page='.$_GET['page'].'&error=数据库错误'));
|
||||
}
|
||||
|
||||
public function do_update_category() {
|
||||
if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
|
||||
header('Location: ' . (categories::update_category($_GET['cid'], $_POST['name']) ?
|
||||
'/admin/categories?page='.$_GET['page'] : '/admin/update-category?page='.$_GET['page'].'&cid='.$_GET['cid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/categories?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_delete_category() {
|
||||
if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
|
||||
header('Location: ' . (books::update_book_category($_GET['cid'], $_POST['category']) && categories::del_category_by_id($_GET['cid']) ?
|
||||
'/admin/categories?page='.$_GET['page'] : '/admin/delete-category?page='.$_GET['page'].'&cid='.$_GET['cid'].'&error=数据库错误'));
|
||||
} else header('Location: /admin/categories?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
private function template($title, $name, $parameters = []) {
|
||||
template::render('admins', $name, array_merge(['title' => $title], $parameters));
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
use model\books;
|
||||
use model\stock;
|
||||
use model\records;
|
||||
use model\template;
|
||||
use model\categories;
|
||||
|
||||
class default_controller {
|
||||
|
||||
public function index() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$count = records::count_hot_records();
|
||||
$books = records::list_hot_records($page);
|
||||
$categories = categories::get_categories();
|
||||
$records = isset($_SESSION['user']) ? records::get_in_records_by_uid($_SESSION['user']['uid']) : null;
|
||||
$records_count = isset($_SESSION['user']) ? records::count_in_records_by_uid($_SESSION['user']['uid']) : 0;
|
||||
$this->template('首页', 'index', ['books' => $books, 'page' => $page, 'count' => $count, 'categories' => $categories, 'records' => $records, 'records_count' => $records_count]);
|
||||
}
|
||||
|
||||
public function lists() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$count = books::count_books();
|
||||
$books = books::list_books($page);
|
||||
$categories = categories::get_categories();
|
||||
$records = isset($_SESSION['user']) ? records::get_in_records_by_uid($_SESSION['user']['uid']) : null;
|
||||
$records_count = isset($_SESSION['user']) ? records::count_in_records_by_uid($_SESSION['user']['uid']) : 0;
|
||||
$this->template('书籍列表', 'lists', ['books' => $books, 'page' => $page, 'count' => $count, 'categories' => $categories, 'records' => $records, 'records_count' => $records_count]);
|
||||
}
|
||||
|
||||
public function search() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
if (isset($_GET['s']) && !empty($_GET['s'])) {
|
||||
$word = $_GET['s'] ?? '';
|
||||
$books = books::find_books($word, $page);
|
||||
$count = books::count_find_books($word);
|
||||
$categories = categories::get_categories();
|
||||
} else $word = $books = $count = $categories = null;
|
||||
$records = isset($_SESSION['user']) ? records::get_in_records_by_uid($_SESSION['user']['uid']) : null;
|
||||
$records_count = isset($_SESSION['user']) ? records::count_in_records_by_uid($_SESSION['user']['uid']) : 0;
|
||||
$this->template('馆存查询', 'search', ['books' => $books, 'page' => $page, 'count' => $count, 'categories' => $categories, 'records' => $records, 'records_count' => $records_count]);
|
||||
}
|
||||
|
||||
public function book($bid) {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$count = stock::count_stock_by_bid($bid);
|
||||
$stock = stock::count_in_stock_by_bid($bid);
|
||||
$books = stock::list_stock_by_bid($bid, $page);
|
||||
$this->template('库存查询', 'book', ['books' => $books, 'page' => $page, 'count' => $count, 'stock' => $stock]);
|
||||
}
|
||||
|
||||
private function template($title, $name, $parameters = []) {
|
||||
template::render('defaults', $name, array_merge(['title' => $title], $parameters));
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
use model\users;
|
||||
use model\stock;
|
||||
use model\records;
|
||||
use model\template;
|
||||
|
||||
class user_controller {
|
||||
|
||||
public function info() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$this->template('个人资料', 'info');
|
||||
}
|
||||
|
||||
public function record() {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$books = records::list_records_by_uid($_SESSION['user']['uid'], $page);
|
||||
$count = records::count_records_by_uid($_SESSION['user']['uid']);
|
||||
$stock = records::count_in_records_by_uid($_SESSION['user']['uid']);
|
||||
$this->template('借书记录', 'record', ['books' => $books, 'page' => $page, 'count' => $count, 'stock' => $stock]);
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$this->template('更新信息', 'update');
|
||||
}
|
||||
|
||||
public function login() {
|
||||
$this->template('用户登录', 'login');
|
||||
}
|
||||
|
||||
public function register() {
|
||||
$this->template('用户注册', 'register');
|
||||
}
|
||||
|
||||
public function update_stock() {
|
||||
if (isset($_GET['sid']) && is_numeric($_GET['sid']) && isset($_GET['bid']) && is_numeric($_GET['bid'])) {
|
||||
if (stock::update_stock_state($_GET['sid'], 1))
|
||||
records::add_record($_GET['bid'], $_SESSION['user']['uid'], $_GET['sid'], time());
|
||||
} header('Location: /book/'.$_GET['bid'].'?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function update_record() {
|
||||
if (isset($_GET['rid']) && is_numeric($_GET['rid']) && isset($_GET['sid']) && is_numeric($_GET['sid'])) {
|
||||
if (records::update_record($_GET['rid'], time())) stock::update_stock_state($_GET['sid'], 0);
|
||||
} header('Location: /user/record?page='.$_GET['page']);
|
||||
}
|
||||
|
||||
public function do_login() {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
if (!(strlen($username) <= 30 && preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/u', $username)))
|
||||
exit(header('Location: /user/login?error=用户名不合规'));
|
||||
if ($user = users::get_user($username)) {
|
||||
if ($user['password'] == hash('sha256', $GLOBALS['config']['salt'].$password)) {
|
||||
$_SESSION['user'] = $user;
|
||||
header('Location: /user/info');
|
||||
} else header('Location: /user/login?error=密码错误');
|
||||
} else header('Location: /user/login?error=用户不存在');
|
||||
}
|
||||
|
||||
public function do_logout() {
|
||||
session_destroy();
|
||||
header('Location: /user/login?error=注销成功');
|
||||
}
|
||||
|
||||
public function do_update() {
|
||||
$sex = $_POST['sex'];
|
||||
$birthday = $_POST['birthday'];
|
||||
if (empty($password = $_POST['password']))
|
||||
$password = null;
|
||||
elseif ($password != $_POST['confirm'])
|
||||
exit(header('Location: /user/update?error=两次输入密码不一致'));
|
||||
|
||||
if (users::update_user($_SESSION['user']['uid'], $password, $sex, $birthday, $_SESSION['user']['id_card'], $_SESSION['user']['borrow_num'], $_SESSION['user']['type'])) {
|
||||
session_destroy();
|
||||
header('Location: /user/login?error=更新成功,请重新登录');
|
||||
} else header('Location: /user/update?error=数据库错误');
|
||||
}
|
||||
|
||||
public function do_register() {
|
||||
$username = $_POST['username'];
|
||||
if (!(strlen($username) <= 30 && preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/u', $username)))
|
||||
exit(header('Location: /user/register?error=用户名不合规'));
|
||||
$id_card = $_POST['id_card'];
|
||||
if (strlen($id_card) < 10 || !is_numeric($id_card))
|
||||
exit(header('Location: /user/register?error=身份证不合规'));
|
||||
$password = $_POST['password'];
|
||||
if ($password != $_POST['confirm'])
|
||||
exit(header('Location: /user/register?error=两次输入密码不一致'));
|
||||
|
||||
if (users::add_user($username, $password, 0, '1900-01-01', $id_card, 15, 0))
|
||||
header('Location: /user/login?error=注册成功,请登录');
|
||||
else header('Location: /user/register?error=数据库错误');
|
||||
}
|
||||
|
||||
private function template($title, $name, $parameters = []) {
|
||||
template::render('users', $name, array_merge(['title' => $title], $parameters));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user