219 lines
5.0 KiB
PHP
219 lines
5.0 KiB
PHP
<?
|
|
|
|
namespace controls;
|
|
|
|
class Apanel
|
|
{
|
|
static public function login_view()
|
|
{
|
|
if (\S::get_session('user'))
|
|
{
|
|
header('Location: /apanel/main_view/');
|
|
}
|
|
else
|
|
{
|
|
return \Tpl::view('admin-panel/login');
|
|
}
|
|
}
|
|
|
|
static public function main_view()
|
|
{
|
|
global $mdb;
|
|
$ordersArr = $mdb->query('SELECT id, name, surname, email, order_price, date_added, payment_status, used_ticket FROM orders')->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
return \Tpl::view('admin-panel/main-view', [
|
|
'orders' => $ordersArr
|
|
]);
|
|
}
|
|
|
|
static public function order_data()
|
|
{
|
|
global $mdb;
|
|
$clientId = $_GET['id'];
|
|
$orderTickets = $mdb->query('SELECT * FROM order_tickets WHERE order_id =' . $clientId)->fetchAll(\PDO::FETCH_ASSOC);
|
|
$orderInfo = $mdb->select('orders', '*', ['id' => $clientId]);
|
|
|
|
\S::del_session('user_orders');
|
|
\S::set_session('user_orders', $orderTickets);
|
|
|
|
return \Tpl::view('admin-panel/order-data', [
|
|
'order_tickets' => $orderTickets,
|
|
'order_info' => $orderInfo,
|
|
]);
|
|
}
|
|
|
|
static public function login_check()
|
|
{
|
|
global $settings;
|
|
$writingPassword = trim($_POST['admin_password']);
|
|
|
|
if ($writingPassword == $settings['admin-password'])
|
|
{
|
|
\S::set_session('user', true);
|
|
header('Location: /scanner/scanner_view/');
|
|
}
|
|
else
|
|
{
|
|
header('Location: /apanel/login_view/');
|
|
}
|
|
exit;
|
|
}
|
|
|
|
static public function unlogin()
|
|
{
|
|
\S::del_session("user");
|
|
header('Location: /apanel/login_view/');
|
|
|
|
exit;
|
|
}
|
|
|
|
//* Increment ticket
|
|
static public function ticket_inc()
|
|
{
|
|
$basket = \S::get_session('user_orders');
|
|
|
|
$ticket_id = \S::get('ticket_id');
|
|
|
|
if ($basket[$ticket_id])
|
|
{
|
|
$basket[$ticket_id]['quantity']++;
|
|
}
|
|
else
|
|
{
|
|
$basket[$ticket_id]['quantity'] = 1;
|
|
}
|
|
|
|
|
|
$basket = \factory\Apanel::recalculate_ticket_protection( $basket );
|
|
$basket = \factory\Apanel::check_delivery( $basket );
|
|
|
|
\S::set_session( 'user_orders', $basket );
|
|
|
|
echo json_encode([
|
|
'basket_form' => \Tpl::view('admin-panel/order-data-table', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
'order_summ' => \Tpl::view('admin-panel/order-summary', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
]);
|
|
|
|
exit;
|
|
}
|
|
|
|
//* Decrement ticket
|
|
static public function ticket_dec()
|
|
{
|
|
$basket = \S::get_session('user_orders');
|
|
|
|
$ticket_id = \S::get('ticket_id');
|
|
|
|
$basket[$ticket_id]['quantity']--;
|
|
|
|
if ( $basket[$ticket_id]['quantity'] == 0 )
|
|
{
|
|
unset($basket[$ticket_id]);
|
|
}
|
|
|
|
$basket = \factory\Apanel::recalculate_ticket_protection( $basket );
|
|
$basket = \factory\Apanel::check_delivery( $basket );
|
|
|
|
\S::set_session('user_orders', $basket);
|
|
|
|
echo json_encode([
|
|
'basket_form' => \Tpl::view('admin-panel/order-data-table', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
'order_summ' => \Tpl::view('admin-panel/order-summary', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
]);
|
|
|
|
exit;
|
|
}
|
|
|
|
//* Remove ticket
|
|
static public function ticket_rem()
|
|
{
|
|
$basket = \S::get_session('user_orders');
|
|
|
|
$ticket_id = \S::get('ticket_id');
|
|
|
|
unset($basket[$ticket_id]);
|
|
|
|
$basket = \factory\Apanel::recalculate_ticket_protection( $basket );
|
|
$basket = \factory\Apanel::check_delivery( $basket );
|
|
|
|
\S::set_session('user_orders', $basket);
|
|
|
|
echo json_encode([
|
|
'basket_form' => \Tpl::view('admin-panel/order-data-table', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
'order_summ' => \Tpl::view('admin-panel/order-summary', [
|
|
'order_tickets' => $basket
|
|
]),
|
|
]);
|
|
|
|
exit;
|
|
}
|
|
|
|
//* Save new tickets list
|
|
static public function ticket_save()
|
|
{
|
|
global $mdb;
|
|
|
|
$order_id = \S::get('order_id');
|
|
$payment_status = \S::get( 'payment_status' );
|
|
$basket = \S::get_session('user_orders');
|
|
$order_price = 0;
|
|
|
|
$mdb -> delete('order_tickets',['order_id' => $order_id]);
|
|
|
|
foreach ($basket as $key => $value)
|
|
{
|
|
$order_price += $value['price'] * $value['quantity'];
|
|
//* Zapisywanie do DB bilety
|
|
$mdb->insert('order_tickets', [
|
|
'order_id' => $order_id,
|
|
'product_id' => $value['product_id'],
|
|
'name' => $value['name'],
|
|
'quantity' => $value['quantity'],
|
|
'price' => trim($value['price']),
|
|
'date_visit' => $value['date_visit'],
|
|
'date_added' => $value['date_added']
|
|
]);
|
|
}
|
|
$mdb->update('orders', ['order_price' => $order_price, 'payment_status' => $payment_status ], ['id' => $order_id]);
|
|
|
|
exit;
|
|
}
|
|
|
|
static public function order_delete()
|
|
{
|
|
global $mdb;
|
|
|
|
$order_id = \S::get('order_id');
|
|
|
|
$mdb->delete('order_tickets', ['order_id' => $order_id]);
|
|
$mdb->delete('orders', ['id' => $order_id]);
|
|
|
|
header( 'Location: /apanel/main_view/' );
|
|
exit;
|
|
}
|
|
|
|
static public function use_ticket() {
|
|
global $mdb;
|
|
|
|
$order_id = \S::get('order_id');
|
|
$date = date('Y-m-d H:i:s');
|
|
$mdb->update('orders', ['used_ticket' => 1, 'used_ticket_date' => $date], ['id' => $order_id]);
|
|
|
|
echo json_encode([
|
|
'useStatus' => true
|
|
]);
|
|
|
|
exit;
|
|
}
|
|
} |