-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
211 lines (187 loc) · 8.7 KB
/
Copy pathindex.php
File metadata and controls
211 lines (187 loc) · 8.7 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php include "base.php"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Gonzaga Small Talk</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Header File -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style>
body{
background: url(Media/GonzagaBackground.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: auto;
}
a{
color:white;
text-decoration: underline;
}
</style>
</head>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
// let the user access the main page
if ($_SESSION['Role'] == 'Admin')
{
?>
<meta http-equiv='refresh' content='0;/Admin/Home/' />
<?php
}
elseif ($_SESSION['Role'] == 'Student')
{
?>
<meta http-equiv='refresh' content='0;/Student/Home/' />
<?php
}
elseif ($_SESSION['Role'] == 'Teacher')
{
?>
<meta http-equiv='refresh' content='0;/Teacher/Home/' />
<?php
}
?>
<?php
/*
<h1>Gonzaga Smalltalk</h1>
<p>You are currently logged in as <code><?=$_SESSION['Username']?></code> your email: <code><?=$_SESSION['EmailAddress']?></code>. Redirecting to your home page</p>
<a href="logout.php">Logout</a>
*/
?>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
// let the user login //mssql_escape may cause problems with md5()
$username = $_POST['username'];
$password = md5($_POST['password'] . $salt);
$loginquery = "
SELECT DISTINCT SU.[user_id], SU.[username], SU.[password], SU.[date_added], R.[Role], R.[Type], R.[Designation], SU.firstname, SU.lastname
FROM SiteUsers as SU, RoleInstances as RI, Roles as R
WHERE SU.username = ? AND
SU.[password] = ? AND
RI.SiteUsername = SU.username AND
RI.Priority = 'Default' AND
R.RoleID = RI.RoleID";
$params = array($username, $password, $username);
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET);
$checklogin = sqlsrv_query($con, $loginquery, $params, $options);
if(sqlsrv_num_rows($checklogin) == 1)
{
$row = sqlsrv_fetch_array($checklogin);
$role = $row['Role'];
$_SESSION['Username'] = $username;
$_SESSION['LoggedIn'] = 1;
$_SESSION['Role'] = $role;
$_SESSION['AccessType'] = $row['Type'];
$_SESSION['Designation'] = $row['Designation'];
$_SESSION['UserID'] = $row['user_id'];
$_SESSION['firstname'] = $row['firstname'];
$_SESSION['lastname'] = $row['lastname'];
if ($role == 'Admin')
{
$params = array($username);
$options = array( "Scrollable" => 'static');
$query = "SELECT A.FirstName, A.LastName, A.Email, I.InstitutionName FROM Administrators as A, Institutions as I WHERE A.SiteUsername = ? AND I.InstitutionID = A.InstitutionID";
$stmt = sqlsrv_query($con, $query, $params, $options);
if ($stmt === false)
die( print_r( sqlsrv_errors(), true));
if (sqlsrv_fetch($stmt) === true)
{
$first_name = sqlsrv_get_field( $stmt, 0);
$last_name = sqlsrv_get_field( $stmt, 1);
$email = sqlsrv_get_field( $stmt, 2);
$institution = sqlsrv_get_field( $stmt, 3);
$_SESSION['Institution'] = $institution;
}
}
elseif ($role == 'Teacher')
{
$params = array($username);
$options = array( "Scrollable" => 'static');
$query = "SELECT FirstName, LastName, Email FROM Teachers WHERE SiteUsername = ?";
$stmt = sqlsrv_query($con, $query, $params, $options);
if ($stmt === false)
die( print_r( sqlsrv_errors(), true));
if (sqlsrv_fetch($stmt) === true)
{
$first_name = sqlsrv_get_field( $stmt, 0);
$last_name = sqlsrv_get_field( $stmt, 1);
$email = sqlsrv_get_field( $stmt, 2);
}
else
echo "Teacher.";
}
elseif ($role == 'Student')
{
$params = array($username);
$options = array( "Scrollable" => 'static');
$query = "SELECT S.FirstName, S.LastName, S.Email, I.InstitutionName FROM Students as S, Institutions as I WHERE SiteUsername = ? and I.InstitutionID = S.InstitutionID";
$stmt = sqlsrv_query($con, $query, $params, $options);
if ($stmt === false)
die( print_r( sqlsrv_errors(), true));
if (sqlsrv_fetch($stmt) === true)
{
$first_name = sqlsrv_get_field( $stmt, 0);
$last_name = sqlsrv_get_field( $stmt, 1);
$email = sqlsrv_get_field( $stmt, 2);
$institution = sqlsrv_get_field( $stmt, 3);
$_SESSION['Institution'] = $institution;
}
}
$_SESSION['EmailAddress'] = $email;
$_SESSION['FirstName'] = $first_name;
$_SESSION['LastName'] = $last_name;
echo "<meta http-equiv='refresh' content='0;/$role/Home/' />";
}
else
{?>
<body>
<div class ="well col-xs-12">
<h1 class="form-signin-heading text-right"><font color="white">Error</font></h1>
<p><font color="white">Sorry, your account could not be found</font></p>
<p><font color="white">Please <a href="/">click here to try again</a></font></p>
<p><font color="white">If you are having trouble accessing your account, contact your administrator</font></p>
</div>
</body>
<?php
}
}
else
{
// display the login form
?>
<!-- <body background="GonzagaBackground.jpg"> -->
<body>
<div class="well col-xs-12 pull-right">
<form class="form-signin" method ="post" action="/" name="loginform" id="loginform">
<h1 class="form-signin-heading text-right"><font color="white">Sign-in</font></h1>
<!--<h4 class="form-signin-heading text-right"><font color="white">Login below or <a href= "register.php">click here to register</a>.</font></h4>-->
<fieldset>
<label for="username" class="sr-only">Username</label>
<input type="text" name="username" id="username" class="form-control" placeholder="Username" required="" autofocus"">
<label for="password" class="sr-only">Password</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required="">
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
</fieldset>
<h4 class="form-signin-heading text-right"><a href="#">Forgot Username?</a></h4>
<h4 class="form-signin-heading text-right"><a href="#">Forgot Password?</a></h4>
<!-- <h4 class="form-signin-heading text-right"><a href="register.php">Register</a></h4> -->
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
<?php
}
?>
</html>