/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
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
		
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
14
		/*
15
		 *	This function loads a popupview to be displayed, the argument is the name of the popupview
16
		 */
17
		public function popup($popupName) {
83.2.8 by elof.bigestans at gmail
Further modifications in popups
18
			$this->load->view('popup/'.$popupName);
19
		}
20
21
		function showPopup($popupName) {
83.2.7 by elof.bigestans at gmail
Started work on normalizing popups. Lots to go.
22
			$headTagData = array(
83.2.12 by elof.bigestans at gmail
* Merged trunk
23
				'cssFiles' => array('popup'),
24
				'jsFiles' => array('login')
83.2.7 by elof.bigestans at gmail
Started work on normalizing popups. Lots to go.
25
			);
26
27
			$userInfo = array(
28
				'userType' => $this->user->getUserType(), // Loads different header for teacher/student
29
				'userName' => $this->user->getUserName()
30
			);
31
32
			// Loads head views, supplying CSS and JS data
33
			$this->load->view('headTag', array('headTagData' => $headTagData));
34
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
35
			$this->load->view('popup/'.$popupName);
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
36
		}
37
		
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
38
		/*
90.1.8 by a11emmjo
Fixed some redirect-links.
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
		}
83.2.22 by elof.bigestans at gmail
* Moved login JS to bannermenu.js and removed login.js
49
50
		function 
90.1.8 by a11emmjo
Fixed some redirect-links.
51
		
52
		/*
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
53
		 *	This function outputs data: user password hint.
54
		 */
64.1.1 by b11johgu
ExamplesController:
55
		public function pwdhint() {
83.2.12 by elof.bigestans at gmail
* Merged trunk
56
			$this->load->model('user');
57
			if($this->input->post('username')) {
58
				$username = $this->input->post('username');
59
				$data = array(
60
					'hint' => $this->user->getPasswordHint($username)
61
				);
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
62
			
83.2.12 by elof.bigestans at gmail
* Merged trunk
63
				//Output JSON data
64
				echo json_encode($data);
65
			}
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
66
		}
69.1.3 by Daniel Hermansson
Added ajax functionality for ladok parser
67
68
		/*
69
		 *	This function outputs data: user password hint.
70
		 */
71
		public function ladok() {
72
			$string = $this->input->post('data');
73
			
74
			$parsedArray = $this->user->parseLadok($string);
75
			
76
			if ($parsedArray === FALSE) {
77
				$data = array('status' => FALSE);				
78
			} else {
79
				//Add users to database
80
				foreach ($parsedArray as $key => $value) {
81
					$this->user->addUser($parsedArray[$key]['username'], $parsedArray[$key]['firstname'] . ' ' . $parsedArray[$key]['lastname'], $parsedArray[$key]['ssn'], $parsedArray[$key]['ssn'], 'Student', 'Default', $parsedArray[$key]['email']);
82
				}
83
			
84
				$data = array('status' => TRUE);			
85
			}
86
			
87
			//Output JSON data
88
			echo json_encode($data);
89
		}
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
90
		
91
		/*
92
		 *	This function outputs data: user password hint.
93
		 */
94
		public function pwdchange() {
95
			$pwdOld = $this->input->post('currentPwd');
96
			$pwdNew = $this->input->post('newPwd');
97
			$pwdHint = $this->input->post('hintPwd');
98
		
99
			$data = array(
100
				'status' => $this->user->changePassword($pwdOld, $pwdNew, $pwdHint)
101
			);
102
			
103
			//Output JSON data
104
			echo json_encode($data);
105
		}
64.1.1 by b11johgu
ExamplesController:
106
		
107
		public function categoryOrderDecrease(){
108
			$pwdOld = $this->input->post('currentPwd');
109
			$pwdNew = $this->input->post('newPwd');
110
		}
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
111
112
		// Takes a course ID and sets the course to published (isHidden = 0)
113
		public function publishCourse($courseID) {
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
114
			$this->load->model('user');
115
			$this->load->model('admin/admin_model');
116
117
			if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
118
				$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
119
				echo "not logged in";
120
				return;
121
			}
122
123
			$this->admin_model->unsetCourseHidden($courseID);
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
124
		}
125
126
		//Takes a course ID and sets the course to unpublished (isHidden = 1)
127
		public function unpublishCourse($courseID) {
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
128
			$this->load->model('user');
129
			$this->load->model('admin/admin_model');
130
131
			if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
132
				$this->load->view('manageCoursesMessage', array('message' => 'You do not have access to this page'));
133
				echo "not logged in";
134
				return;
135
			}
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
136
			
83.2.5 by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller.
137
			$this->admin_model->setCourseHidden($courseID);
83.2.3 by elof.bigestans at gmail
Working on functionality for managecourses
138
		}
52.1.1 by b11johgu
Added controllers for examplepage, templatelayout.
139
	}
140
?>