aboutsummaryrefslogtreecommitdiff
path: root/index.php
blob: 238b72e0a57f9384de8e5def1c1796f5c263ba3d (plain) (blame)
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
<?php
/**
 * Landing page
 * 
 * This handles basically all requests. Every request not to an existing file path, should be redirected here.
 * This file checks basic configuration and includes the required page, based on the REQUEST_URI.
 * 
 * @author Camil Staps
 *
 * BusinessAdmin: administrative software for small companies
 * Copyright (C) 2015 Camil Staps (ViviSoft)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** 
 * Load the basic configuration (sessions, database, class autoloading, etc.) 
 */
require_once('./conf.php');

// Fetch information from the REQUEST_URI.
$_request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$_request = str_replace(constants::url_internal, '', $_request);

// This is the REQUEST_URI switch
// The default shows a 404 page
$pages = array(
  '' => './include/home.php',
  '/clients' => './include/clients.php',
  '/clients/new' => './include/clients-new.php',
  '/clients/edit' => './include/clients-edit.php',
  '/contacts' => './include/contacts.php',
  '/contacts/new' => './include/contacts-new.php',
  '/contacts/edit' => './include/contacts-edit.php',
  '/offers' => './include/offers.php',
  '/offers/new' => './include/offers-new.php',
  '/offers/edit' => './include/offers-edit.php',
  '/assignments' => './include/assignments.php',
  '/assignments/new' => './include/assignments-new.php',
  '/assignments/edit' => './include/assignments-edit.php',
  '/about' => './include/about.php'
);
$_page = null;
foreach ($pages as $uri => $path) {
  if ($_request == $uri && file_exists($path)) {
    $_page = $uri;
    require($path);
    break;
  }
}
if ($_page === null) {
  $_page = '/404';
  http_response_code(404);
  require('./include/404.php');
}