forked from bagvendt/vaip
/
Models.php
51 lines (38 loc) · 1.37 KB
/
Models.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
<?php
class Models {
private $dbhost, $dbuser, $dbpswd, $dbname, $user;
function __construct($dbhost, $dbuser, $dbpswd, $dbname) {
// assert that the resources we need are there
if(!defined('MODELS'))
die();
// Model-specs
require_once MODELS. '/UserFactory.php';
require_once MODELS. '/EmployeeFactory.php';
/*
require_once 'Shifts.php';
require_once 'Schemas.php';
*/
// Database
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpswd = $dbpswd;
$this->dbname = $dbname;
mysql_connect($this->dbhost, $this->dbuser, $this->dbpswd, $this->dbname);
mysql_select_db($this->dbname);
// User
$this->user = null;
if(isset($_SESSION['user_id'])) {
$this->user = UserFactory::create($_SESSION['user_id']);
} elseif(isset($_COOKIE['user_id']) && isset($_COOKIE['email']) && isset($_COOKIE['password'])) {
$user = UserFactory::create($_COOKIE['user_id']);
if($user->getEmail() == $_COOKIE['email'] && $user->getPassword() == $_COOKIE['password']) {
$_SESSION['user_id'] = $user->getUserId();
$this->user = $user;
}
}
}
function getUser() {
return $this->user;
}
}
?>