3
3
class ManageCourses extends CI_Controller {
6
* tempLogin and tempLogout are temporary functions to debug user validation functionality
7
* They should be removed when lenasys is complete
10
public function tempLogin() {
11
$this->load->model('user');
12
$loginDetails = array(
13
'username' => 'tempTeacher',
15
'usertype' => 'Teacher',
17
$this->session->set_userdata('authenticated', $loginDetails);
18
redirect('/ManageCourses');
21
public function tempLogout() {
22
$this->load->model('user');
23
$this->session->unset_userdata('authenticated');
24
redirect('/ManageCourses');
29
* Manage courses index page
30
* RESTRICTED-LEVEL: Teacher
5
32
public function index()
7
$this->load->library('session');
8
$this->load->helper('form');
10
34
/* Loads used models */
11
35
$this->load->model('user');
12
36
$this->load->model('admin/admin_model');
13
37
$this->load->model('ExamplesModel');
39
$this->load->library('session');
40
$this->load->helper('form');
16
43
$headTagData = array(
17
44
'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
18
45
'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
21
49
'userType' => $this->user->getUserType(), // Loads different header for teacher/student
22
50
'userName' => $this->user->getUserName()
24
54
$allTitles = array();
25
55
$allCourses = array();
50
/* Loads coursedata into $allCourses */
51
$courses = $this->admin_model->getCourses();
54
81
$this->load->view('headTag', array('headTagData' => $headTagData));
55
82
$this->load->view('header', $userInfo);
56
83
$this->load->view('examplesMenu', array('titles' => $allTitles));
85
// Check user login and display message if not logged in
86
// User has to be logged in and usertype has to be Tea
87
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
88
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
92
/* Loads coursedata into $allCourses */
93
$courses = $this->admin_model->getCourses();
57
95
$this->load->view('manageCoursesBody', array("courses" => $courses));
60
public function add_Course(){
101
* Add course page - handles form submission from index page
102
* RESTRICTED-LEVEL: Teacher
104
public function addCourse(){
105
$this->load->model('user');
107
// User has to be logged in and usertype has to be Tea
108
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
109
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
62
118
if($this->input->post('cid')){
63
119
$this->load->model('admin/admin_model');
64
120
$this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
68
124
redirect("/ManageCourses");
129
* Edit course page - handles form submission from index page
130
* RESTRICTED-LEVEL: Teacher
132
function editCourse() {
133
$this->load->model('user');
134
// User has to be logged in and usertype has to be Teacher
135
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
136
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
140
if($this->input->post('editCourseID')) {
141
$this->load->model('admin/admin_model');
142
$this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
143
redirect('/ManageCourses');
145
echo "Something went wrong";
72
149
public function validate() {