/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-24 14:24:18 UTC
  • mto: This revision was merged to the branch mainline in revision 103.
  • Revision ID: a11emmjo@student.his.se-20130524142418-vyvd1ccmfira2cr9
Fixed some redirect-links.

Bug #1183407 Part of this: Fixed click-function for the usermenubutton/loginbutton.

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
                /*
 
22
                 *      This function return TRUE if the user is logged in and FALSE otherwise.
 
23
                 */
 
24
                public function isLoggedIn() {
 
25
                        if ($this->user->isLoggedIn()) {
 
26
                                echo 'yes';
 
27
                        }
 
28
                        else {
 
29
                                echo 'no';
 
30
                        }
 
31
                }
 
32
                
 
33
                /*
 
34
                 *      This function outputs data: user password hint.
 
35
                 */
 
36
                public function pwdhint() {
 
37
                $user = $this->input->post('hintPwd');
 
38
                        $data = array(
 
39
                                'hint' => $this->user->getPasswordHint($user)
 
40
                        );
 
41
                        
 
42
                        //Output JSON data
 
43
                        echo json_encode($data);
 
44
                }
 
45
 
 
46
                /*
 
47
                 *      This function outputs data: user password hint.
 
48
                 */
 
49
                public function ladok() {
 
50
                        $string = $this->input->post('data');
 
51
                        
 
52
                        $parsedArray = $this->user->parseLadok($string);
 
53
                        
 
54
                        if ($parsedArray === FALSE) {
 
55
                                $data = array('status' => FALSE);                               
 
56
                        } else {
 
57
                                //Add users to database
 
58
                                foreach ($parsedArray as $key => $value) {
 
59
                                        $this->user->addUser($parsedArray[$key]['username'], $parsedArray[$key]['firstname'] . ' ' . $parsedArray[$key]['lastname'], $parsedArray[$key]['ssn'], $parsedArray[$key]['ssn'], 'Student', 'Default', $parsedArray[$key]['email']);
 
60
                                }
 
61
                        
 
62
                                $data = array('status' => TRUE);                        
 
63
                        }
 
64
                        
 
65
                        //Output JSON data
 
66
                        echo json_encode($data);
 
67
                }
 
68
                
 
69
                /*
 
70
                 *      This function outputs data: user password hint.
 
71
                 */
 
72
                public function pwdchange() {
 
73
                        $pwdOld = $this->input->post('currentPwd');
 
74
                        $pwdNew = $this->input->post('newPwd');
 
75
                        $pwdHint = $this->input->post('hintPwd');
 
76
                
 
77
                        $data = array(
 
78
                                'status' => $this->user->changePassword($pwdOld, $pwdNew, $pwdHint)
 
79
                        );
 
80
                        
 
81
                        //Output JSON data
 
82
                        echo json_encode($data);
 
83
                }
 
84
                
 
85
                public function categoryOrderDecrease(){
 
86
                        $pwdOld = $this->input->post('currentPwd');
 
87
                        $pwdNew = $this->input->post('newPwd');
 
88
                }
 
89
 
 
90
                // Takes a course ID and sets the course to published (isHidden = 0)
 
91
                public function publishCourse($courseID) {
 
92
                        $this->load->model('user');
 
93
                        $this->load->model('admin/admin_model');
 
94
 
 
95
                        if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
96
                                $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
97
                                echo "not logged in";
 
98
                                return;
 
99
                        }
 
100
 
 
101
                        $this->admin_model->unsetCourseHidden($courseID);
 
102
                }
 
103
 
 
104
                //Takes a course ID and sets the course to unpublished (isHidden = 1)
 
105
                public function unpublishCourse($courseID) {
 
106
                        $this->load->model('user');
 
107
                        $this->load->model('admin/admin_model');
 
108
 
 
109
                        if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
 
110
                                $this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
 
111
                                echo "not logged in";
 
112
                                return;
 
113
                        }
 
114
                        
 
115
                        $this->admin_model->setCourseHidden($courseID);
 
116
                }
 
117
        }
 
118
?>
 
 
b'\\ No newline at end of file'