/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3
class ManageCourses extends CI_Controller {
4
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
5
	/* 
6
	 * tempLogin and tempLogout are temporary functions to debug user validation functionality
7
	 * They should be removed when lenasys is complete
8
	 */
9
	
10
	public function tempLogin() {
11
		$this->load->model('user');
12
		$loginDetails = array(
13
			'username' => 'tempTeacher',
14
			'name' => 'tempFoo',
15
			'usertype' => 'Teacher',
16
			'ssn' => '0000');
17
		$this->session->set_userdata('authenticated', $loginDetails);
18
		redirect('/ManageCourses');
19
	}
20
21
	public function tempLogout() {
22
		$this->load->model('user');
23
		$this->session->unset_userdata('authenticated');
24
		redirect('/ManageCourses');
25
	}
26
27
28
	/*
29
	 *	Manage courses index page
30
	 *  RESTRICTED-LEVEL: Teacher
31
	 */
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
32
	public function index()
33
	{
34
		/* Loads used models */
35
		$this->load->model('user');
36
		$this->load->model('admin/admin_model');
37
		$this->load->model('ExamplesModel');
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
38
39
		$this->load->library('session');
40
		$this->load->helper('form');
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
41
		
42
		// Arrays
43
		$headTagData = array(
44
			'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
45
			'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
46
		);
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
47
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
48
		$userInfo = array(
49
			'userType' => $this->user->getUserType(), // Loads different header for teacher/student
50
			'userName' => $this->user->getUserName()
51
		);
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
52
53
		
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
54
		$allTitles = array();
55
		$allCourses = array();
56
		
57
		/* Loads categorydata into $allTitles */
58
		$query = $this->ExamplesModel->getTitles($userInfo['userName']);
59
		foreach ($query as $category)
60
		{
61
			// Category
62
			$query2 = $this->ExamplesModel->getBody($category->categoryName);
63
			$allTitles[$category->categoryName.",".$category->courseID] = array();
64
		//	$allTitles[$category->categoryName] = array();
65
		//	$allTitles[$category->courseID] = array();
66
						foreach ($query2 as $subCategory)
67
			{
68
				// Subcategory
69
				$query3 = $this->ExamplesModel->getExamples($subCategory->subCategoryName);
70
				$allTitles[$category->categoryName][$subCategory->subCategoryName] = array();
71
				foreach ($query3 as $examples)
72
				{
73
					//Examples
74
					$allTitles[$category->categoryName][$subCategory->subCategoryName][] = $examples->exampleName;
75
				}
76
77
			}
78
		}
79
80
		/* Loads views */
81
		$this->load->view('headTag', array('headTagData' => $headTagData));
82
		$this->load->view('header', $userInfo);
83
		$this->load->view('examplesMenu', array('titles' => $allTitles));	
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
84
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'));
89
			return;
90
		}
91
92
		/* Loads coursedata into $allCourses */
93
		$courses = $this->admin_model->getCourses();
94
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
95
		$this->load->view('manageCoursesBody', array("courses" => $courses));	
96
97
	}
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
98
99
100
	/*
101
	 *	Add course page - handles form submission from index page 
102
	 *  RESTRICTED-LEVEL: Teacher
103
	 */
104
	public function addCourse(){
105
		$this->load->model('user');
106
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'));
110
			return;
111
		}
112
113
		/* 
114
			To do: 
115
				Login validation
116
				Input validation
117
		*/
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
118
		if($this->input->post('cid')){
119
			$this->load->model('admin/admin_model');
120
			$this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
121
			redirect("/ManageCourses");
122
		}
123
		else{
124
			redirect("/ManageCourses");
125
		}
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
126
	} 	
127
128
	/*
129
	 *	Edit course page - handles form submission from index page 
130
	 *  RESTRICTED-LEVEL: Teacher
131
	 */
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'));
137
			return;
138
		}
139
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');
144
		} else {
145
			echo "Something went wrong";
146
		}
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
147
	}
148
	
149
	public function validate() {
150
		//Load required library
151
		$this->load->library('form_validation');
152
		
153
		//Sets validation rules
154
		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
155
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
156
		
157
		//Run validation
158
		if($this->form_validation->run() == FALSE) {
159
			//Field validation failed. Display login form (with error message).
160
			$this->drawLoginForm(validation_errors());
161
		} else {
162
			$username = $this->input->post('username');
163
			$password = $this->input->post('password');
164
			
165
			//Try to login
166
			if ($this->user->login($username, $password)) {
167
				redirect(base_url().'home', 'refresh');
168
			} else {
169
				$this->drawLoginForm('Access denied!');
170
			}
171
		}
172
	}
173
	
174
}
175
176
/* End of file ManageCourses.php */
177
/* Location: ./application/controllers/ExamplesController.php */