-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.js
86 lines (68 loc) · 2.73 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var bodyParser = require("body-parser");
var urlEncodedParser = bodyParser.urlencoded({extended: false});
var path = require("path");
var express = require("express");
var app = express();
var mysql = require("mysql");
module.exports =
{
Dashboard : function(connection, req, response)
{
var role = req.session.role;
//console.log("USER ROLE: ", role);
if (role == 1)
{
connection.query("SELECT * FROM STUDENT WHERE USN = '" + req.session.username + "'", function(err, res, fields){
//console.log(res);
if(res.length == 0) {
console.log("Error 1");
console.log(res);
response.sendFile("unauthorised.html", { root: path.join(__dirname, 'templates') });
//return 0;
} else {
var testq = "SELECT * FROM TEST WHERE TESTDATE > 2000-01-01";
connection.query(testq, function(error, result){
if (error)
{
throw error;
}
else
{
response.render('dashboard_stu', {
Details: res[0],
Tests: result
});
}
});
}
});
}
else if (role == 2 || role == 3)//faculty
{
connection.query("SELECT * FROM FACULTY WHERE FACULTYID = '" + req.session.username + "'", function(err, res, fields){
console.log(res);
if(res.length == 0) {
console.log("Error 1");
console.log(res);
response.sendFile("unauthorised.html", { root: path.join(__dirname, 'templates') });
//return 0;
} else {
var dept;
connection.query("SELECT * FROM DEPARTMENT WHERE DEPARTMENTID = '" + res[0].DepartmentID + "';", function(errid, resid){
if(errid) throw errid;
else dept = resid[0].Name;
response.render('dashboard_fac', {
ID: res[0].FacultyID,
//FirstName: res[0].FirstName,
//LastName: res[0].LastName,
Name: res[0].Name,
EmailID: res[0].EmailID,
MobileNumber: res[0].MobileNumber,
Department: dept
});
});
}
});
}
}
}