/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/cms.php

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-28 15:21:12 UTC
  • mfrom: (83.2.23 pvp)
  • Revision ID: gustav.hartvigsson@gmail.com-20130528152112-pn1d6h8o6udcia0b
merged  Bigestans:s changes.


* Moved login JS to bannermenu.js and removed login.js
* Removed deprecated login CSS and JS
* Fixed login functionality -- now shows validation errors directly in the login popup, works through ajax
* Added a nifty little icon to represent the disabled login hint button
* Removed temporary functions from cms controller: tempLogin(), tempLogout(), test()
* Cleaned up ajax.php and cms.php

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 Cms extends CI_Controller {
 
4
        
 
5
                /*
 
6
                 *      Constructor
 
7
                 */
 
8
                function __construct() {
 
9
                        parent::__construct();
 
10
                        //Load required library
 
11
                        $this->load->model('user', '', TRUE);
 
12
                        $this->load->model('admin/admin_model', '', TRUE);
 
13
                        $this->load->model('filetree');
 
14
                }
 
15
                
 
16
                /*
 
17
                 *      This function runs when the user navigates directly to this controller
 
18
                 */
 
19
                public function index() {
 
20
                        if($this->user->isLoggedIn()) {
 
21
                                //User already logged in
 
22
                                $this->drawCmsPage('');
 
23
                        } else {
 
24
                                //Display the start page
 
25
                                redirect(base_url().'home', 'refresh');
 
26
                        }
 
27
                }               
 
28
                
 
29
                /*
 
30
                 *      This function draws the cms page.
 
31
                 */
 
32
                private function drawCmsPage() {
 
33
                        $userName = $this->user->getUserName();
 
34
                        $userType = $this->user->getUserType();
 
35
                        $activeCourse = $this->user->getActiveCourse();
 
36
 
 
37
                        if($userName != "" && $userType == "Teacher") {
 
38
                                //Creates an array with all courses.
 
39
                                $courses = $this->admin_model->getCourses();
 
40
                        } elseif($userName != "" && $userType == "Student") {
 
41
                                $courses = $this->admin_model->getStudentCourses($userName);
 
42
                        } else {
 
43
                                $courses = $this->admin_model->getPublicCourses();
 
44
                        }
 
45
 
 
46
 
 
47
                        //Creates an array with all categories for active course
 
48
                        $categories = $this->admin_model->getCategories($activeCourse['courseID']);
 
49
                        
 
50
                        //Creates an array with the variables that the bannermenu-view is expecting.
 
51
                        $data = array(
 
52
                                'userType' => $userType,
 
53
                                'userName' => $userName,
 
54
                                'courses' => $courses,
 
55
                                'categories' => $categories,
 
56
                                'activeCourse' => $activeCourse
 
57
                        );
 
58
                        
 
59
                        //Creates an array with the variables that the cmsindex-view is expecting.
 
60
                        $filetree = array();
 
61
                        
 
62
                        //Categories
 
63
                        $categories = $this->filetree->getCategories($data['activeCourse']['courseID']);
 
64
                        foreach ($categories as $category) {
 
65
                                $filetree[$category->categoryName] = array();
 
66
                                
 
67
                                //Sub categories
 
68
                                $subcategories = $this->filetree->getSubCategories($category->categoryName, $data['activeCourse']['courseID']);
 
69
                                foreach ($subcategories as $subcategory) {
 
70
                                        $filetree[$category->categoryName][$subcategory->subCategoryName] = array();
 
71
                                        
 
72
                                        //Examples
 
73
                                        $filetree[$category->categoryName][$subcategory->subCategoryName]['examples'] = array();
 
74
                                        $examples = $this->filetree->getExamples($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
 
75
                                        foreach ($examples as $example) {
 
76
                                                $filetree[$category->categoryName][$subcategory->subCategoryName]['examples'][] = $example->exampleName;
 
77
                                        }
 
78
                                        
 
79
                                        //Quizzes
 
80
                                        $filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'] = array();
 
81
                                        $quizzes = $this->filetree->getQuizzes($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
 
82
                                        foreach ($quizzes as $quiz) {
 
83
                                                $filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'][] = $quiz->quizNr;
 
84
                                        }
 
85
                                }
 
86
                        }
 
87
                        
 
88
                        //Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
 
89
                        $headTagData = array(
 
90
                                'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
 
91
                                'jsFiles' => array('bannermenu')
 
92
                        );
 
93
                        
 
94
                        //Puts the array above in <head></head>
 
95
                        $this->load->view('headTag', array('headTagData' => $headTagData));     
 
96
                        
 
97
                        $this->load->view('bannermenu', $data);
 
98
                        $this->load->view('sidemenu', $data);
 
99
                        $this->load->view('cmsindex', array('filetree' => $filetree));
 
100
                }
 
101
        }
 
102
?>