-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#index.php#
195 lines (176 loc) · 7.27 KB
/
#index.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
include("pages/config.lib.php");
global $loggedIn;
if(isset($_SESSION['emailId']))
$loggedIn = 1;
?>
<html>
<title>Status App</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="./css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="./css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./scripts/jquery.js"></script>
<script type="text/javascript" src="./scripts/jquery-2.0.0.min.js"></script>
<script src="./scripts/bootstrap.min.js"></script>
<script type='text/javascript'>
var statusArray = new Array();
var timeArray = new Array();
function statusHide(emailId){
var divId = emailId.replace(/[@.]/g,"");
$('#'+divId+"Statuses").empty();
document.getElementById(divId+"link").onclick = function(){listStatuses(emailId);};
}
function listStatuses(emailId){
var divId = emailId.replace(/[@.]/g,"");
$.ajax({
url :'pages/listUserStatus.php',
type : 'post',
data : {'emailId' : emailId} ,
success:function(data){
statusArray = data.split(';');
$('#'+divId+"Statuses").append("<br/><table align = 'center' id='"+divId+"Table'></table>");
$('#'+divId+"Table").append("<tr><td align='center'><pre>Status</pre></td><td align='center'><pre>Time</pre></td></tr>");
for(var i=0;i<statusArray.length;i++){
timeArray = statusArray[i].split("#");
$('#'+divId+"Table").append("<tr><td align='center'><pre>"+timeArray[0]+"</pre></td><td align='center'><pre>"+timeArray[1]+"</pre></td></tr>");
}
$('#'+divId+"Statuses").append("<br/><br/>");
document.getElementById(divId+"link").onclick = function(){statusHide(emailId);}
}
});
}
function seniority(){
$.ajax({
url :'pages/checkSeniority.php',
type : 'get',
success : function(data){
console.log(data);
if(data!=""){
if(data=="minor")
minorYear();
else{
$('#userDataList').append("<h4>List of Active 2nd Years</h4>");
$('#userDataList').append(data);
}
}
}
});
}
function minorYear(){
$('#statusDiv').append("<br/><br/><div>What's your curent status ? <input id = 'curStatus' type ='text' /><button id='submit' onclick = 'uploadStatus()'>Submit</button></div><br/><div id ='message'></div>");
listCurrentStatus();
}
function listCurrentStatus(){
$.ajax({
url : 'pages/listCurrentStatus.php',
type : 'get',
success : function(data){
if(data!=''){
$('#userDataList').empty();
$('#userDataList').append("<br/><h4>My Current Status</h4><br/><table align='center'><tr><td style='text-align:left'><pre>Status</pre></td><td style='text-align:left'><pre>Time</pre></td>");
var timeArray = data.split('#');
$('#userDataList').append("<tr><td style='text-align:left'><pre>"+timeArray[0]+"</pre></td><td style='text-align:left'><pre>"+timeArray[1]+"</pre></td></tr></table>");
}
}
});
}
function uploadStatus(){
console.log($('#curStatus').val());
var statusValue = encodeURI($('#curStatus').val());
$.ajax({
url : 'pages/uploadStatus.php',
type : 'post',
data : { 'status' : statusValue},
success : function(data){
$('#message').empty();
$('#message').append(data);
listCurrentStatus();
}
});
};
function registration(){
console.log($('#year').val());
$.ajax({
url: './pages/registration.php',
type: 'post',
data: {'firstName': $('input[name=firstName]').val(), 'lastName': $('input[name=lastName]').val(),'emailId':$('input[name=emailId]').val(), 'regPassword':$('input[name=regPassword]').val(), 'confPassword':$('input[name=confPassword]').val(), 'year': $('#year').val()},
success: function(data){
if(data=='Success!'){
window.location = "./";
$('#registrationForm').empty();
}
else{
$('#errorMessage').empty();
$('#errorMessage').append(data);
}
}
});
}
function login(){
$.ajax({
url: './pages/login.php',
type: 'post',
data: {'emailId':$('input[name=username]').val(), 'password':$('input[name=password]').val()},
success: function(data){
if(data){
$('#loginErrorMessage').empty();
$('#loginErrorMessage').append(data);
}
else{
window.location = "./";
$('#loginForm').empty();
}
}
});
}
function logout(){
$.ajax({
url : 'pages/logout.php'
});
$('#logged').empty();
$('#statusDiv').empty();
$('#userDataList').empty();
$('#logged').append("<div id=''><a href='#myModalRegister' role='button' class='btn btn-primary' data-toggle='modal'> REGISTER </a> <a href='#myModalLogin' role='button' class='btn btn-primary' data-toggle='modal'> LOGIN </a></div>");
}
</script>
</head>
<body>
<?php
if($loggedIn==1 && $_SESSION['views']==1){
echo "<div id='logged'>Hello!".$_SESSION['emailId']." <a href='javascript:void' onclick = 'logout()'>Logout</a></div>";
$_SESSION['views']++;
}
else if($loggedIn==1 && $_SESSION['views']!=1){
echo "<div id='logged'>".$_SESSION['emailId']." <a href='javascript:void' onclick = 'logout()'>Logout</a></div>";
$_SESSION['views']++;
}
else
echo "<div id=''><a href='#myModalRegister' role='button' class='btn btn-primary' data-toggle='modal'> REGISTER </a> <a href='#myModalLogin' role='button' class='btn btn-primary' data-toggle='modal'> LOGIN </a></div>";
if($loggedIn==1){
echo"<script type='text/javascript'>seniority()</script>";
}
?>
<?php
if(isset($_SESSION['emailId']))
echo "<!-- Registration Modal --><div align='center'><div class='logReg' id='regForm'><table id='regFormDetails'><tr> <td class='inputFields'> First Name </td> <td class='inputValues'><input name='firstName' type='text' /> </td> </tr><tr> <td class='inputFields'> Last Name </td> <td class='inputValues'><input name='lastName' type='text' /> </td> </tr><tr> <td class='inputFields'> Email Id </td> <td class='inputValues'><input name='emailId' type='email' /> </td> </tr> <tr> <td class='inputFields'> Choose Password </td> <td class='inputValues'><input name='regPassword' type='password' /> </td> </tr>
<tr> <td class='inputFields'> Confirm Password </td> <td class='inputValues'><input name='confPassword' type='password' /> </td> </tr> <tr> <td class='inputFields'> Year </td> <td class='inputValues'><select id='year'> <option value=""> </option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> </select></td> </tr></table><button onclick='registration()'>Register</button>
</div>
<div id='errorMessage'></div>
</div>
<!-- Login Modal -->
<div align='center'>
<div class='logReg' id='loginForm'>
<div>
<input name='username' type='text' placeholder='Username' />
<br/><input name='password' type='password' placeholder='Password' />
</div>
<button onclick='login()'>Login</button><div id='loginErrorMessage'></div></div>
";
?>
<div id = 'statusDiv'></div>
<div id='userDataList'></div>
</body>
</html>