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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ManageCourses extends CI_Controller {
/*
* tempLogin and tempLogout are temporary functions to debug user validation functionality
* They should be removed when lenasys is complete
*/
public function tempLogin() {
$this->load->model('user');
$loginDetails = array(
'username' => 'tempTeacher',
'name' => 'tempFoo',
'usertype' => 'Teacher',
'ssn' => '0000');
$this->session->set_userdata('authenticated', $loginDetails);
redirect('/ManageCourses');
}
public function tempLogout() {
$this->load->model('user');
$this->session->unset_userdata('authenticated');
redirect('/ManageCourses');
}
/*
* Manage courses index page
* RESTRICTED-LEVEL: Teacher
*/
public function index()
{
/* Loads used models */
$this->load->model('user');
$this->load->model('admin/admin_model');
$this->load->library('session');
$this->load->helper('form');
// Arrays
$headTagData = array(
'cssFiles' => array('manageCoursesBody', 'popup'),
'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
);
$userInfo = array(
'userType' => $this->user->getUserType(), // Loads different header for teacher/student
'userName' => $this->user->getUserName()
);
// Loads head views, supplying CSS and JS data
$this->load->view('headTag', array('headTagData' => $headTagData));
//$this->load->view('bannermenu', $userInfo);
// Check user login and display message if not logged in
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
return;
}
// Loads data into $courses
$courses = $this->admin_model->getCourses();
// Loads manageCourses view with $courses
$this->load->view('manageCoursesBody', array("courses" => $courses));
}
/*
* Add course page - handles form submission from index page
* RESTRICTED-LEVEL: Teacher
*/
public function addCourse(){
$this->load->model('user');
// User has to be logged in and usertype has to be Tea
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
return;
}
if($this->input->post('addCourseID')){
$this->load->model('admin/admin_model');
$this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
redirect("/ManageCourses");
}
else{
redirect("/ManageCourses");
}
}
/*
* Edit course page - handles form submission from index page
* RESTRICTED-LEVEL: Teacher
*/
function editCourse() {
$this->load->model('user');
// User has to be logged in and usertype has to be Teacher
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
return;
}
if($this->input->post('editCourseID')) {
$this->load->model('admin/admin_model');
$this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
redirect('/ManageCourses');
} else {
echo "Something went wrong";
}
}
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!');
}
}
}
public function manageCourse($cid) {
$cid = urldecode($cid);
$this->load->model('admin/Admin_model');
$categories = $this->Admin_model->getCategories($cid);
$this->load->view('admin/header', array("title" => "Manage course - ".$cid));
$menu = $this->Admin_model->getMenu();
$this->load->view('admin/menu', array("menu" => $menu));
$this->load->view('admin/manage_course', array("categories" => $categories, "cid" => $cid));
}
}
/* End of file ManageCourses.php */
/* Location: ./application/controllers/ExamplesController.php */
|