-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.php
75 lines (59 loc) · 1.5 KB
/
core.php
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
<?php
/* Code and Design created and managed by Dario Magliocchetti & Thomas Lim
* Do not replicate, use or host any part of this code without prior permission.
*
* Project for GTA feedback within the department. To be used by EE1 and EE2.
*
* File: core.php
* Use:
* Initialises classes, databases and session. Handles login and logout.
*
*/
session_save_path(__DIR__.'/sess');
session_start();
require_once 'db.php';
include('class/user.class.php');
include('class/feedback.class.php');
require_once 'Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array() );
//session:user saves the username
//we then create the user class from that username
if(currentpage != 'admin')
{
if(time()>1367621999) //This automatically closes the survey if beyond the finishing time, unless it's the admin page.
{
echo $twig->render('closed');
exit();
}
}
if (@$_GET['do'] == 'logout')
{
session_destroy();
header('Location: ' . $_SERVER['SCRIPT_NAME']);
}
if (!@$_SESSION['user'])
{
if (!empty($_POST))
{
//check login.
$user = new user($db);
if ($user->login($_POST['username'], $_POST['password']) === true)
{
header('Location: index.php');
$_SESSION['user'] = $_POST['username'];
//header();
}
else
{
$error = $user->login_error;
}
}
echo $twig->render('web_login', array(
'title' => 'EE GTA Feedback',
'error' => @$error
));
exit();
}
$user = new user($db, $_SESSION['user']);