/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
	 */
83.2.2 by elof.bigestans at gmail
Further cleaned up ManageCourses
9
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
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');
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
37
38
		$this->load->library('session');
39
		$this->load->helper('form');
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
40
		
41
		// Arrays
42
		$headTagData = array(
83.2.12 by elof.bigestans at gmail
* Merged trunk
43
			'cssFiles' => array('manageCoursesBody', 'popup'),
83.2.6 by elof.bigestans at gmail
Solved some bugs in ManageCourses and related files (CSS, JS, View, Controller)
44
			'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
45
		);
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
46
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
47
		$userInfo = array(
48
			'userType' => $this->user->getUserType(), // Loads different header for teacher/student
49
			'userName' => $this->user->getUserName()
50
		);
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
51
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
52
		// Loads head views, supplying CSS and JS data
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
53
		$this->load->view('headTag', array('headTagData' => $headTagData));
83.2.12 by elof.bigestans at gmail
* Merged trunk
54
		//$this->load->view('bannermenu', $userInfo);
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
55
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'));
59
			return;
60
		}
61
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
62
		// Loads data into $courses
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
63
		$courses = $this->admin_model->getCourses();
64
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
65
		// Loads manageCourses view with $courses
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
66
		$this->load->view('manageCoursesBody', array("courses" => $courses));	
67
68
	}
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
69
70
71
	/*
72
	 *	Add course page - handles form submission from index page 
73
	 *  RESTRICTED-LEVEL: Teacher
74
	 */
75
	public function addCourse(){
76
		$this->load->model('user');
77
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'));
81
			return;
82
		}
83
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
84
		if($this->input->post('addCourseID')){
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
85
			$this->load->model('admin/admin_model');
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
86
			$this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
87
			redirect("/ManageCourses");
88
		}
89
		else{
90
			redirect("/ManageCourses");
91
		}
83.2.1 by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function
92
	} 	
93
94
	/*
95
	 *	Edit course page - handles form submission from index page 
96
	 *  RESTRICTED-LEVEL: Teacher
97
	 */
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'));
103
			return;
104
		}
105
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');
110
		} else {
111
			echo "Something went wrong";
112
		}
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
113
	}
114
	
115
	public function validate() {
116
		//Load required library
117
		$this->load->library('form_validation');
118
		
119
		//Sets validation rules
120
		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
121
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
122
		
123
		//Run validation
124
		if($this->form_validation->run() == FALSE) {
125
			//Field validation failed. Display login form (with error message).
126
			$this->drawLoginForm(validation_errors());
127
		} else {
128
			$username = $this->input->post('username');
129
			$password = $this->input->post('password');
130
			
131
			//Try to login
132
			if ($this->user->login($username, $password)) {
133
				redirect(base_url().'home', 'refresh');
134
			} else {
135
				$this->drawLoginForm('Access denied!');
136
			}
137
		}
138
	}
83.2.2 by elof.bigestans at gmail
Further cleaned up ManageCourses
139
140
	public function manageCourse($cid) {
141
		$cid = urldecode($cid);
142
		$this->load->model('admin/Admin_model');
143
		$categories = $this->Admin_model->getCategories($cid);
144
		$this->load->view('admin/header', array("title" => "Manage course - ".$cid));
145
		$menu = $this->Admin_model->getMenu();
146
		$this->load->view('admin/menu', array("menu" => $menu));
147
		$this->load->view('admin/manage_course', array("categories" => $categories, "cid" => $cid));
148
	}
79.1.1 by a10rolch
- Updated admin_model function addCourse to also include courseData.
149
	
150
}
151
152
/* End of file ManageCourses.php */
153
/* Location: ./application/controllers/ExamplesController.php */