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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ExamplesController extends CI_Controller {
public function index()
{
/* headData manages the <head>-tag and loads corresponding CSS.
* The views that are entered will load CSS with same name.
* Ex. test_header will load test_header.css
*/
$this->load->library('session');
$headTagData = array(
'cssFiles' => array('header', 'examplesMenu', 'examplesBody'),
'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls')
);
$this->load->view('headTag', array('headTagData' => $headTagData));
$this->load->helper('form');
// Loading model to retrieve login data
$this->load->model('user');
$userInfo = array(
'userType' => $this->user->getUserType(), // Loads different header for teacher/student
'userName' => $this->user->getUserName()
);
$this->load->view('header', $userInfo);
/* Loads used models */
$this->load->model('ExamplesModel');
// menuData loads items to the menu.
$allTitles = array();
/* Loads categorydata into array */
$query = $this->ExamplesModel->getTitles($userInfo['userName']);
foreach ($query as $category)
{
// Category
$query2 = $this->ExamplesModel->getBody($category->categoryName);
$allTitles[$category->categoryName.",".$category->courseID] = array();
// $allTitles[$category->categoryName] = array();
// $allTitles[$category->courseID] = array();
foreach ($query2 as $subCategory)
{
// Subcategory
$query3 = $this->ExamplesModel->getExamples($subCategory->subCategoryName);
$allTitles[$category->categoryName][$subCategory->subCategoryName] = array();
foreach ($query3 as $examples)
{
//Examples
$allTitles[$category->categoryName][$subCategory->subCategoryName][] = $examples->exampleName;
}
}
}
/* Menu for examples page showing categories */
$this->load->view('examplesMenu', array('titles' => $allTitles));
/* Loads body for examples page */
$this->load->view('examplesBody', array('titles' => $allTitles));
}
public function validate() {
//Load required library
$this->load->library('form_validation');
//Sets validation rules
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
//Run validation
if($this->form_validation->run() == FALSE) {
//Field validation failed. Display login form (with error message).
$this->drawLoginForm(validation_errors());
} else {
$username = $this->input->post('username');
$password = $this->input->post('password');
//Try to login
if ($this->user->login($username, $password)) {
redirect(base_url().'home', 'refresh');
} else {
$this->drawLoginForm('Access denied!');
}
}
}
}
/* End of file ExamplesController.php */
/* Location: ./application/controllers/ExamplesController.php */
|