/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: elof.bigestans at gmail
  • Date: 2013-05-22 11:39:03 UTC
  • mto: This revision was merged to the branch mainline in revision 94.
  • Revision ID: elof.bigestans@gmail.com-20130522113903-j31cvd4i191k7mkz
Fixed various bugs in the ManageCourses function

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
         */
5
32
        public function index()
6
33
        {
7
 
                $this->load->library('session');
8
 
                $this->load->helper('form');
9
 
 
10
34
                /* Loads used models */
11
35
                $this->load->model('user');
12
36
                $this->load->model('admin/admin_model');
13
37
                $this->load->model('ExamplesModel');
 
38
 
 
39
                $this->load->library('session');
 
40
                $this->load->helper('form');
14
41
                
15
42
                // Arrays
16
43
                $headTagData = array(
17
44
                        'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
18
45
                        'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
19
46
                );
 
47
 
20
48
                $userInfo = array(
21
49
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
22
50
                        'userName' => $this->user->getUserName()
23
51
                );
 
52
 
 
53
                
24
54
                $allTitles = array();
25
55
                $allCourses = array();
26
56
                
47
77
                        }
48
78
                }
49
79
 
50
 
                /* Loads coursedata into $allCourses */
51
 
                $courses = $this->admin_model->getCourses();
52
 
 
53
80
                /* Loads views */
54
81
                $this->load->view('headTag', array('headTagData' => $headTagData));
55
82
                $this->load->view('header', $userInfo);
56
83
                $this->load->view('examplesMenu', array('titles' => $allTitles));       
 
84
 
 
85
                // Check user login and display message if not logged in
 
86
                                // User has to be logged in and usertype has to be Tea
 
87
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
88
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
89
                        return;
 
90
                }
 
91
 
 
92
                /* Loads coursedata into $allCourses */
 
93
                $courses = $this->admin_model->getCourses();
 
94
 
57
95
                $this->load->view('manageCoursesBody', array("courses" => $courses));   
58
96
 
59
97
        }
60
 
        public function add_Course(){
61
 
                // FIXA H�R     
 
98
 
 
99
 
 
100
        /*
 
101
         *      Add course page - handles form submission from index page 
 
102
         *  RESTRICTED-LEVEL: Teacher
 
103
         */
 
104
        public function addCourse(){
 
105
                $this->load->model('user');
 
106
 
 
107
                // User has to be logged in and usertype has to be Tea
 
108
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
109
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
110
                        return;
 
111
                }
 
112
 
 
113
                /* 
 
114
                        To do: 
 
115
                                Login validation
 
116
                                Input validation
 
117
                */
62
118
                if($this->input->post('cid')){
63
119
                        $this->load->model('admin/admin_model');
64
120
                        $this->admin_model->addCourse($_POST['cid'], $_POST['name'], $_POST['courseData']);
67
123
                else{
68
124
                        redirect("/ManageCourses");
69
125
                }
 
126
        }       
 
127
 
 
128
        /*
 
129
         *      Edit course page - handles form submission from index page 
 
130
         *  RESTRICTED-LEVEL: Teacher
 
131
         */
 
132
        function editCourse() {
 
133
                $this->load->model('user');
 
134
                // User has to be logged in and usertype has to be Teacher
 
135
                if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
136
                        $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
137
                        return;
 
138
                }
 
139
 
 
140
                if($this->input->post('editCourseID')) {
 
141
                        $this->load->model('admin/admin_model');
 
142
                        $this->admin_model->editCourse($this->input->post('editCourseID'), $this->input->post('editCourseName'), $this->input->post('editCourseData'));
 
143
                        redirect('/ManageCourses');
 
144
                } else {
 
145
                        echo "Something went wrong";
 
146
                }
70
147
        }
71
148
        
72
149
        public function validate() {