/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-24 11:28:43 UTC
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: a11andoh@student.his.se-20130524112843-360je7hu7q13r171
added the cms controller to load all content pages.
added first time registration controller to load the views for the registration
pages.
added and fixed temporarypages for the controllers 
and edited the models to be able to get active courses.

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
        public function index()
 
6
        {
 
7
                $this->load->library('session');
 
8
                $this->load->helper('form');
 
9
 
 
10
                /* Loads used models */
 
11
                $this->load->model('user');
 
12
                $this->load->model('admin/admin_model');
 
13
                $this->load->model('ExamplesModel');
 
14
                
 
15
                // Arrays
 
16
                $headTagData = array(
 
17
                        'cssFiles' => array('header', 'examplesMenu', 'manageCoursesBody'),
 
18
                        'jsFiles' => array('header', 'examplesMenu', 'examplesBody', 'userControls', 'manageCourses')
 
19
                );
 
20
                $userInfo = array(
 
21
                        'userType' => $this->user->getUserType(), // Loads different header for teacher/student
 
22
                        'userName' => $this->user->getUserName()
 
23
                );
 
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
                $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));   
 
58
 
 
59
        }
 
60
        public function add_Course(){
 
61
                // FIXA H�R     
 
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");
 
66
                }
 
67
                else{
 
68
                        redirect("/ManageCourses");
 
69
                }
 
70
        }
 
71
        
 
72
        public function validate() {
 
73
                //Load required library
 
74
                $this->load->library('form_validation');
 
75
                
 
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');
 
79
                
 
80
                //Run validation
 
81
                if($this->form_validation->run() == FALSE) {
 
82
                        //Field validation failed. Display login form (with error message).
 
83
                        $this->drawLoginForm(validation_errors());
 
84
                } else {
 
85
                        $username = $this->input->post('username');
 
86
                        $password = $this->input->post('password');
 
87
                        
 
88
                        //Try to login
 
89
                        if ($this->user->login($username, $password)) {
 
90
                                redirect(base_url().'home', 'refresh');
 
91
                        } else {
 
92
                                $this->drawLoginForm('Access denied!');
 
93
                        }
 
94
                }
 
95
        }
 
96
        
 
97
}
 
98
 
 
99
/* End of file ManageCourses.php */
 
100
/* Location: ./application/controllers/ExamplesController.php */
 
 
b'\\ No newline at end of file'