/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/controllers/ManageCourses.php

  • Committer: a11andoh
  • Date: 2013-05-23 08:16:45 UTC
  • mfrom: (88 lenasys_b)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: a11andoh@student.his.se-20130523081645-jxltw80q135v14ot
blurp

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
class ManageCourses extends CI_Controller {
4
4
 
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
 
         */
32
5
        public function index()
33
6
        {
 
7
                $this->load->library('session');
 
8
                $this->load->helper('form');
 
9
 
34
10
                /* Loads used models */
35
11
                $this->load->model('user');
36
12
                $this->load->model('admin/admin_model');
37
13
                $this->load->model('ExamplesModel');
38
 
 
39
 
                $this->load->library('session');
40
 
                $this->load->helper('form');
41
14
                
42
15
                // Arrays
43
16
                $headTagData = array(
44
 
                        'cssFiles' => array('manageCoursesBody', 'popup'),
45
 
                        'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
 
17
                        'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
 
18
                        'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
46
19
                );
47
 
 
48
20
                $userInfo = array(
49
21
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
50
22
                        'userName' => $this->user->getUserName()
51
23
                );
52
 
 
53
 
                // Loads head views, supplying CSS and JS data
 
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
54
                $this->load->view('headTag', array('headTagData' => $headTagData));
55
 
                //$this->load->view('bannermenu', $userInfo);
56
 
 
57
 
                // Check user login and display message if not logged in
58
 
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
59
 
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
60
 
                        return;
61
 
                }
62
 
 
63
 
                // Loads data into $courses
64
 
                $courses = $this->admin_model->getCourses();
65
 
 
66
 
                // Loads manageCourses view with $courses
 
55
                $this->load->view('header', $userInfo);
 
56
                $this->load->view('examplesMenu', array('titles' => $allTitles));       
67
57
                $this->load->view('manageCoursesBody', array("courses" => $courses));   
68
58
 
69
59
        }
70
 
 
71
 
 
72
 
        /*
73
 
         *      Add course page - handles form submission from index page 
74
 
         *  RESTRICTED-LEVEL: Teacher
75
 
         */
76
 
        public function addCourse(){
77
 
                $this->load->model('user');
78
 
 
79
 
                // User has to be logged in and usertype has to be Tea
80
 
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
81
 
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
82
 
                        return;
83
 
                }
84
 
 
85
 
                if($this->input->post('addCourseID')){
 
60
        public function add_Course(){
 
61
                // FIXA H�R     
 
62
                if($this->input->post('cid')){
86
63
                        $this->load->model('admin/admin_model');
87
 
                        $this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
 
64
                        $this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
88
65
                        redirect("/ManageCourses");
89
66
                }
90
67
                else{
91
68
                        redirect("/ManageCourses");
92
69
                }
93
 
        }       
94
 
 
95
 
        /*
96
 
         *      Edit course page - handles form submission from index page 
97
 
         *  RESTRICTED-LEVEL: Teacher
98
 
         */
99
 
        function editCourse() {
100
 
                $this->load->model('user');
101
 
                // User has to be logged in and usertype has to be Teacher
102
 
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
103
 
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
104
 
                        return;
105
 
                }
106
 
 
107
 
                if($this->input->post('editCourseID')) {
108
 
                        $this->load->model('admin/admin_model');
109
 
                        $this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
110
 
                        redirect('/ManageCourses');
111
 
                } else {
112
 
                        echo "Something went wrong";
113
 
                }
114
70
        }
115
71
        
116
72
        public function validate() {
137
93
                        }
138
94
                }
139
95
        }
140
 
 
141
 
        public function manageCourse($cid) {
142
 
                $cid = urldecode($cid);
143
 
                $this->load->model('admin/Admin_model');
144
 
                $categories = $this->Admin_model->getCategories($cid);
145
 
                $this->load->view('admin/header', array("title" => "Manage course - ".$cid));
146
 
                $menu = $this->Admin_model->getMenu();
147
 
                $this->load->view('admin/menu', array("menu" => $menu));
148
 
                $this->load->view('admin/manage_course', array("categories" => $categories, "cid" => $cid));
149
 
        }
150
96
        
151
97
}
152
98