/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/ExamplesController.php

  • Committer: b11johgu
  • Date: 2013-05-03 11:39:08 UTC
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: b11johgu@student.his.se-20130503113908-m8nilvexb8atwtvz
Added controllers for examplepage, templatelayout.
Updated models for login and database interaction.
Added ajax controller.
... A lot of stuff has changed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
class ExamplesController extends CI_Controller {
4
4
 
5
 
        /**
6
 
         * Index Page for this controller.
7
 
         *
8
 
         * Maps to the following URL
9
 
         *              http://example.com/index.php/welcome
10
 
         *      - or -  
11
 
         *              http://example.com/index.php/welcome/index
12
 
         *      - or -
13
 
         * Since this controller is set as the default controller in 
14
 
         * config/routes.php, it's displayed at http://example.com/
15
 
         *
16
 
         * So any other public methods not prefixed with an underscore will
17
 
         * map to /index.php/welcome/<method_name>
18
 
         * @see http://codeigniter.com/user_guide/general/urls.html
19
 
         */
20
5
        public function index()
21
6
        {
22
7
                /* headData manages the <head>-tag and loads corresponding CSS.
23
8
                 * The views that are entered will load CSS with same name.
24
9
                 * Ex. test_header will load test_header.css
25
10
                 */
26
 
                $headData['list'] = array('header', 'examplesMenu', 'examplesBody');
 
11
                $this->load->library('session');
 
12
                $headData['list'] = array('headTag', 'header', 'examplesMenu', 'examplesBody');
 
13
                $this->load->view('headTag', $headData);
 
14
                
 
15
                $this->load->helper('form');
 
16
                
 
17
                // Loading model to retrieve login data
 
18
                $this->load->model('user');
 
19
                $userInfo = array(
 
20
                        'userType' => $this->user->getUserType(),
 
21
                        'userName' => $this->user->getUserName()
 
22
                );
 
23
                
 
24
                $this->load->view('header', $userInfo);
 
25
                        
 
26
                /* Loads used models */
 
27
                $this->load->model('ExamplesModel');
 
28
                
 
29
                // menuData loads items to the menu.
 
30
                $allTitles = array();
 
31
                
 
32
                /* Loads categorydata into array */
 
33
                $query = $this->ExamplesModel->getTitles($userInfo['userName']);
 
34
                foreach ($query as $row)
 
35
                {
 
36
                        // Category
 
37
                        $query2 = $this->ExamplesModel->getBody($row->categoryName);
 
38
                        $allTitles[$row->categoryName] = array();
 
39
                        foreach ($query2 as $row2)
 
40
                        {
 
41
                                // Subcategory
 
42
                                $query3 = $this->ExamplesModel->getExamples($row2->subCategoryName);
 
43
                                $allTitles[$row->categoryName][$row2->subCategoryName] = array();
 
44
                                foreach ($query3 as $row3)
 
45
                                {
 
46
                                        //Examples
 
47
                                        $allTitles[$row->categoryName][$row2->subCategoryName][] = $row3->exampleName;
 
48
                                }
 
49
 
 
50
                        }
 
51
                }
 
52
                /* Menu for examples page showing categories */
 
53
                $this->load->view('examplesMenu', array('titles' => $allTitles));
 
54
                
 
55
                /* Loads body for examples page */
 
56
                $this->load->view('examplesBody', array('titles' => $allTitles));       
 
57
 
 
58
        }
 
59
        
 
60
        public function validate() {
 
61
                //Load required library
 
62
                $this->load->library('form_validation');
 
63
                
 
64
                //Sets validation rules
 
65
                $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
 
66
                $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
 
67
                
 
68
                //Run validation
 
69
                if($this->form_validation->run() == FALSE) {
 
70
                        //Field validation failed. Display login form (with error message).
 
71
                        $this->drawLoginForm(validation_errors());
 
72
                } else {
 
73
                        $username = $this->input->post('username');
 
74
                        $password = $this->input->post('password');
 
75
                        
 
76
                        //Try to login
 
77
                        if ($this->user->login($username, $password)) {
 
78
                                redirect(base_url().'home', 'refresh');
 
79
                        } else {
 
80
                                $this->drawLoginForm('Access denied!');
 
81
                        }
 
82
                }
 
83
        }
 
84
        
 
85
        
 
86
        /*
 
87
         *      This function draws the login form.
 
88
         */
 
89
        private function drawLoginForm($errors) {
 
90
                //Load required library
 
91
                $this->load->helper(array('form'));
 
92
                
 
93
                //Display the view
 
94
                $data['error'] = $errors;
 
95
                $headData['list'] = array('headTag', 'header', 'login_view');
27
96
                $this->load->view('headTag', $headData);
28
97
                $this->load->view('header');
29
 
                
30
 
                // menuData loads items to the menu.
31
 
                $menuData['list'] = array('Quizzes', 'JavaScript', 'jQuery', 'AJAX API', 'SQL', 'PHP', 'Rollekunskap');
32
 
                $this->load->view('examplesMenu', $menuData);
33
 
                
34
 
                // examples matrix loads headers and example titles to the body.
35
 
                $examples['titles'] = Array(
36
 
                        'JavaScript' => Array('Example0', 'Example1', 'Example2'),
37
 
                        'jQuery' => Array('Example0', 'ruben', 'Example2'),
38
 
                        'AJAX API' => Array('Example0', 'Example1', 'Example2'),
39
 
                        'SQL' => Array('Example0', 'Example1', 'Example2'),
40
 
                        'PHP' => Array('Example0', 'Example1', 'Example2'),
41
 
                        'Rollekunskap' => Array('Rolle', 'is', 'awsome', 'because', 'he', 'can', 'fix', 'stuffs')
42
 
                );
43
 
                $this->load->view('examplesBody', $examples);   
 
98
                $this->load->view('login_view', $data);
44
99
        }
 
100
        
45
101
}
46
102
 
47
 
/* End of file welcome.php */
48
 
/* Location: ./application/controllers/welcome.php */
 
 
b'\\ No newline at end of file'
 
103
/* End of file ExamplesController.php */
 
104
/* Location: ./application/controllers/ExamplesController.php */
 
 
b'\\ No newline at end of file'