-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
451 lines (394 loc) · 15.2 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
session_start();
require_once("cookie.php");
require_once("functions.php");
// gets the cookie for auto login feature and decrypt it for use
if(!isset($_SESSION['primaryId']) && isset($_COOKIE[$CFG->cookiename]) && isset($CFG->cookiepad) && $CFG->cookiepad !== false){
$encCookie = $_COOKIE[$CFG->cookiename];
$decCookie = extract_secure_cookie($encCookie);
if($decCookie === false ) {
die('Decryption failed:'.$encCookie);
delete_secure_cookie();
}
$cookie_primaryId = $decCookie[0]+0;
if($cookie_primaryId < 0){
$cookie_primaryId = false;
$decCookie = false;
die("Auto login information is corrupt");
}else{
// check if the p_primary is the same as the one in the db
require_once("connect.php");
dbconnect();
$isThisValidId = mysql_real_escape_string($cookie_primaryId);
$query = "SELECT * FROM CT_User WHERE id = $isThisValidId;";
$result = mysql_query($query, $connect);
if(!$result){
die("No match found. This user no longer exists.");
delete_secure_cookie();
}else{
$data = mysql_fetch_array($result);
if($decCookie[1] != md5($data['userPw'])){
die("Corrupt identity!");
delete_secure_cookie();
}else{
$_SESSION['primaryId'] = $decCookie[0];
$_SESSION['userIdentity'] = $decCookie[1]; // used for authorization
$_SESSION['firstName'] = $data['firstName'];
$_SESSION['lastName'] = $data['lastName'];
$_SESSION['userEmail'] = $data['userEmail'];
$_SESSION['level'] = $data['level'];
dbclose();
}
}
}
}
// finds out which login mode is used and send appropriate parameters to login.php
if(isset($_GET['loginType'])){
$loginType = $_GET['loginType'];
if($_GET['loginType'] == 1){
if(isset($_GET['keepSignedIn'])){
$kSI = $_GET['keepSignedIn'];
}else{
$kSI = 0;
}
}
echo("<script>location.href='login.php?loginType=".$loginType."&keepSignedIn=".$kSI."';</script>");
}
if(isset($_POST['loginType'])){
$loginType = $_POST['loginType'];
if($_POST['loginType'] == 2){
if(isset($_POST['keepSignedInN'])){
$kSI = $_POST['keepSignedInN'];
}else{
$kSI = 0;
}
}
$_SESSION['inputEmail'] = $_POST['userEmail'];
$_SESSION['inputPw'] = md5($_POST['userPw']);
echo("<script>location.href='login.php?loginType=".$loginType."&keepSignedIn=".$kSI."';</script>");
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Common Time - Sharing the worlds' public domain music</title>
<script src="./assets/libraries/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script src="./ct.js"></script>
<link href='http://fonts.googleapis.com/css?family=Kotta+One|Raleway:400|Average' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="./assets/style.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
</head>
<body>
<div class="page">
<div id="bg"></div>
<div class="top_nav">
<div class="topmenus">
<ul>
<li id="aboutPage">About</li>
<div id="signUp">
<div id="signUp_header"><br>Sign Up</div>
<div id="signUp_body">
<form id="FormSignUp" method="post" action="signup.php" data-ajax="false">
<div id="notifier">Notifier</div>
<input type="text" name="new_firstName" id="new_firstName" data-mini="true" placeholder="Your first name"><input type="text" data-mini="true" id="new_lastName" name="new_lastName" placeholder="Your last name">
<input type="text" data-mini="true" id="new_Email" name="new_Email" placeholder="Enter your email address">
<input type="password" data-mini="true" id="new_Pw" name="new_Pw" placeholder="Set your password">
<input type="password" data-mini="true" id="new_Pw_verify" name="new_Pw_verify" placeholder="Enter your password again">
<input type="hidden" name="loginType" value=2>
<input type="submit" id="FSU_submit" value="Sign up" ><input type="button" value="Cancel" onclick='$("#signUp").fadeOut(300);'>
</form>
</div>
</div>
<?php
if(!isset($_SESSION['primaryId']) || $_SESSION['primaryId'] == ''){
echo('
<li id="loginW">Sign in via Google</li>
<div id="loginWindow">
<div id="formComponents">
<form id="Form_keepSigned" action="index.php" method="get" data-ajax="false">
<input type="checkbox" name="keepSignedIn" value=1 id="keepSignedIn" data-role="none">
<input type="hidden" name="loginType" value=1> <!-- value 1 for openID Login, value 2 for traditional Login -->
<label for="keepSignedIn">Keep me signed in</label>
</form>
</div>
</div>
<li id="loginWN">Sign in</li>
<div id="loginWindowN">
<div id="formComponentsN">
<form id="Form_keepSignedN" action="index.php" method="post" data-ajax="false">
<input type="text" name="userEmail" placeholder="Email"><input type="password" placeholder="Password" name="userPw">
<input type="checkbox" name="keepSignedInN" value=1 id="keepSignedInN" data-role="none">
<label for="keepSignedInN">Keep me signed in</label>
<input type="hidden" name="loginType" value=2> <!-- value 1 for openID Login, value 2 for traditional Login -->
<div data-role="fieldcontain">
<input type="submit" id="normal_signin" value="Sign in"><input type="button" id="normal_signup" value="Sign up"><input type="button" id="normal_help" value="Help!">
</div>
</form>
</div>
</div>
');
}else{
echo("<li id='logOut'>Log out</li>");
echo("<li id='userPanel'>".$_SESSION['firstName']."</li>");
echo("<li id='upload' onclick=location.href='upload.php'>Upload a score</li>");
}
// count how many scores & users are registered
/*
dbconnect();
$totalScoresQuery = "SELECT COUNT(*) FROM CT_Score WHERE 1;";
$totalUsersQuery = "SELECT COUNT(*) FROM CT_User WHERE 1;";
$resultTotalScores = mysql_query($totalScoresQuery, $connect);
$resultTotalUsers = mysql_query($totalUsersQuery, $connect);
$dataTotalScores = mysql_fetch_array($resultTotalScores);
$dataTotalUsers = mysql_fetch_array($resultTotalUsers);
$totalScores = $dataTotalScores[0];
$totalUsers = $dataTotalUsers[0];
dbclose();
*/
?>
</ul>
</div>
<div id="notification_main"></div>
</div>
<div class="main_layout">
<div class="main_center">
<span id="logotitle">
Common Time</span><br><span id="logoheader">Sharing the world's public domain music<br><br></span>
<form id="searchForm" method="get" action="browse.php" data-ajax="false" >
<div class="t1">
<select id="srchType" name="srchType" data-inline="true" data-corners="false">
<option value="title">Title</option>
<option value="genre">Genre</option>
<option value="composer">Composer</option>
<option value="composeYear">Compose year</option>
<option value="publishYear">Publish year</option>
<option value="instrumentation">Instrumentation</option>
<option value="tag">Tag</option>
</select>
</div>
<div class="t2">
<input data-inline="true" type="text" id="keyword" name="keyword" placeholder="Type in keywords here">
</div>
<div class="t3">
<a data-role="button" onclick="$('#searchForm').submit()" id="submit">Search</a>
</div>
</form>
<br>
<div class="mostList" id="pop"><div class="moreBtn">more</div>
<span class="mostListHeader">Most Popular</span>
<ul>
<?php
dbconnect();
$query = "SELECT * FROM CT_Score ORDER BY id DESC;";
$result = mysql_query($query, $connect);
while($data=mysql_fetch_array($result)){
if(strlen($data['title'])>30){
$title = substr($data['title'], 0, 30)."...";
}else{
$title = $data['title'];
}
echo('<li class="most" style="cursor: pointer" data-link='.htmlentities($data['id']).'>'.htmlentities($title).'</li>');
}
?>
</ul>
</div>
<div class="mostList" id="rec"><div class="moreBtn">more</div>
<span class="mostListHeader">Most Recent</span>
<ul>
<?php
dbconnect();
$query = "SELECT * FROM CT_Score ORDER BY id DESC;";
$result = mysql_query($query, $connect);
while($data=mysql_fetch_array($result)){
if(strlen($data['title'])>30){
$title = substr($data['title'], 0, 30)."...";
}else{
$title = $data['title'];
}
echo('<li class="most" style="cursor: pointer" data-link='.htmlentities($data['id']).'>'.htmlentities($title).'</li>');
}
?>
</ul>
</div>
<br><div class="tagList">
<span class="tagListHeader">Tags</span>
<?php
dbconnect();
$queryTags = "SELECT tag FROM CT_ScoreTag;";
$resultTags = mysql_query($queryTags, $connect);
$tagCounter = 0;
while($dataTags = mysql_fetch_array($resultTags)){
echo("<span class='tags' data-link='browse.php?srchType=tag&keyword=".$dataTags['tag']."'>".htmlentities($dataTags['tag'])."</span>");
$tagCounter++;
}
?>
</div>
</div>
</div>
</div>
<?php
/* displayes errors */
if(isset($_SESSION['error'])){
echo("<script>
$('#notification_main').removeClass('success');
$('#notification_main').html('".$_SESSION['error']."').show();
setTimeout(function(){
$('#notification_main').fadeOut(300);
}, 2000);
</script>");
unset($_SESSION['error']);
}
if(isset($_SESSION['success'])){
echo("<script>
$('#notification_main').addClass('success');
$('#notification_main').html('".$_SESSION['success']."').show();
setTimeout(function(){
$('#notification_main').fadeOut(300);
}, 2000);
</script>");
unset($_SESSION['success']);
}
?>
<script>
// should be exported to a separate JS file
var signUpWidth;
$('#FSU_submit').click(function(e){
var firstName = $('#new_firstName').val();
var lastName = $('#new_lastName').val();
var Email = $('#new_Email').val();
var Pw = $('#new_Pw').val();
var Pw_verify = $('#new_Pw_verify').val();
if(firstName == ''){ $('#notifier').html('First name field is empty!').show(); $('#new_firstName').focus(); e.preventDefault(); }
if(lastName == ''){ $('#notifier').html('Last name field is empty!').show(); $('#new_lastName').focus(); e.preventDefault(); }
if(Email == ''){ $('#notifier').html('Email field is empty!').show(); $('#new_Email').focus(); e.preventDefault(); }
if(Pw == ''){ $('#notifier').html('Password field is empty!').show(); $('#new_Pw').focus(); e.preventDefault(); }
if(firstName && lastName && Email && Pw){
if(Pw !== Pw_verify){
$('#notifier').html('Password fields do not match!').show(); $('#new_Pw_verify').focus(); e.preventDefault();
}else{
$('#FormSignUp').submit();
e.preventDefault();
}
}
});
$(window).resize(function(){
signUpWidth = $('#signUp').css('width').toString().substr(0,$('#signUp').css('width').toString().length-2);
signUpHeight = $('#signUp').css('height').toString().substr(0,$('#signUp').css('height').toString().length-2);
signUpWidth = parseInt(signUpWidth);
signUpHeight = parseInt(signUpHeight);
$('#signUp').css({'right': ((window.innerWidth - signUpWidth-50)/2)+'px', 'top': ((window.innerHeight - signUpHeight)/2)+'px'});
});
$(document).ready(function(){
var availableTags = [];
//// TEMP ////
$('#pop ul li:first').click(function(){
location.href='browse.php';
});
$('#pop ul li:first').css('cursor', 'pointer');
///
/*
$('#keyword').click(function(){
if($(this).val() == 'Type in keywords here'){
$(this).css({'color': '#000000'}).val('');
}
});
*/
/* logo title */
$('#logotitle').click(function(){
location.href="index.php";
});
/* popup context menu handlers */
$('#loginW').on('mouseenter', function(){
$('#loginWindow').show();
$('#loginWindowN').hide();
});
$('#loginW').on('mouseleave', function(){
$('#loginWindow').mouseenter(function(){
$('#loginWindow').show();
});
$('.main_layout').mouseenter(function(){
$('#loginWindow').hide();
});
});
$('#loginWN').on('mouseenter', function(){
$('#loginWindowN').show();
$('#loginWindow').hide();
});
$('#loginWN').on('mouseleave', function(){
$('#loginWindowN').mouseenter(function(){
$('#loginWindowN').show();
});
$('.main_layout').mouseenter(function(){
$('#loginWindowN').hide();
});
});
/* adjusts the location of the signup window based on the current size of the window */
signUpWidth = $('#signUp').css('width').toString().substr(0,$('#signUp').css('width').toString().length-2);
signUpHeight = $('#signUp').css('height').toString().substr(0,$('#signUp').css('height').toString().length-2);
signUpWidth = parseInt(signUpWidth);
signUpHeight = parseInt(signUpHeight);
$('#signUp').css({'right': ((window.innerWidth - signUpWidth-50)/2)+'px', 'top': ((window.innerHeight - signUpHeight)/2)+'px'});
/* sign in/up and help event handlers */
$('#loginW').mouseup(function(){
$('#Form_keepSigned').submit();
});
$('#Form_keepSignedN').submit(function(e){
$(this).submit();
e.preventDefault();
});
$('#normal_signup').click(function(){
$('#signUp').fadeIn(300);
$('#loginWindowN').hide();
});
$('#userPanel').click(function(){
location.href='mypage.php';
});
$('#logOut').click(function(){
location.href='logout.php';
});
$('.tags').click(function(){
location.href=$(this).attr('data-link');
});
$('#keyword').keyup(function(){
$.ajax({
async: false,
url: 'retrieve.php',
data: {'mode': 1, 'srchType': $('#srchType').val(), 'keyword': $('#keyword').val()},
success: function(data){
availableTags = [];
var jdata = eval("("+data+")");
for(var i in jdata){
availableTags.push(jdata[i][0]);
}
}
});
});
$('.most').click(function(){
location.href="view.php?id="+$(this).attr("data-link");
});
$('.moreBtn').click(function(){
location.href="browse.php";
});
$('#aboutPage').click(function(){
location.href='about.php';
});
$(document).ajaxSuccess(function(){
$('#keyword').autocomplete({
source: availableTags
});
});
// on keydown on the keyword area, initiate the tag retrieval process, and once the process is done, launch the autocomplete process
// test
/*
$('#keyword').autocomplete({
source: availableTags,
});
*/
});
</script>
</body>
</html>