summaryrefslogtreecommitdiffstats
path: root/management-interface/api/models/Master.php
blob: 4ee2943a23bc0a10fe6d08aa643d09fc90467105 (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
<?php

class Master {

	public $view;

	public function __construct() {
		$this->view = new View;
	}

	public function parse($f3, $params) {
                $f3->set('_title', $f3->get('title'));

                // set view if item exists
                if (in_array($params['m'], $f3->get('item'))) {
                        if (!file_exists('views/' . $params['m'] . '.htm')) {
                                // if file does not exists, create a template
                                copy('views/template.htm', 'views/' . $params['m'] . '.htm');
                        }
                        $f3->set('_module', $params['m']);
                } elseif ($params['m'] === 'login') {
			$f3->set('_module', 'login');	
		} else {
                        $f3->set('_module', 'home');
                }
                
                echo $this->view->render('template/header.php');

                echo $this->view->render('views/menu.php');

		if (!empty($f3->get('message'))) {
			echo $this->view->render('template/message.php');
		}
		
                echo Template::instance()->render('views/' . $f3->get('_module') . '.htm');

                echo $this->view->render('template/footer.php');

	}

	public function dologin($f3, $username, $password) {
		if (isset($f3->get('user')[$username]) && $f3->get('user')[$username] == sha1($password)) {
			$_SESSION['username'] = $username;
			$f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false);
			$f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest');
			$this->parse($f3, array('m' => 'home'));
		} else {
			$f3->set('message', 'Login invalid.');
			$this->parse($f3, array('m' => 'login'));
		}
	}

	public function dologout($f3) {
		$_SESSION = array();
		$f3->set('message', 'Logout successful');
		$f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false);
		$f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest');
		$this->parse($f3, array('m' => 'login'));
	}

}

?>