2015-05-14 16:37:12 +02:00
|
|
|
<?php
|
2017-01-20 21:12:19 +01:00
|
|
|
|
2017-09-19 14:50:20 +02:00
|
|
|
use Engelsystem\Application;
|
2017-01-21 23:07:20 +01:00
|
|
|
use Engelsystem\Config\Config;
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\Db;
|
2017-01-20 21:12:19 +01:00
|
|
|
use Engelsystem\Exceptions\Handler as ExceptionHandler;
|
2017-07-18 21:38:53 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2017-09-19 18:30:42 +02:00
|
|
|
use Engelsystem\Logger\EngelsystemLogger;
|
2017-07-20 02:22:18 +02:00
|
|
|
use Engelsystem\Renderer\HtmlEngine;
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
2017-09-20 01:09:11 +02:00
|
|
|
use Engelsystem\Routing\UrlGenerator;
|
2017-09-19 18:30:42 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2017-08-30 19:57:01 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
2017-09-19 18:30:42 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
2017-09-20 11:07:25 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
2017-01-20 21:12:19 +01:00
|
|
|
|
2015-05-14 16:37:12 +02:00
|
|
|
/**
|
|
|
|
* This file includes all needed functions, connects to the db etc.
|
|
|
|
*/
|
2017-08-28 16:21:10 +02:00
|
|
|
require_once __DIR__ . '/autoload.php';
|
2017-01-21 23:07:20 +01:00
|
|
|
|
2017-08-31 17:30:54 +02:00
|
|
|
|
|
|
|
/**
|
2017-09-19 14:50:20 +02:00
|
|
|
* Initialize the application
|
2017-08-31 17:30:54 +02:00
|
|
|
*/
|
2017-09-21 20:52:19 +02:00
|
|
|
$app = new Application(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..'));
|
2017-08-31 17:30:54 +02:00
|
|
|
|
|
|
|
|
2017-09-22 14:02:02 +02:00
|
|
|
/**
|
|
|
|
* Bootstrap application
|
|
|
|
*/
|
|
|
|
$appConfig = $app->make(Config::class);
|
|
|
|
$appConfig->set(app('path.config') . '/app.php');
|
|
|
|
$app->bootstrap($appConfig);
|
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
/**
|
|
|
|
* Load configuration
|
|
|
|
*/
|
|
|
|
$config = new Config();
|
2017-09-19 14:50:20 +02:00
|
|
|
$app->instance('config', $config);
|
2017-01-21 23:07:20 +01:00
|
|
|
$config->set(require __DIR__ . '/../config/config.default.php');
|
|
|
|
|
|
|
|
if (file_exists(__DIR__ . '/../config/config.php')) {
|
|
|
|
$config->set(array_replace_recursive(
|
|
|
|
$config->get(null),
|
|
|
|
require __DIR__ . '/../config/config.php'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-09-22 14:02:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure application
|
|
|
|
*/
|
2017-01-21 23:07:20 +01:00
|
|
|
date_default_timezone_set($config->get('timezone'));
|
|
|
|
|
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
/**
|
|
|
|
* Initialize Request
|
2017-08-29 16:21:25 +02:00
|
|
|
*
|
|
|
|
* @var Request $request
|
2017-07-18 21:38:53 +02:00
|
|
|
*/
|
2017-08-29 16:21:25 +02:00
|
|
|
$request = Request::createFromGlobals();
|
2017-09-19 14:50:20 +02:00
|
|
|
$app->instance('request', $request);
|
2017-08-31 17:30:54 +02:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
/**
|
|
|
|
* Check for maintenance
|
|
|
|
*/
|
2017-09-22 14:02:02 +02:00
|
|
|
if ($app->get('config')->get('maintenance')) {
|
2017-07-20 02:22:18 +02:00
|
|
|
echo file_get_contents(__DIR__ . '/../templates/maintenance.html');
|
2017-01-21 23:07:20 +01:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 01:09:11 +02:00
|
|
|
/**
|
|
|
|
* Register UrlGenerator
|
|
|
|
*/
|
|
|
|
$urlGenerator = new UrlGenerator();
|
|
|
|
$app->instance('routing.urlGenerator', $urlGenerator);
|
|
|
|
|
|
|
|
|
2017-07-20 02:22:18 +02:00
|
|
|
/**
|
|
|
|
* Initialize renderer
|
|
|
|
*/
|
|
|
|
$renderer = new Renderer();
|
2017-09-19 14:50:20 +02:00
|
|
|
$app->instance('renderer', $renderer);
|
2017-07-20 02:22:18 +02:00
|
|
|
$renderer->addRenderer(new HtmlEngine());
|
|
|
|
|
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
/**
|
|
|
|
* Register error handler
|
|
|
|
*/
|
|
|
|
$errorHandler = new ExceptionHandler();
|
2017-09-19 14:50:20 +02:00
|
|
|
$app->instance('error.handler', $errorHandler);
|
2017-01-21 23:07:20 +01:00
|
|
|
if (config('environment') == 'development') {
|
|
|
|
$errorHandler->setEnvironment(ExceptionHandler::ENV_DEVELOPMENT);
|
|
|
|
ini_set('display_errors', true);
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
} else {
|
|
|
|
ini_set('display_errors', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect to database
|
|
|
|
*/
|
|
|
|
Db::connect(
|
|
|
|
'mysql:host=' . config('database')['host'] . ';dbname=' . config('database')['db'] . ';charset=utf8',
|
|
|
|
config('database')['user'],
|
|
|
|
config('database')['pw']
|
|
|
|
) || die('Error: Unable to connect to database');
|
|
|
|
Db::getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
2017-03-02 12:48:48 +01:00
|
|
|
Db::getPdo()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
2017-01-21 23:07:20 +01:00
|
|
|
|
2017-09-19 18:30:42 +02:00
|
|
|
/**
|
|
|
|
* Init logger
|
|
|
|
*/
|
|
|
|
$logger = new EngelsystemLogger();
|
|
|
|
$app->instance('logger', $logger);
|
2017-09-21 18:37:37 +02:00
|
|
|
$app->bind(LoggerInterface::class, 'logger');
|
|
|
|
$app->bind(EngelsystemLogger::class, 'logger');
|
2017-09-19 18:30:42 +02:00
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include legacy code
|
|
|
|
*/
|
2017-08-29 22:39:35 +02:00
|
|
|
$includeFiles = [
|
|
|
|
__DIR__ . '/../includes/sys_auth.php',
|
|
|
|
__DIR__ . '/../includes/sys_form.php',
|
|
|
|
__DIR__ . '/../includes/sys_log.php',
|
|
|
|
__DIR__ . '/../includes/sys_menu.php',
|
|
|
|
__DIR__ . '/../includes/sys_page.php',
|
|
|
|
__DIR__ . '/../includes/sys_template.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/model/AngelType_model.php',
|
|
|
|
__DIR__ . '/../includes/model/EventConfig_model.php',
|
|
|
|
__DIR__ . '/../includes/model/LogEntries_model.php',
|
|
|
|
__DIR__ . '/../includes/model/Message_model.php',
|
|
|
|
__DIR__ . '/../includes/model/NeededAngelTypes_model.php',
|
|
|
|
__DIR__ . '/../includes/model/Room_model.php',
|
|
|
|
__DIR__ . '/../includes/model/ShiftEntry_model.php',
|
|
|
|
__DIR__ . '/../includes/model/Shifts_model.php',
|
|
|
|
__DIR__ . '/../includes/model/ShiftsFilter.php',
|
|
|
|
__DIR__ . '/../includes/model/ShiftSignupState.php',
|
|
|
|
__DIR__ . '/../includes/model/ShiftTypes_model.php',
|
|
|
|
__DIR__ . '/../includes/model/UserAngelTypes_model.php',
|
|
|
|
__DIR__ . '/../includes/model/UserDriverLicenses_model.php',
|
|
|
|
__DIR__ . '/../includes/model/UserGroups_model.php',
|
|
|
|
__DIR__ . '/../includes/model/User_model.php',
|
|
|
|
__DIR__ . '/../includes/model/ValidationResult.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/view/AngelTypes_view.php',
|
|
|
|
__DIR__ . '/../includes/view/EventConfig_view.php',
|
|
|
|
__DIR__ . '/../includes/view/Questions_view.php',
|
|
|
|
__DIR__ . '/../includes/view/Rooms_view.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftCalendarLane.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftCalendarRenderer.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftsFilterRenderer.php',
|
|
|
|
__DIR__ . '/../includes/view/Shifts_view.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftEntry_view.php',
|
|
|
|
__DIR__ . '/../includes/view/ShiftTypes_view.php',
|
|
|
|
__DIR__ . '/../includes/view/UserAngelTypes_view.php',
|
|
|
|
__DIR__ . '/../includes/view/UserDriverLicenses_view.php',
|
|
|
|
__DIR__ . '/../includes/view/UserHintsRenderer.php',
|
|
|
|
__DIR__ . '/../includes/view/User_view.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/controller/angeltypes_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/event_config_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/rooms_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/shift_entries_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/shifts_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/shifttypes_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/users_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/user_angeltypes_controller.php',
|
|
|
|
__DIR__ . '/../includes/controller/user_driver_licenses_controller.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/helper/graph_helper.php',
|
|
|
|
__DIR__ . '/../includes/helper/internationalization_helper.php',
|
|
|
|
__DIR__ . '/../includes/helper/message_helper.php',
|
|
|
|
__DIR__ . '/../includes/helper/error_helper.php',
|
|
|
|
__DIR__ . '/../includes/helper/email_helper.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/mailer/shifts_mailer.php',
|
|
|
|
__DIR__ . '/../includes/mailer/users_mailer.php',
|
|
|
|
|
|
|
|
__DIR__ . '/../includes/pages/admin_active.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_arrive.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_free.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_groups.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_import.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_log.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_questions.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_rooms.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_shifts.php',
|
|
|
|
__DIR__ . '/../includes/pages/admin_user.php',
|
|
|
|
__DIR__ . '/../includes/pages/guest_login.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_messages.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_myshifts.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_news.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_questions.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_settings.php',
|
|
|
|
__DIR__ . '/../includes/pages/user_shifts.php',
|
|
|
|
];
|
|
|
|
foreach ($includeFiles as $file) {
|
|
|
|
require_once realpath($file);
|
|
|
|
}
|
2015-05-14 16:37:12 +02:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
/**
|
|
|
|
* Init application
|
|
|
|
*/
|
2017-09-20 11:07:25 +02:00
|
|
|
$sessionStorage = (PHP_SAPI != 'cli' ? new NativeSessionStorage(['cookie_httponly' => true]) : new MockArraySessionStorage());
|
|
|
|
$session = new Session($sessionStorage);
|
2017-09-19 14:50:20 +02:00
|
|
|
$app->instance('session', $session);
|
2017-08-30 19:57:01 +02:00
|
|
|
$session->start();
|
|
|
|
$request->setSession($session);
|
2015-06-07 13:33:59 +02:00
|
|
|
|
2015-05-14 16:37:12 +02:00
|
|
|
gettext_init();
|
|
|
|
|
|
|
|
load_auth();
|