/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
78.1.1 by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3
class ViewStudentsController extends CI_Controller {
4
83.2.14 by elof.bigestans at gmail
* Started work on the viewStudents functionality... So far, displaying users works and it outputs correct and standardized html.
5
	public function index() {
6
		$this->load->model('user');
7
		$this->load->model('admin/admin_model');
8
83.2.15 by elof.bigestans at gmail
Continuing work on viewstudents
9
		if(!$this->user->isLoggedIn() || $this->user->getUserType() != "Teacher") {
10
			echo "You do not have access to this page.";
11
			return;
12
		}
13
83.2.14 by elof.bigestans at gmail
* Started work on the viewStudents functionality... So far, displaying users works and it outputs correct and standardized html.
14
		// NOTE: viewstudents is a deprecated model. Should eventually be replaced by a proper model
15
		$this->load->model('viewstudents');
16
17
		$userName = $this->user->getUserName();
18
		$userType = $this->user->getUserType();
19
		
20
		//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
21
		$headTagData = array(
22
			'cssFiles' => array('bannermenu', 'sidemenu', 'dummieContent', 'viewStudents', 'body'),//cms tillfällig sida
23
			'jsFiles' => array('bannermenu', 'viewStudents')
24
		);
25
		
26
		//Puts the array above in <head></head>
27
		$this->load->view('headTag', array('headTagData' => $headTagData));	
28
29
		$students = $this->viewstudents->getStudents();
30
		
31
		$this->load->view('viewStudentsBody', array('students' => $students));
32
	}
33
83.2.15 by elof.bigestans at gmail
Continuing work on viewstudents
34
	public function editStudentDetails() {
78.1.1 by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it
35
		$this->load->model('user');
83.2.15 by elof.bigestans at gmail
Continuing work on viewstudents
36
		if(!$this->input->post('username') || !$this->user->isLoggedIn()) {
37
			echo "You do not have access to this page";
38
			return;
78.1.1 by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it
39
		}
40
83.2.15 by elof.bigestans at gmail
Continuing work on viewstudents
41
		
78.1.1 by Johan Gustavsson
added controller, model and view for View students, so that next imp can continue on it
42
	}
43
	
44
	public function validate() {
45
		//Load required library
46
		$this->load->library('form_validation');
47
		
48
		//Sets validation rules
49
		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
50
		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
51
		
52
		//Run validation
53
		if($this->form_validation->run() == FALSE) {
54
			//Field validation failed. Display login form (with error message).
55
			$this->drawLoginForm(validation_errors());
56
		} else {
57
			$username = $this->input->post('username');
58
			$password = $this->input->post('password');
59
			
60
			//Try to login
61
			if ($this->user->login($username, $password)) {
62
				redirect(base_url().'home', 'refresh');
63
			} else {
64
				$this->drawLoginForm('Access denied!');
65
			}
66
		}
67
	}
68
	
69
}
70
71
/* End of file ExamplesController.php */
72
/* Location: ./application/controllers/ExamplesController.php */