bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
78.1.1
by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it |
1 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
2 |
||
3 |
class ViewStudentsController extends CI_Controller { |
|
4 |
||
83.2.14
by elof.bigestans at gmail
* Started work on the viewStudents functionality... So far, displaying users works and it outputs correct and standardized html. |
5 |
public function index() { |
6 |
$this->load->model('user'); |
|
7 |
$this->load->model('admin/admin_model'); |
|
8 |
||
9 |
// NOTE: viewstudents is a deprecated model. Should eventually be replaced by a proper model
|
|
10 |
$this->load->model('viewstudents'); |
|
11 |
||
12 |
$userName = $this->user->getUserName(); |
|
13 |
$userType = $this->user->getUserType(); |
|
14 |
||
15 |
//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
|
|
16 |
$headTagData = array( |
|
17 |
'cssFiles' => array('bannermenu', 'sidemenu', 'dummieContent', 'viewStudents', 'body'),//cms tillfällig sida |
|
18 |
'jsFiles' => array('bannermenu', 'viewStudents') |
|
19 |
);
|
|
20 |
||
21 |
//Puts the array above in <head></head>
|
|
22 |
$this->load->view('headTag', array('headTagData' => $headTagData)); |
|
23 |
||
24 |
$students = $this->viewstudents->getStudents(); |
|
25 |
||
26 |
$this->load->view('viewStudentsBody', array('students' => $students)); |
|
27 |
}
|
|
28 |
||
29 |
public function index_old() |
|
78.1.1
by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it |
30 |
{
|
31 |
/* headData manages the <head>-tag and loads corresponding CSS.
|
|
32 |
* The views that are entered will load CSS with same name.
|
|
33 |
* Ex. test_header will load test_header.css
|
|
34 |
*/
|
|
35 |
$this->load->library('session'); |
|
36 |
$headTagData = array( |
|
37 |
'cssFiles' => array('header', 'examplesMenu', 'examplesBody'), |
|
38 |
'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls') |
|
39 |
);
|
|
40 |
$this->load->view('headTag', array('headTagData' => $headTagData)); |
|
41 |
||
42 |
$this->load->helper('form'); |
|
43 |
||
44 |
// Loading model to retrieve login data
|
|
45 |
$this->load->model('user'); |
|
46 |
$userInfo = array( |
|
47 |
'userType' => $this->user->getUserType(), // Loads different header for teacher/student |
|
48 |
'userName' => $this->user->getUserName() |
|
49 |
);
|
|
50 |
||
51 |
$this->load->view('header', $userInfo); |
|
52 |
||
53 |
/* Loads used models */
|
|
54 |
$this->load->model('viewstudents'); |
|
55 |
||
56 |
// menuData loads items to the menu.
|
|
57 |
$allTitles = array(); |
|
58 |
$allStudents = array(); |
|
59 |
||
60 |
/* Loads categorydata into array */
|
|
61 |
$query = $this->viewstudents->getStudents(); |
|
62 |
||
63 |
||
64 |
foreach ($query as $student) |
|
65 |
{
|
|
66 |
array_push($allStudents, $student->userName); |
|
67 |
}
|
|
68 |
||
69 |
/*Menu for examples page showing categories */
|
|
70 |
$this->load->view('examplesMenu', array('titles' => $allTitles)); |
|
71 |
||
72 |
/* Loads body for examples page */
|
|
73 |
||
74 |
$this->load->view('viewStudentsBody', array('students' => $allStudents)); |
|
75 |
||
76 |
}
|
|
77 |
||
78 |
||
79 |
public function validate() { |
|
80 |
//Load required library
|
|
81 |
$this->load->library('form_validation'); |
|
82 |
||
83 |
//Sets validation rules
|
|
84 |
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean'); |
|
85 |
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); |
|
86 |
||
87 |
//Run validation
|
|
88 |
if($this->form_validation->run() == FALSE) { |
|
89 |
//Field validation failed. Display login form (with error message).
|
|
90 |
$this->drawLoginForm(validation_errors()); |
|
91 |
} else { |
|
92 |
$username = $this->input->post('username'); |
|
93 |
$password = $this->input->post('password'); |
|
94 |
||
95 |
//Try to login
|
|
96 |
if ($this->user->login($username, $password)) { |
|
97 |
redirect(base_url().'home', 'refresh'); |
|
98 |
} else { |
|
99 |
$this->drawLoginForm('Access denied!'); |
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|
|
103 |
||
104 |
}
|
|
105 |
||
106 |
/* End of file ExamplesController.php */
|
|
107 |
/* Location: ./application/controllers/ExamplesController.php */
|