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

  • Committer: a11emmjo
  • Date: 2013-05-26 14:42:21 UTC
  • mto: This revision was merged to the branch mainline in revision 105.
  • Revision ID: a11emmjo@student.his.se-20130526144221-6zhtkrqnek1ckyx9
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.

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 Ajax extends CI_Controller {
 
4
                /*
 
5
                 *      Constructor
 
6
                 */
 
7
                function __construct() {
 
8
                        parent::__construct();
 
9
                        
 
10
                        //Load required library
 
11
                        $this->load->model('user', '', TRUE);
 
12
                }
 
13
                
 
14
                /*
 
15
                 *      This function loads a popupview to be displayed, the argument is the name of the popupview
 
16
                 */
 
17
                public function popup($popupName) {
 
18
                        $this->load->view('popup/'.$popupName);
 
19
                }
 
20
 
 
21
                function showPopup($popupName) {
 
22
                        $headTagData = array(
 
23
                                'cssFiles' => array('bannermenu', 'popup')
 
24
                        );
 
25
 
 
26
                        $userInfo = array(
 
27
                                'userType' => $this->user->getUserType(), // Loads different header for teacher/student
 
28
                                'userName' => $this->user->getUserName()
 
29
                        );
 
30
 
 
31
                        // Loads head views, supplying CSS and JS data
 
32
                        $this->load->view('headTag', array('headTagData' => $headTagData));
 
33
                        $this->load->view('bannermenu', $userInfo);
 
34
 
 
35
                        $this->load->view('popup/'.$popupName);
 
36
                }
 
37
                
 
38
                /*
 
39
                 *      This function return TRUE if the user is logged in and FALSE otherwise.
 
40
                 */
 
41
                public function isLoggedIn() {
 
42
                        if ($this->user->isLoggedIn()) {
 
43
                                echo 'yes';
 
44
                        }
 
45
                        else {
 
46
                                echo 'no';
 
47
                        }
 
48
                }
 
49
                
 
50
                /*
 
51
                 *      This function outputs data: user password hint.
 
52
                 */
 
53
                public function pwdhint() {
 
54
                $user = $this->input->post('hintPwd');
 
55
                        $data = array(
 
56
                                'hint' => $this->user->getPasswordHint($user)
 
57
                        );
 
58
                        
 
59
                        //Output JSON data
 
60
                        echo json_encode($data);
 
61
                }
 
62
 
 
63
                /*
 
64
                 *      This function outputs data: user password hint.
 
65
                 */
 
66
                public function ladok() {
 
67
                        $string = $this->input->post('data');
 
68
                        
 
69
                        $parsedArray = $this->user->parseLadok($string);
 
70
                        
 
71
                        if ($parsedArray === FALSE) {
 
72
                                $data = array('status' => FALSE);                               
 
73
                        } else {
 
74
                                //Add users to database
 
75
                                foreach ($parsedArray as $key => $value) {
 
76
                                        $this->user->addUser($parsedArray[$key]['username'], $parsedArray[$key]['firstname'] . ' ' . $parsedArray[$key]['lastname'], $parsedArray[$key]['ssn'], $parsedArray[$key]['ssn'], 'Student', 'Default', $parsedArray[$key]['email']);
 
77
                                }
 
78
                        
 
79
                                $data = array('status' => TRUE);                        
 
80
                        }
 
81
                        
 
82
                        //Output JSON data
 
83
                        echo json_encode($data);
 
84
                }
 
85
                
 
86
                /*
 
87
                 *      This function outputs data: user password hint.
 
88
                 */
 
89
                public function pwdchange() {
 
90
                        $pwdOld = $this->input->post('currentPwd');
 
91
                        $pwdNew = $this->input->post('newPwd');
 
92
                        $pwdHint = $this->input->post('hintPwd');
 
93
                
 
94
                        $data = array(
 
95
                                'status' => $this->user->changePassword($pwdOld, $pwdNew, $pwdHint)
 
96
                        );
 
97
                        
 
98
                        //Output JSON data
 
99
                        echo json_encode($data);
 
100
                }
 
101
                
 
102
                public function categoryOrderDecrease(){
 
103
                        $pwdOld = $this->input->post('currentPwd');
 
104
                        $pwdNew = $this->input->post('newPwd');
 
105
                }
 
106
 
 
107
                // Takes a course ID and sets the course to published (isHidden = 0)
 
108
                public function publishCourse($courseID) {
 
109
                        $this->load->model('user');
 
110
                        $this->load->model('admin/admin_model');
 
111
 
 
112
                        if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
113
                                $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
114
                                echo "not logged in";
 
115
                                return;
 
116
                        }
 
117
 
 
118
                        $this->admin_model->unsetCourseHidden($courseID);
 
119
                }
 
120
 
 
121
                //Takes a course ID and sets the course to unpublished (isHidden = 1)
 
122
                public function unpublishCourse($courseID) {
 
123
                        $this->load->model('user');
 
124
                        $this->load->model('admin/admin_model');
 
125
 
 
126
                        if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
127
                                $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
128
                                echo "not logged in";
 
129
                                return;
 
130
                        }
 
131
                        
 
132
                        $this->admin_model->setCourseHidden($courseID);
 
133
                }
 
134
        }
 
135
?>
 
 
b'\\ No newline at end of file'