1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
3
class ExamplesController extends CI_Controller {
5
public function index()
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
11
$this->load->library('session');
12
$headData['list'] = array('headTag', 'header', 'examplesMenu', 'examplesBody');
13
$this->load->view('headTag', $headData);
15
$this->load->helper('form');
17
// Loading model to retrieve login data
18
$this->load->model('user');
20
'userType' => $this->user->getUserType(),
21
'userName' => $this->user->getUserName()
24
$this->load->view('header', $userInfo);
26
/* Loads used models */
27
$this->load->model('ExamplesModel');
29
// menuData loads items to the menu.
32
/* Loads categorydata into array */
33
$query = $this->ExamplesModel->getTitles($userInfo['userName']);
34
foreach ($query as $row)
37
$query2 = $this->ExamplesModel->getBody($row->categoryName);
38
$allTitles[$row->categoryName] = array();
39
foreach ($query2 as $row2)
42
$query3 = $this->ExamplesModel->getExamples($row2->subCategoryName);
43
$allTitles[$row->categoryName][$row2->subCategoryName] = array();
44
foreach ($query3 as $row3)
47
$allTitles[$row->categoryName][$row2->subCategoryName][] = $row3->exampleName;
52
/* Menu for examples page showing categories */
53
$this->load->view('examplesMenu', array('titles' => $allTitles));
55
/* Loads body for examples page */
56
$this->load->view('examplesBody', array('titles' => $allTitles));
60
public function validate() {
61
//Load required library
62
$this->load->library('form_validation');
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');
69
if($this->form_validation->run() == FALSE) {
70
//Field validation failed. Display login form (with error message).
71
$this->drawLoginForm(validation_errors());
73
$username = $this->input->post('username');
74
$password = $this->input->post('password');
77
if ($this->user->login($username, $password)) {
78
redirect(base_url().'home', 'refresh');
80
$this->drawLoginForm('Access denied!');
87
* This function draws the login form.
89
private function drawLoginForm($errors) {
90
//Load required library
91
$this->load->helper(array('form'));
94
$data['error'] = $errors;
95
$headData['list'] = array('headTag', 'header', 'login_view');
96
$this->load->view('headTag', $headData);
97
$this->load->view('header');
98
$this->load->view('login_view', $data);
103
/* End of file ExamplesController.php */
104
/* Location: ./application/controllers/ExamplesController.php */
b'\\ No newline at end of file'