summaryrefslogtreecommitdiff
path: root/includes/engelsystem_provider.php
blob: aed331d40ca1709d80698ae6955e6594c4d11b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php

use Engelsystem\Config\Config;
use Engelsystem\Database\Db;
use Engelsystem\Exceptions\Handler as ExceptionHandler;
use Engelsystem\Http\Request;
use Engelsystem\Renderer\HtmlEngine;
use Engelsystem\Renderer\Renderer;
use Symfony\Component\HttpFoundation\Session\Session;

/**
 * This file includes all needed functions, connects to the db etc.
 */

require_once __DIR__ . '/autoload.php';

/**
 * Load configuration
 */
$config = new Config();
Config::setInstance($config);
$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'
    ));
}

date_default_timezone_set($config->get('timezone'));


/**
 * Initialize Request
 *
 * @var Request $request
 */
$request = Request::createFromGlobals();
$request::setInstance($request);

/**
 * Check for maintenance
 */
if ($config->get('maintenance')) {
    echo file_get_contents(__DIR__ . '/../templates/maintenance.html');
    die();
}


/**
 * Initialize renderer
 */
$renderer = new Renderer();
$renderer->addRenderer(new HtmlEngine());
Renderer::setInstance($renderer);


/**
 * Register error handler
 */
$errorHandler = new ExceptionHandler();
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);
Db::getPdo()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);


/**
 * Include legacy code
 */
$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);
}


/**
 * Init application
 */
$session = new Session();
$session->start();
$request->setSession($session);

gettext_init();

load_auth();