-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.php
265 lines (235 loc) · 8.95 KB
/
main.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
<?php
require_once "db_login.php";
require_once "globals.php";
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
mysql_select_db($db_database, $db_server);
$loggedin = false;
$userid = -1;
$cookieinfo = explode("%", $_COOKIE['main']);
if ($cookieinfo[0] != null){
$loggedin = true;
$userid = $cookieinfo[0];
}
else{
header( 'Location: http://www.lyricscommander.com' ) ;
}
$query = "SELECT * FROM User WHERE UserID = $userid";
$result = mysql_query($query) or DIE(mysql_error());
$row = mysql_fetch_row($result);
$username = "'" . $row[1] . "'";
$email = "'" . $row[3] . "'";
?>
<html>
<head>
<title>Lyrics Commander</title>
<link rel="stylesheet" type="text/css" href="homestyle.css" />
<script src="_js/jquery-1.7.js"></script>
<script>
var selections = new Array(20); //Selections is which button is pressed
var userID = <?php echo $userid; ?>; //Using the PHP variables from above
var username = <?php echo $username; ?>;
var email = <?php echo $email; ?>;
var stanzaID = -1
var buttonsDown = 0
$(document).ready(function(){
/*=======================================================*/
/*== The Logout Button and its functionality ==*/
/*=======================================================*/
$("#logouttext").click(function(evt){
evt.preventDefault();
$.post("logout.php", function(data){
location.href="index.php";
});
});
$("#logouttext").hover(function(){
$("#logouttext").css("color", "blue");
$("#logouttext").css("font-weight", 700);
}, function(){
$("#logouttext").css("color", "white");
$("#logouttext").css("font-weight", 400);
});
$('#userID').attr('value', userID);
newStanza();
for (i = 0; i < 20; i++) //Clear all the buttons and show the first stanza when the page loads.
selections[i] = 0;
$('#nextinput').submit(function(evt){ //Get a new stanza with AJAX without reloading the page
evt.preventDefault(); //Right now, this doesn't write ratings to the database
addTag();
});
$('.choices').click(function(evt){
evt.preventDefault();
var clickedID = $(this).attr('id');
clickedID = clickedID.substring(6, clickedID.length); //The id would be "button20" so remove the button part
clickedID = parseInt(clickedID); //and make it a number.
if (selections[clickedID - 1] == 0){ //If it wasn't selected.
$(this).css('background-color', '#B6F0E2');
selections[clickedID - 1] = 1;
buttonsDown++;
}
else{
$(this).css('background-color', 'white'); //If it was selected
selections[clickedID - 1] = 0;
buttonsDown--;
}
if (buttonsDown == 0){ //If the user hasn't selected any buttons, they can't go.
$("#nextbutton").attr("disabled", "disabled");
$("#nextbutton").css("color", "#A3A3A3");
}
else if (buttonsDown == 1){
$("#nextbutton").removeAttr("disabled");
$("#nextbutton").css("color", "#000000");
}
});
});
var count = 0; //count is how many stanzas the user has gone through.
var lastArtist = "";
var lastSong = "";
var lastAlbum = "";
function addTag(){
$(".choices").css("background-color", "white");
$("#nextbutton").attr("disabled", "disabled");
$(".choices").attr("disabled", "disabled");
$("#nextbutton").css("color", "#A3A3A3");
//Dynamically build a multiple-tuple insertion query.
var tempStanzaID = stanzaID
var tuples = 0;
var query = "INSERT INTO Rating(StanzaID, WordID, UserID) VALUES";
for (i = 0; i < 20; i++){
if (selections[i] == 1){
var wordID = i + 1
tuples++;
if (tuples == 1)
query += "(" + tempStanzaID + ", " + wordID + ", " + userID + ")"
else
query += ", (" + tempStanzaID + ", " + wordID + ", " + userID + ")"
}
}
if (tuples != 0){ //Making sure there's no JavaScript games.
$('#query').attr('value', query); //Store the query in a hidden form and pass it to the script.
query = $('#hiddentag').serialize();
$.post("addtag.php", query, function(data){
if (data != "success")
alert("There has been an error, please e-mail [email protected]\n" + data);
newStanza();
$(".choices").removeAttr("disabled");
buttonsDown = 0;
});
$('#data').attr('value', wordID + "%" + stanzaID);
dataToPost = $('#hiddenpot').serialize();
$.post("addPotentialBuddy.php", dataToPost, function(data){
if (data != "success")
alert("There has been an error, please e-mail [email protected]\n" + data);
});
}
}
function newStanza(){
$('#artist').text(lastArtist);
$('#song').text(lastSong);
$('#album').text(lastAlbum);
var pageVals = $('#hidden').serialize(); //Serialize the form so that it can be passed via AJAX.
$.post("remrows.php", pageVals, function(data){ //Returns the number of unrated stanzas available.
totalRows = parseInt(data); //Now totalRows should be that.
if (totalRows == 0){ //Give an error if no stanzas to show.
alert("You have already seen every lyric we have! Please e-mail [email protected] and let us know so we can add more.");
return;
}
if (totalRows == <?php print ($gl_stanzas - 2) ?>){
alert("Tip: You can select multiple emotions to associate with a lyric (this is the only tip in this app)");
}
rowNo = (Math.floor(Math.random() * (totalRows)))
if (rowNo == totalRows) rowNo = 0; //Pick a random row number from 0 to max - 1.
//All the available rows will be returned and the n'th is used.
$('#rowNo').attr('value', rowNo);
var pageVals = $('#hidden').serialize();
$.post("getstanza.php", pageVals, function(data){
var values = data.split("&");
$('#lyrics').html(values[0]);
stanzaID = values[7];
lastArtist = values[4];
lastSong = values[1];
lastAlbum = values[2];
count++;
for (i = 0; i < 20; i++){
selections[i] = 0;
}
});
});
}
</script>
<head>
<body>
<div id="titlebar">
<span id="titletext" style="cursor: pointer" onclick="window.location='http://www.lyricscommander.com'">Lyrics Commander</span>
<?php
if ($loggedin) echo "<a href='' id='logouttext'>Logout</a>";
?>
</div>
<table id="maintable">
<tr>
<td id="lyricstd">
<div id="lyricsdiv">
<span id="lyrics">
</span>
<br />
</div>
</td>
<td id="choicetd">
<div id="choicediv">
<button id="button1" class="choices">Amused</button>
<button id="button2" class="choices">Angry</button>
<button id="button3" class="choices">Concerned</button>
<button id="button4" class="choices">Confident</button>
<button id="button5" class="choices">Cynical</button>
<button id="button6" class="choices">Depressed</button>
<button id="button7" class="choices">Energetic</button>
<button id="button8" class="choices">Frustrated</button>
<button id="button9" class="choices">Happy</button>
<button id="button10" class="choices">Inspired</button>
<button id="button11" class="choices">Jealous</button>
<button id="button12" class="choices">Lonely</button>
<button id="button13" class="choices">Optimistic</button>
<button id="button14" class="choices">Relaxed</button>
<button id="button15" class="choices">Restless</button>
<button id="button16" class="choices">Sad</button>
<button id="button17" class="choices">Solemn</button>
<button id="button18" class="choices">Superior</button>
<button id="button19" class="choices">Thoughtful</button>
<button id="button20" class="choices">Touched</button>
<br />
<br />
<form method="post" action="main.php" id="nextinput">
<input type="submit" value="Next" disabled="disabled" id="nextbutton"/>
</form>
<br />
<br />
<br />
<br />
<span id="lastsong">
Last Song:
</span>
<br />
<span id="artist">
</span>
<br />
<span id="song">
</span>
<br />
<span id="album">
</span>
</div>
</td>
</tr>
</table>
<!-- These forms hold values generated in the JavaScript functions that are passed by AJAX-->
<form method="post" action="" id="hidden">
<input type="hidden" name="userID" id="userID" value="" />
<input type="hidden" name="rowNo" id="rowNo" value="0" />
</form>
<form method="post" action="" id="hiddentag">
<input type="hidden" name="query" id="query" value="" />
</form>
<form method="post" action="" id="hiddenpot">
<input type="hidden" name="data" id="data" value="" />
</form>
</body>
</html>