1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 
3
class ManageCourses extends CI_Controller {
 
 
5
        public function index()
 
 
7
                $this->load->library('session');
 
 
8
                $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');
 
 
17
                        'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
 
 
18
                        'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
 
 
21
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
 
 
22
                        '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;
 
 
50
                /* Loads coursedata into $allCourses */
 
 
51
                $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));       
 
 
57
                $this->load->view('manageCoursesBody', array("courses" => $courses));   
 
 
60
        public function add_Course(){
 
 
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");
 
 
68
                        redirect("/ManageCourses");
 
 
72
        public function validate() {
 
 
73
                //Load required library
 
 
74
                $this->load->library('form_validation');
 
 
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');
 
 
81
                if($this->form_validation->run() == FALSE) {
 
 
82
                        //Field validation failed. Display login form (with error message).
 
 
83
                        $this->drawLoginForm(validation_errors());
 
 
85
                        $username = $this->input->post('username');
 
 
86
                        $password = $this->input->post('password');
 
 
89
                        if ($this->user->login($username, $password)) {
 
 
90
                                redirect(base_url().'home', 'refresh');
 
 
92
                                $this->drawLoginForm('Access denied!');
 
 
99
/* End of file ManageCourses.php */
 
 
100
/* Location: ./application/controllers/ExamplesController.php */
 
 
 
b'\\ No newline at end of file'