/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
5
	public function index()
6
	{
7
		$this->load->library('session');
8
		$this->load->helper('form');
9
10
		/* Loads used models */
11
		$this->load->model('user');
12
		$this->load->model('admin/admin_model');
13
		$this->load->model('ExamplesModel');
14
		
15
		// Arrays
16
		$headTagData = array(
17
			'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
18
			'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
19
		);
20
		$userInfo = array(
21
			'userType' => $this->user->getUserType(), // Loads different header for teacher/student
22
			'userName' => $this->user->getUserName()
23
		);
24
		$allTitles = array();
25
		$allCourses = array();
26
		
27
		/* Loads categorydata into $allTitles */
28
		$query = $this->ExamplesModel->getTitles($userInfo['userName']);
29
		foreach ($query as $category)
30
		{
31
			// 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)
37
			{
38
				// Subcategory
39
				$query3 = $this->ExamplesModel->getExamples($subCategory->subCategoryName);
40
				$allTitles[$category->categoryName][$subCategory->subCategoryName] = array();
41
				foreach ($query3 as $examples)
42
				{
43
					//Examples
44
					$allTitles[$category->categoryName][$subCategory->subCategoryName][] = $examples->exampleName;
45
				}
46
47
			}
48
		}
49
50
		/* Loads coursedata into $allCourses */
51
		$courses = $this->admin_model->getCourses();
52
53
		/* Loads views */
54
		$this->load->view('headTag', array('headTagData' => $headTagData));
55
		$this->load->view('header', $userInfo);
56
		$this->load->view('examplesMenu', array('titles' => $allTitles));	
57
		$this->load->view('manageCoursesBody', array("courses" => $courses));	
58
59
	}
60
	public function add_Course(){
61
		// FIXA HÄR	
62
		if($this->input->post('cid')){
63
			$this->load->model('admin/admin_model');
64
			$this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
65
			redirect("/ManageCourses");
66
		}
67
		else{
68
			redirect("/ManageCourses");
69
		}
70
	}
71
	
72
	public function validate() {
73
		//Load required library
74
		$this->load->library('form_validation');
75
		
76
		//Sets validation rules
77
		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
78
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
79
		
80
		//Run validation
81
		if($this->form_validation->run() == FALSE) {
82
			//Field validation failed. Display login form (with error message).
83
			$this->drawLoginForm(validation_errors());
84
		} else {
85
			$username = $this->input->post('username');
86
			$password = $this->input->post('password');
87
			
88
			//Try to login
89
			if ($this->user->login($username, $password)) {
90
				redirect(base_url().'home', 'refresh');
91
			} else {
92
				$this->drawLoginForm('Access denied!');
93
			}
94
		}
95
	}
96
	
97
}
98
99
/* End of file ManageCourses.php */
100
/* Location: ./application/controllers/ExamplesController.php */