/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/controllers/start.php

  • Committer: Erik Wikström
  • Date: 2013-04-09 09:21:05 UTC
  • mto: (21.1.1 lenasys)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: wikxen@gmail.com-20130409092105-u1u3gxbql1vx65a7
Added missing WebGL javascript files, moved bothe them and the existing ones to /js. Updated references

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
 
3
 
        class Start extends CI_Controller {
4
 
        
5
 
                /*
6
 
                 *      Constructor
7
 
                 */
8
 
                function __construct() {
9
 
                        parent::__construct();
10
 
                        //Load required library
11
 
                        $this->load->model('user', '', TRUE);
12
 
                        $this->load->model('admin/admin_model', '', TRUE);
13
 
                }
14
 
        
15
 
                /*
16
 
                 *Temporary function to be able to be logged in to reach the page
17
 
                 */
18
 
                public function tempLogin() {
19
 
                        $this->load->model('user');
20
 
                        $loginDetails = array(
21
 
                        'username' => 'tempTeacher',
22
 
                        'name' => 'tempFoo',
23
 
                        'usertype' => 'Teacher',
24
 
                        'ssn' => '0000',
25
 
                        'activeCourse' => 'DA525G');
26
 
                        $this->session->set_userdata('authenticated', $loginDetails);
27
 
                        redirect(base_url().'start', 'refresh');
28
 
                }
29
 
                public function tempLogout() {
30
 
                        $this->load->model('user');
31
 
                        $this->session->unset_userdata('authenticated');
32
 
                        redirect(base_url().'home', 'refresh');
33
 
                }
34
 
        
35
 
                /*
36
 
                 *      This function runs when the user navigates directly to the start controller
37
 
                 */
38
 
                public function index() {
39
 
                        if($this->user->isLoggedIn()) {
40
 
                                //User already logged in
41
 
                                redirect(base_url().'cms', 'refresh');
42
 
                        } else {
43
 
                                //Display the start page
44
 
                                $this->drawStartPage('');
45
 
                        }
46
 
                }               
47
 
        
48
 
                /*
49
 
                 *      This function draws the start page.
50
 
                 */
51
 
                private function drawStartPage() {
52
 
                        $userName = $this->user->getUserName();
53
 
                        $userType = $this->user->getUserType();
54
 
                        //Creates an array with active course info.
55
 
                        $activeCourse = $this->user->getActiveCourse();
56
 
                        //Creates an array with all courses.
57
 
                        $courses = $this->admin_model->getCourses();
58
 
                        
59
 
                        
60
 
                        //Creates an array with the variables that the bannermenu-view is expecting.
61
 
                        $data = array(
62
 
                                'userType' => $userType,
63
 
                                'userName' => $userName,
64
 
                                'activeCourse' => $activeCourse,
65
 
                                'courses' => $courses
66
 
                        );
67
 
                        
68
 
                        //Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
69
 
                        $headTagData = array(
70
 
                                'cssFiles' => array('bannermenu', 'startview'),
71
 
                                'jsFiles' => array('bannermenu', 'login')
72
 
                        );
73
 
                        
74
 
                        //Puts the array above in <head></head>
75
 
                        $this->load->view('headTag', array('headTagData' => $headTagData));     
76
 
                        
77
 
                        $this->load->view('bannermenu', $data);
78
 
                        $this->load->view('startview', $data);
79
 
                }
80
 
 
81
 
                /* Login and logout functionality */
82
 
                public function login() {
83
 
                        $this->load->library('user_agent');
84
 
                        $this->load->library('form_validation');
85
 
 
86
 
                        //Sets validation rules
87
 
                        $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
88
 
                        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
89
 
                        
90
 
                        //Run validation
91
 
                        if($this->form_validation->run() == FALSE) {
92
 
                                //Field validation failed. Display login form (with error message).
93
 
                                echo validation_errors();
94
 
                        } else {
95
 
                                $username = $this->input->post('username');
96
 
                                $password = $this->input->post('password');
97
 
 
98
 
                                $this->load->model('user');
99
 
                                
100
 
                                //Try to login
101
 
                                if ($this->user->login($username, $password)) {
102
 
                                        // If the login is successful, Redirects user to the page it came from
103
 
                                        redirect($_SERVER['HTTP_REFERER']);
104
 
                                } else {
105
 
                                        echo "Wrong username or password";
106
 
                                }
107
 
                        }
108
 
                }
109
 
 
110
 
                public function logout() {
111
 
                        $this->load->model('user');
112
 
                        if($this->user->isLoggedIn()) {
113
 
                                $this->session->unset_userdata('authenticated');
114
 
                                redirect($_SERVER['HTTP_REFERER']);
115
 
                        } else {
116
 
                                echo "You're not logged in!";
117
 
                        }
118
 
                }
119
 
        }
120
 
?>