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