1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
32
public function index()
34
/* Loads used models */
35
$this->load->model('user');
36
$this->load->model('admin/admin_model');
37
$this->load->model('ExamplesModel');
39
$this->load->library('session');
40
$this->load->helper('form');
44
'cssFiles' => array('manageCoursesBody', 'popup'),
45
'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
49
'userType' => $this->user->getUserType(), // Loads different header for teacher/student
50
'userName' => $this->user->getUserName()
53
// Loads head views, supplying CSS and JS data
54
$this->load->view('headTag', array('headTagData' => $headTagData));
55
//$this->load->view('bannermenu', $userInfo);
57
// Check user login and display message if not logged in
58
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
59
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
63
// Loads data into $courses
64
$courses = $this->admin_model->getCourses();
66
// Loads manageCourses view with $courses
67
$this->load->view('manageCoursesBody', array("courses" => $courses));
73
* Add course page - handles form submission from index page
74
* RESTRICTED-LEVEL: Teacher
76
public function addCourse(){
77
$this->load->model('user');
79
// User has to be logged in and usertype has to be Tea
80
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
81
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
85
if($this->input->post('addCourseID')){
86
$this->load->model('admin/admin_model');
87
$this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
88
redirect("/ManageCourses");
91
redirect("/ManageCourses");
96
* Edit course page - handles form submission from index page
97
* RESTRICTED-LEVEL: Teacher
99
function editCourse() {
100
$this->load->model('user');
101
// User has to be logged in and usertype has to be Teacher
102
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
103
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
107
if($this->input->post('editCourseID')) {
108
$this->load->model('admin/admin_model');
109
$this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
110
redirect('/ManageCourses');
112
echo "Something went wrong";
116
public function validate() {
117
//Load required library
118
$this->load->library('form_validation');
120
//Sets validation rules
121
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
122
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
125
if($this->form_validation->run() == FALSE) {
126
//Field validation failed. Display login form (with error message).
127
$this->drawLoginForm(validation_errors());
129
$username = $this->input->post('username');
130
$password = $this->input->post('password');
133
if ($this->user->login($username, $password)) {
134
redirect(base_url().'home', 'refresh');
136
$this->drawLoginForm('Access denied!');
141
public function manageCourse($cid) {
142
$cid = urldecode($cid);
143
$this->load->model('admin/Admin_model');
144
$categories = $this->Admin_model->getCategories($cid);
145
$this->load->view('admin/header', array("title" => "Manage course - ".$cid));
146
$menu = $this->Admin_model->getMenu();
147
$this->load->view('admin/menu', array("menu" => $menu));
148
$this->load->view('admin/manage_course', array("categories" => $categories, "cid" => $cid));
153
/* End of file ManageCourses.php */
154
/* Location: ./application/controllers/ExamplesController.php */
b'\\ No newline at end of file'