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()
34
/* Loads used models */
35
$this->load->model('user');
36
$this->load->model('admin/admin_model');
7
38
$this->load->library('session');
8
39
$this->load->helper('form');
10
/* Loads used models */
11
$this->load->model('user');
12
$this->load->model('admin/admin_model');
13
$this->load->model('ExamplesModel');
16
42
$headTagData = array(
17
'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
18
'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
43
'cssFiles' => array('manageCoursesBody', 'popup'),
44
'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
21
48
'userType' => $this->user->getUserType(), // Loads different header for teacher/student
22
49
'userName' => $this->user->getUserName()
25
$allCourses = array();
27
/* Loads categorydata into $allTitles */
28
$query = $this->ExamplesModel->getTitles($userInfo['userName']);
29
foreach ($query as $category)
32
$query2 = $this->ExamplesModel->getBody($category->categoryName);
33
$allTitles[$category->categoryName.",".$category->courseID] = array();
34
// $allTitles[$category->categoryName] = array();
35
// $allTitles[$category->courseID] = array();
36
foreach ($query2 as $subCategory)
39
$query3 = $this->ExamplesModel->getExamples($subCategory->subCategoryName);
40
$allTitles[$category->categoryName][$subCategory->subCategoryName] = array();
41
foreach ($query3 as $examples)
44
$allTitles[$category->categoryName][$subCategory->subCategoryName][] = $examples->exampleName;
52
// Loads head views, supplying CSS and JS data
53
$this->load->view('headTag', array('headTagData' => $headTagData));
54
//$this->load->view('bannermenu', $userInfo);
56
// Check user login and display message if not logged in
57
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
58
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
50
/* Loads coursedata into $allCourses */
62
// Loads data into $courses
51
63
$courses = $this->admin_model->getCourses();
54
$this->load->view('headTag', array('headTagData' => $headTagData));
55
$this->load->view('header', $userInfo);
56
$this->load->view('examplesMenu', array('titles' => $allTitles));
65
// Loads manageCourses view with $courses
57
66
$this->load->view('manageCoursesBody', array("courses" => $courses));
60
public function add_Course(){
62
if($this->input->post('cid')){
72
* Add course page - handles form submission from index page
73
* RESTRICTED-LEVEL: Teacher
75
public function addCourse(){
76
$this->load->model('user');
78
// User has to be logged in and usertype has to be Tea
79
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
80
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
84
if($this->input->post('addCourseID')){
63
85
$this->load->model('admin/admin_model');
64
$this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
86
$this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
65
87
redirect("/ManageCourses");
68
90
redirect("/ManageCourses");
95
* Edit course page - handles form submission from index page
96
* RESTRICTED-LEVEL: Teacher
98
function editCourse() {
99
$this->load->model('user');
100
// User has to be logged in and usertype has to be Teacher
101
if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
102
$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
106
if($this->input->post('editCourseID')) {
107
$this->load->model('admin/admin_model');
108
$this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
109
redirect('/ManageCourses');
111
echo "Something went wrong";
72
115
public function validate() {