/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: Gustav Hatvigsson
  • Date: 2013-05-21 12:01:01 UTC
  • mfrom: (82.1.1 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130521120101-ch0ps106uaovyh5u
merged the missing things...

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 ExamplesController extends CI_Controller {
 
4
 
 
5
        public function index()
 
6
        {
 
7
                /* headData manages the <head>-tag and loads corresponding CSS.
 
8
                 * The views that are entered will load CSS with same name.
 
9
                 * Ex. test_header will load test_header.css
 
10
                 */
 
11
                $this->load->library('session');
 
12
                $headTagData = array(
 
13
                        'cssFiles' => array('header', 'examplesMenu', 'examplesBody'),
 
14
                        'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls')
 
15
                );
 
16
                $this->load->view('headTag', array('headTagData' => $headTagData));
 
17
                
 
18
                $this->load->helper('form');
 
19
                
 
20
                // Loading model to retrieve login data
 
21
                $this->load->model('user');
 
22
                $userInfo = array(
 
23
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
 
24
                        'userName' => $this->user->getUserName()
 
25
                );
 
26
                
 
27
                $this->load->view('header', $userInfo);
 
28
                        
 
29
                /* Loads used models */
 
30
                $this->load->model('ExamplesModel');
 
31
                
 
32
                // menuData loads items to the menu.
 
33
                $allTitles = array();
 
34
                
 
35
                /* Loads categorydata into array */
 
36
                $query = $this->ExamplesModel->getTitles($userInfo['userName']);
 
37
                foreach ($query as $category)
 
38
                {
 
39
                        // Category
 
40
                        $query2 = $this->ExamplesModel->getBody($category->categoryName);
 
41
                        $allTitles[$category->categoryName.",".$category->courseID] = array();
 
42
                //      $allTitles[$category->categoryName] = array();
 
43
                //      $allTitles[$category->courseID] = array();
 
44
                                                foreach ($query2 as $subCategory)
 
45
                        {
 
46
                                // Subcategory
 
47
                                $query3 = $this->ExamplesModel->getExamples($subCategory->subCategoryName);
 
48
                                $allTitles[$category->categoryName][$subCategory->subCategoryName] = array();
 
49
                                foreach ($query3 as $examples)
 
50
                                {
 
51
                                        //Examples
 
52
                                        $allTitles[$category->categoryName][$subCategory->subCategoryName][] = $examples->exampleName;
 
53
                                }
 
54
 
 
55
                        }
 
56
                }
 
57
                /* Menu for examples page showing categories */
 
58
                $this->load->view('examplesMenu', array('titles' => $allTitles));
 
59
                
 
60
                /* Loads body for examples page */
 
61
                $this->load->view('examplesBody', array('titles' => $allTitles));       
 
62
 
 
63
        }
 
64
        
 
65
        public function validate() {
 
66
                //Load required library
 
67
                $this->load->library('form_validation');
 
68
                
 
69
                //Sets validation rules
 
70
                $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
 
71
                $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
 
72
                
 
73
                //Run validation
 
74
                if($this->form_validation->run() == FALSE) {
 
75
                        //Field validation failed. Display login form (with error message).
 
76
                        $this->drawLoginForm(validation_errors());
 
77
                } else {
 
78
                        $username = $this->input->post('username');
 
79
                        $password = $this->input->post('password');
 
80
                        
 
81
                        //Try to login
 
82
                        if ($this->user->login($username, $password)) {
 
83
                                redirect(base_url().'home', 'refresh');
 
84
                        } else {
 
85
                                $this->drawLoginForm('Access denied!');
 
86
                        }
 
87
                }
 
88
        }
 
89
        
 
90
}
 
91
 
 
92
/* End of file ExamplesController.php */
 
93
/* Location: ./application/controllers/ExamplesController.php */
 
 
b'\\ No newline at end of file'