-
Notifications
You must be signed in to change notification settings - Fork 0
/
navbar.php
224 lines (182 loc) · 7.29 KB
/
navbar.php
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
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Online Teaching</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="Dependencies/jquery-3.2.1.min.js"></script>
<script src="Dependencies/bootstrap-4.0.0/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" type="text/css" href="Dependencies/bootstrap-4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="Dependencies/font-awesome-4.7.0/css/font-awesome.min.css">
<style>
.required {
border: 2px solid red;
}
.visible{
visibility: visible;
}
.nodisplay{
display: none;
}
</style>
<script>
var xhr = new XMLHttpRequest();
function authentificate(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if(!validateAuthentification(username,password)){return;}
$("#modalLogin").addClass('disabled');
$("#modalLogin").html("<i class='fa fa-circle-o-notch fa-spin'></i> Loading")
xhr.onreadystatechange = doAuthentification;
xhr.open("post","authentificate.php",true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send("username="+username+"&password="+password);
}
function doAuthentification(){
//alert(xhr.readyState + "-" + xhr.status);
if(xhr.readyState==4 && xhr.status==200){
result = xhr.responseText;
if (result < 0){
//alert(result);
$("#credentialMessage").addClass('visible');
document.getElementById("password").value = "";
}
else {
//alert(result);
//succesfully logged in
$("#credentialMessage").removeClass('visible');
$("#modalLogin").html("Login");
$(".before-login").addClass('nodisplay');
$(".after-login").removeClass('nodisplay');
$("#modalLogin").removeClass('disabled');
$(".modal .close").click()
var sessionTypeId = $.ajax({type: "GET", url: "sessionType.php", async: false}).responseText;
//alert(sessionTypeId);
if (sessionTypeId == 1){
$("#courseManagement").removeClass('nodisplay');
}
//$.get("sessionWrite.php?id="+result);
//var msg = $.ajax({type: "GET", url: "sessionRead.php", async: false}).responseText;
//alert(msg);
}
$("#modalLogin").html("Login");
$("#modalLogin").removeClass('disabled');
}
}
function validateAuthentification(username,password){
flag = true;
$("#username").removeClass('required');
$("#password").removeClass('required');
if(username == ""){
$("#username").addClass('required');
flag = false;
}
if(password == ""){
$("#password").addClass('required');
flag = false;
}
return flag;
}
function disconnect(){
$(".before-login").removeClass('nodisplay');
$(".after-login").addClass('nodisplay');
window.location.replace("index.php");
$.get("disconnect.php");
}
function ifLoggedIn(){
var id = $.ajax({type: "GET", url: "sessionRead.php", async: false}).responseText;
//alert(id);
if( id > 0){
$(".before-login").addClass('nodisplay');
$(".after-login").removeClass('nodisplay');
}
var sessionTypeId = $.ajax({type: "GET", url: "sessionType.php", async: false}).responseText;
//alert(sessionTypeId);
if (sessionTypeId == 1){
$("#courseManagement").removeClass('nodisplay');
}
}
</script>
<script>
jQuery(document).ready(function($){
$('.card h4').each(function(){
$(this).attr('data-search-term', $(this).text().toLowerCase());
});
$('.live-search-box').on('keyup', function(){
var searchTerm = $(this).val().toLowerCase();
$('.card h4').each(function(){
if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
$(this).parents('.card').removeClass('nodisplay');
} else {
$(this).parents('.card').addClass('nodisplay');
}
});
});
});
</script>
</head>
<body onload="ifLoggedIn()">
<!-- Navbar -->
<div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.php">
<img src="Dependencies/Images/OnlineTeaching_Logo.svg" alt="OnlineTeaching_Logo"/>
<span>Online Teaching</span>
</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<div class="input-group">
<input class="form-control live-search-box" type="search" placeholder="Search">
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>
</li>
<li class="nav-item before-login"><a class="nav-link" data-toggle="modal" href="#loginModal"><span class="fa fa-sign-in"></span> Login</a></li>
<li class="nav-item before-login"><a class="nav-link" href="signUp.php"><span class="fa fa-user-plus"></span> Sign Up</a></li>
<li class="dropdown after-login nodisplay" style="margin-right: 3rem;">
<a class="nav-link" data-toggle="dropdown" href="#"><i class="fa fa-user-circle fa-lg"></i> Profile</a>
<ul class="dropdown-menu">
<!-- Follow up of done courses not implemented yet -->
<li class="nodisplay"><a href="#"><i class="fa fa-user"></i> My Profile</a></li>
<li id="courseManagement" class="nodisplay"><a href="courseManagement.php"><i class="fa fa-pencil"></i> Manage Courses</a></li>
<li class="dropdown-divider"></li>
<li><a href="#" onclick="disconnect()"><i class="fa fa-power-off"></i> Disconnect</a></li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
<!-- Modal Login-->
<div>
<div class="modal fade" id="loginModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Authentification</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Username:</label>
<input type="text" class="form-control" id="username" placeholder="Enter username" name="username">
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password">
</div>
</div>
<div class="modal-footer">
<div class="w-100 text-center">
<p style="color: red; visibility: hidden;" id="credentialMessage">Invalid Credentials</p>
<button type="button" class="btn btn-primary" id="modalLogin" onclick="authentificate()">Login</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>