/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: Gustav Hartvigsson
  • Date: 2013-04-12 19:13:58 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130412191358-lvnmll48cw7idkzk
added:
* COPYING - licensing information
* COPYRIGHT_HEADER - the header that should be in every file related to
  the project.
* README - Information about the project.
* lgpl-3.0 - The license that is used by this project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
 
3
 
class ManageCourses extends CI_Controller {
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
 
        public function index()
33
 
        {
34
 
                /* Loads used models */
35
 
                $this->load->model('user');
36
 
                $this->load->model('admin/admin_model');
37
 
                $this->load->model('ExamplesModel');
38
 
 
39
 
                $this->load->library('session');
40
 
                $this->load->helper('form');
41
 
                
42
 
                // Arrays
43
 
                $headTagData = array(
44
 
                        'cssFiles' => array('manageCoursesBody', 'popup'),
45
 
                        'jsFiles' => array('examplesBody', 'userControls', 'manageCourses')
46
 
                );
47
 
 
48
 
                $userInfo = array(
49
 
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
50
 
                        'userName' => $this->user->getUserName()
51
 
                );
52
 
 
53
 
                // Loads head views, supplying CSS and JS data
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
67
 
                $this->load->view('manageCoursesBody', array("courses" => $courses));   
68
 
 
69
 
        }
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')){
86
 
                        $this->load->model('admin/admin_model');
87
 
                        $this->admin_model->addCourse($this->input->post("addCourseID"), $this->input->post("addCourseName"), $this->input->post("addCourseData"));
88
 
                        redirect("/ManageCourses");
89
 
                }
90
 
                else{
91
 
                        redirect("/ManageCourses");
92
 
                }
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
 
        }
115
 
        
116
 
        public function validate() {
117
 
                //Load required library
118
 
                $this->load->library('form_validation');
119
 
                
120
 
                //Sets validation rules
121
 
                $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
122
 
                $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
123
 
                
124
 
                //Run validation
125
 
                if($this->form_validation->run() == FALSE) {
126
 
                        //Field validation failed. Display login form (with error message).
127
 
                        $this->drawLoginForm(validation_errors());
128
 
                } else {
129
 
                        $username = $this->input->post('username');
130
 
                        $password = $this->input->post('password');
131
 
                        
132
 
                        //Try to login
133
 
                        if ($this->user->login($username, $password)) {
134
 
                                redirect(base_url().'home', 'refresh');
135
 
                        } else {
136
 
                                $this->drawLoginForm('Access denied!');
137
 
                        }
138
 
                }
139
 
        }
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
 
        
151
 
}
152
 
 
153
 
/* End of file ManageCourses.php */
154
 
/* Location: ./application/controllers/ExamplesController.php */
 
 
b'\\ No newline at end of file'