112 lines
4.2 KiB
PHP
112 lines
4.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../modules/shared/auth/service.php';
|
|
require_once __DIR__ . '/../modules/shared/auth/ui/login.php';
|
|
require_once __DIR__ . '/../modules/shared/auth/ui/home.php';
|
|
require_once __DIR__ . '/../modules/erp/bestellungen/service.php';
|
|
require_once __DIR__ . '/../modules/erp/lager/service.php';
|
|
require_once __DIR__ . '/../modules/erp/kontakte/service.php';
|
|
require_once __DIR__ . '/../modules/erp/artikel-mapping/service.php';
|
|
require_once __DIR__ . '/../modules/market_management/service.php';
|
|
|
|
$env = expand_env_values(parse_env_file(__DIR__ . '/../.env'));
|
|
$pdo = connect_database($env);
|
|
auth_bootstrap_session();
|
|
auth_ensure_schema($pdo);
|
|
|
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
|
|
$csrfToken = (string) ($_POST['csrf_token'] ?? '');
|
|
if (!auth_validate_csrf_token($csrfToken)) {
|
|
render_auth_login_page([
|
|
'identifier_value' => (string) ($_POST['identifier'] ?? ''),
|
|
'errors' => [
|
|
'identifier' => 'Ungültiges Sicherheits-Token. Bitte Seite neu laden.',
|
|
'password' => null,
|
|
],
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
$loginResult = auth_login(
|
|
$pdo,
|
|
(string) ($_POST['identifier'] ?? ''),
|
|
(string) ($_POST['password'] ?? '')
|
|
);
|
|
|
|
if (($loginResult['ok'] ?? false) === true) {
|
|
header('Location: ' . auth_take_return_to());
|
|
exit;
|
|
}
|
|
|
|
render_auth_login_page([
|
|
'identifier_value' => (string) ($_POST['identifier'] ?? ''),
|
|
'errors' => $loginResult['errors'] ?? [],
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
$currentUser = auth_current_user($pdo);
|
|
if ($currentUser !== null) {
|
|
$otcProducts = get_otc_order_form_products($pdo);
|
|
$otcMarketOptions = market_management_list_active_occurrence_options($pdo);
|
|
$lagerProducts = get_lager_product_overview($pdo);
|
|
$lagerManufacturers = get_manufacturer_options($pdo);
|
|
$lagerArtikel = get_lager_artikel_overview($pdo);
|
|
$bestellungenTable = get_sales_order_overview($pdo, [
|
|
'search' => (string) ($_GET['bestellungen_search'] ?? ''),
|
|
'sort_column' => (string) ($_GET['bestellungen_sort'] ?? 'order_date'),
|
|
'sort_direction' => (string) ($_GET['bestellungen_dir'] ?? 'DESC'),
|
|
'limit' => (int) ($_GET['bestellungen_limit'] ?? 20),
|
|
'page_size' => 20,
|
|
]);
|
|
$marketSearch = (string) ($_GET['market_search'] ?? '');
|
|
$marketSort = (string) ($_GET['market_sort'] ?? 'earliest_date');
|
|
$marketDirection = strtoupper((string) ($_GET['market_dir'] ?? 'ASC'));
|
|
$marketLimit = min(100, max(1, (int) ($_GET['market_limit'] ?? 20)));
|
|
$marketOccurrencesTable = [
|
|
'rows' => market_management_search_occurrences($pdo, [
|
|
'search' => $marketSearch,
|
|
'sort' => $marketSort,
|
|
'sort_direction' => $marketDirection,
|
|
'limit' => $marketLimit,
|
|
'offset' => 0,
|
|
]),
|
|
'search' => $marketSearch,
|
|
'sort_column' => $marketSort,
|
|
'sort_direction' => $marketDirection,
|
|
'limit' => $marketLimit,
|
|
'page_size' => 20,
|
|
];
|
|
$marketOccurrencesTable['has_more'] = count($marketOccurrencesTable['rows']) >= $marketLimit;
|
|
$marketDefinitionsTable = [
|
|
'rows' => market_management_search_markets($pdo, [
|
|
'include_archived' => true,
|
|
'sort' => 'name',
|
|
'sort_direction' => 'ASC',
|
|
'limit' => 100,
|
|
'offset' => 0,
|
|
]),
|
|
'categories' => market_management_list_categories($pdo),
|
|
'organizers' => get_market_organizer_options($pdo),
|
|
];
|
|
if ((string) ($_GET['bestellungen_fragment'] ?? '') === '1') {
|
|
echo auth_render_bestellungen_content($bestellungenTable);
|
|
exit;
|
|
}
|
|
if ((string) ($_GET['market_fragment'] ?? '') === '1') {
|
|
echo auth_render_markets_content($marketOccurrencesTable);
|
|
exit;
|
|
}
|
|
render_auth_home_page($currentUser, $otcProducts, $otcMarketOptions, $bestellungenTable, $marketOccurrencesTable, $lagerProducts, $lagerArtikel, $lagerManufacturers, $marketDefinitionsTable);
|
|
exit;
|
|
}
|
|
|
|
render_auth_login_page([
|
|
'identifier_value' => '',
|
|
'errors' => [
|
|
'identifier' => null,
|
|
'password' => null,
|
|
],
|
|
]);
|