-
Notifications
You must be signed in to change notification settings - Fork 2
/
processformfunctions.php
380 lines (334 loc) · 18.3 KB
/
processformfunctions.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
<?php
function process_searchWord_form($linkFunction = "VIEW"){
$searchWordQuery = "SELECT word.wordID, wordWrittenForm, wordDescription FROM word";
if($_GET['wordSemanticField'] != -2 && $_GET['wordSemanticField'] != ""){
//perform join with word_semanticfield if the criteria include semantic fields
$searchWordQuery .= ", word_semanticfield";
}
$searchWordQuery .= " WHERE wordWrittenForm LIKE '%" . mysql_real_escape_string($_GET['wordWrittenForm']) . "%'" .
" AND wordDescription LIKE '%" . mysql_real_escape_string($_GET['wordDescription']) . "%'" .
" AND etymology LIKE '%" . mysql_real_escape_string($_GET['wordEtymology']) . "%'" ;
if($_GET['wordRoot'] != -2 && $_GET['wordRoot'] != ""){ #-2 is the value used for ANY
$searchWordQuery .= " AND rootID = " . $_GET['wordRoot'];
}
if($_GET['wordLexCat'] != -2 && $_GET['wordLexCat'] != ""){ #-2 is the value used for ANY
$searchWordQuery .= " AND lexicalCategoryID = " . $_GET['wordLexCat'];
}
if($_GET['wordMorphoCat'] != -2 && $_GET['wordMorphoCat'] != ""){ #-2 is the value used for ANY
$searchWordQuery .= " AND morphologicalTypeID = " . $_GET['wordMorphoCat'];
}
if($_GET['wordSemanticField'] != -2 && $_GET['wordSemanticField'] != ""){ #-2 is the value used for ANY
$searchWordQuery .= " AND word_semanticfield.semanticFieldID = " . $_GET['wordSemanticField'];
$searchWordQuery .= " AND word.wordID = word_semanticfield.wordID";
}
if($_GET['wordEnteredBy'] != -2 && $_GET['wordEnteredBy'] != ""){ #-2 is the value used for ANY
$searchWordQuery .= " AND enteredBy = " . $_GET['wordEnteredBy'];
}
if(isSet($_GET['wordAutoGenerated'])){
$searchWordQuery .= " AND isAutoGenerated = 1";
}
if(strcmp($_GET['wordSortBy'], "")==0 || !isSet($_GET['wordSortBy'])){
$_GET['wordSortBy'] = 2;
}
$searchWordQuery .= " ORDER BY " . $_GET['wordSortBy'];
//query is ready; now perform it
$result = mysql_query($searchWordQuery) or die('Query failed: ' . mysql_error() . "QUERY TEXT: " . $searchWordQuery);
//Print results in HTML
echo "<a href=".setValueInURL($_SERVER['REQUEST_URI'], 'wordSortBy', '2').">Sort By IPA</a>";
echo " : ";
echo "<a href=".setValueInURL($_SERVER['REQUEST_URI'], 'wordSortBy', '3').">Sort By Translation</a>";
echo "<br/>";
echo "<table>\n";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "\t<tr>\n";
if(strcmp($linkFunction, "VIEW") == 0){
if($row['wordID'] > -1) echo "\t\t<td><a href=\"".$GLOBALS['baseurl']."/viewword.php?wordID=".$row['wordID']."\">".$row['wordWrittenForm']. " - " . $row['wordDescription']."</a></td>\n";
}
else if(strcmp($linkFunction, "ASSOCIATE") == 0){
if($row['wordID'] > -1) echo "\t\t<td><a href=\"".$GLOBALS['baseurl']."/associatesentenceword.php?wordID=".$row['wordID']."&sentenceID=".$_REQUEST['sentenceID']."&wordSequenceNumber=".$_REQUEST['wordSequenceNumber']."\">".$row['wordWrittenForm']. " - " . $row['wordDescription']."</a></td>\n";
}
else if(strcmp($linkFunction, "SEEALSO") == 0){
if($row['wordID'] > -1) echo "\t\t<td><a href=\"".$GLOBALS['baseurl']."/associatewordword.php?seeAlsoID=".$row['wordID']."&wordID=".$_REQUEST['wordID']."\">".$row['wordWrittenForm']. " - " . $row['wordDescription']."</a></td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
}
function process_searchSentence_form(){
$searchSentenceQuery = "SELECT sentenceID, spokenForm FROM sentence WHERE".
" sentenceDescription LIKE '%" . mysql_real_escape_string($_GET['sentenceDescription']) . "%'" .
" AND SpokenForm LIKE '%" . mysql_real_escape_string($_GET['sentenceSpokenForm']) . "%'" .
" AND analyzedForm LIKE '%" . mysql_real_escape_string($_GET['sentenceAnalyzedForm']) . "%'" .
" AND CloseGloss LIKE '%" . mysql_real_escape_string($_GET['sentenceCloseGloss']) . "%'" .
" AND FreeTranslation LIKE '%" . mysql_real_escape_string($_GET['sentenceFreeTranslation']) . "%'";
if($_GET['sentenceType'] != -2){ #-2 is the value used for ANY
$searchSentenceQuery .= " AND sentenceTypeID = " . $_GET['sentenceType'];
}
if($_GET['sentenceEnteredBy'] != -2 && strcmp($_GET['sentenceEnteredBy'], "") != 0){ #-2 is the value used for ANY
$searchSentenceQuery .= " AND enteredBy = " . $_GET['sentenceEnteredBy'];
}
//query is ready; now perform it
$result = mysql_query($searchSentenceQuery) or die('Query failed: ' . mysql_error());
//Print results in HTML
echo "<table>\n";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "\t<tr>\n";
if($row['sentenceID'] > -1) echo "\t\t<td><a href=\"".$GLOBALS['baseurl']."/viewsentence.php?sentenceID=".$row['sentenceID']."\">".$row['spokenForm']."</a></td>\n";
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
}
function process_addSentence_form(){
$enteredByPersonID = getPersonIDOrCreateNew($_POST['sentenceEnteredBy']);
$spokenByPersonID = getPersonIDOrCreateNew($_POST['sentenceSpokenBy']);
mysql_query("BEGIN");
//First we update the sentence table with the easy stuff
$sentenceUpdateQuery = "INSERT INTO sentence (spokenForm, closeGloss, sentenceDescription, freeTranslation, analyzedForm, session, toDoNotes, enteredBy, spokenBy, sentenceTypeID) VALUES('".
mysql_real_escape_string($_POST['sentenceSpokenForm'])."','".
mysql_real_escape_string($_POST['sentenceCloseGloss'])."','".
mysql_real_escape_string($_POST['sentenceDescription'])."','".
mysql_real_escape_string($_POST['sentenceFreeTranslation'])."','".
mysql_real_escape_string($_POST['sentenceAnalyzedForm'])."','".
mysql_real_escape_string($_POST['sentenceSession'])."','".
mysql_real_escape_string($_POST['sentenceToDo']) . "'," .
$enteredByPersonID . "," .
$spokenByPersonID . "," .
max(mysql_real_escape_string($_POST['sentenceType']), -1) .")";
if(!$result = mysql_query($sentenceUpdateQuery)){echo ('Query failed: ' . mysql_error()) . "QUERY TEXT: " . $sentenceUpdateQuery; mysql_query("ROLLBACK");die();}
$sentenceInsertID = mysql_fetch_array(mysql_query("SELECT LAST_INSERT_ID()"));
$_POST['sentenceInsertID'] = $sentenceInsertID[0];
//Done. Now we update audioFile and move the uploaded file to its home.
doAudioMaintenanceOperations("sentence", $_POST['sentenceInsertID']);
//Done (or unnecessary). Now we update the sentence_tone table.
updateSentenceTone($_POST['sentenceInsertID'], $_POST['sentenceAnalyzedTone']);
//Done (or unnecessary). Now we update the sentence_tone table.
updateSentencePitch($_POST['sentenceInsertID'], $_POST['sentencePitch']);
mysql_query("COMMIT");
}
function process_editSentence_form(){
$enteredByPersonID = getPersonIDOrCreateNew($_POST['sentenceEnteredBy']);
$spokenByPersonID = getPersonIDOrCreateNew($_POST['sentenceSpokenBy']);
mysql_query("BEGIN");
//First we update the sentence table with the easy stuff
$sentenceUpdateQuery = "UPDATE sentence SET spokenForm = '" . mysql_real_escape_string($_POST['sentenceSpokenForm']) .
"', closeGloss = '" . mysql_real_escape_string($_POST['sentenceCloseGloss']) .
"', sentenceDescription = '" . mysql_real_escape_string($_POST['sentenceDescription']) .
"', freeTranslation = '" . mysql_real_escape_string($_POST['sentenceFreeTranslation']) .
"', analyzedForm = '" . mysql_real_escape_string($_POST['sentenceAnalyzedForm']) .
"', toDoNotes = '" . mysql_real_escape_string($_POST['sentenceToDo']) .
"', session = '" . mysql_real_escape_string($_POST['sentenceSession']) .
"', sentenceTypeID = " . max(mysql_real_escape_string($_POST['sentenceType']), -1) .
", enteredBy = " . $enteredByPersonID .
", spokenBy = " . $spokenByPersonID .
" WHERE sentenceID = " . $_POST['sentenceInsertID'];
if(!$result = mysql_query($sentenceUpdateQuery)){echo ('Query failed: ' . mysql_error()) . "QUERY TEXT: " . $sentenceUpdateQuery; mysql_query("ROLLBACK");die();}
//Done. Now we update audioFile and move the uploaded file to its home.
doAudioMaintenanceOperations("sentence", $_POST['sentenceInsertID']);
//Done (or unnecessary). Now we update the sentence_tone table.
updateSentenceTone($_POST['sentenceInsertID'], $_POST['sentenceAnalyzedTone']);
//Done (or unnecessary). Now we update the sentence_pitch table.
updateSentencePitch($_POST['sentenceInsertID'], $_POST['sentencePitch']);
mysql_query("COMMIT");
}
function process_addSentence_form2(){
updateSelectBoxes();
if(isset($_POST['autoNew'])){
//first, remove any existing association for that sentence and SequenceNumber
removeExistingAssociation($_POST['sentenceInsertID'], $_POST['keyWord']);
//now, insert a new, autogen word
insertAutoGenWord();
}
else if(isset($_POST['manualNew'])){
//first, remove any existing association for that sentence and SequenceNumber
removeExistingAssociation($_POST['sentenceInsertID'], $_POST['keyWord']);
//now, insert a new autogen word and encourage the user to edit it
$insertedWordID = insertAutoGenWord();
redirectInNewWindow("editword.php?wordID=".$insertedWordID);
}
else if(isset($_POST['assocExisting'])){
//first, remove any existing association for that sentence and SequenceNumber
removeExistingAssociation($_POST['sentenceInsertID'], $_POST['keyWord']);
//now insert a new row in sentence_word for the association
$sentence_wordInsertQuery = "INSERT INTO sentence_word (sentenceID, wordID, wordSequenceNumber) VALUES (".
$_POST['sentenceInsertID'].",".
$_POST['possibleMatch'].",".
mysql_real_escape_string($_POST['keyWord']).")";
if(!$sentence_wordInsertResult = mysql_query($sentence_wordInsertQuery)){echo ('Query failed: ' . mysql_error()) . " QUERY TEXT: " . $sentence_wordInsertQuery; mysql_query("ROLLBACK");die();}
}
else if(isset($_POST['freeAssociate'])){
//now we must leave the page for a while (either that or have a Java pop-up; ewww!)
redirectInNewWindow("associatesentenceword.php?sentenceID=".$_POST['sentenceInsertID']."&wordSequenceNumber=".$_POST['keyWord']);
}
else if(isset($_POST['disassociate'])){
removeExistingAssociation($_POST['sentenceInsertID'], $_POST['keyWord']);
}
}
function process_manageSeeAlso_form(){
if(isset($_POST['addNew'])){
redirectInNewWindow("associatewordword.php?wordID=" . $_REQUEST['wordID']);
}
else if(isset($_POST['deleteExisting'])){
deleteFromTable2Param("seeAlso", array("wordID" => $_REQUEST['wordID'], "seeAlsoID" => $_REQUEST['seeAlsoList']));
}
}
function process_managewordsemanticfield_form(){
if(isset($_POST['assocExisting'])){
addSemanticFieldToWord($_REQUEST['wordID'], $_POST['semanticField']);
}
else if(isset($_POST['removeSelected'])){
deleteFromTable2Param("word_semanticfield", array("wordID" => $_REQUEST['wordID'], "semanticFieldID" => $_POST['wordSemanticField']));
}
}
function process_manageMorphoCat_form(){
if(isset($_POST['addNew'])){
addNewMorphologicalCategory($_POST['dataEntry']);
}
else if(isset($_POST['editExisting'])){
editExistingMorphologicalCategory($_POST['dataSelection'], $_POST['dataEntry']);
}
else if(isset($_POST['deleteExisting'])){
deleteExistingMorphologicalCategory($_POST['dataSelection']);
}
else if(isset($_POST['freeAssociate'])){
}
}
function process_manageSemanticField_form(){
if(isset($_POST['addNew'])){
addNewSemanticField($_POST['dataEntry']);
}
else if(isset($_POST['editExisting'])){
editExistingSemanticField($_POST['dataSelection'], $_POST['dataEntry']);
}
else if(isset($_POST['deleteExisting'])){
deleteExistingSemanticField($_POST['dataSelection']);
}
else if(isset($_POST['freeAssociate'])){
}
}
function process_manageSentenceType_form(){
if(isset($_POST['addNew'])){
addNewSentenceType($_POST['dataEntry']);
}
else if(isset($_POST['editExisting'])){
editExistingSentenceType($_POST['dataSelection'], $_POST['dataEntry']);
}
else if(isset($_POST['deleteExisting'])){
deleteExistingSentenceType($_POST['dataSelection']);
}
else if(isset($_POST['freeAssociate'])){
}
}
function process_manageLexCat_form(){
if(isset($_POST['addNew'])){
addNewLexicalCategory($_POST['dataEntry']);
}
else if(isset($_POST['editExisting'])){
editExistingLexicalCategory($_POST['dataSelection'], $_POST['dataEntry']);
}
else if(isset($_POST['deleteExisting'])){
deleteExistingLexicalCategory($_POST['dataSelection']);
}
else if(isset($_POST['freeAssociate'])){
}
}
function process_editWord_form(){
$enteredByPersonID = getPersonIDOrCreateNew($_POST['wordEnteredBy']);
$spokenByPersonID = getPersonIDOrCreateNew($_POST['wordSpokenBy']);
mysql_query("BEGIN");
//First we update the word table with the easy stuff
$wordUpdateQuery = "UPDATE word SET ".
"wordWrittenForm = '" . mysql_real_escape_string($_POST['wordWrittenForm'])."', ".
"etymology = '" . mysql_real_escape_string($_POST['wordEtymology'])."', ".
"wordDescription = '" . mysql_real_escape_string($_POST['wordDescription'])."', ".
"lexicalCategoryID = " . max(mysql_real_escape_string($_POST['wordLexCat']), -1) .", ".
"rootID = " . max(mysql_real_escape_string($_POST['wordRoot']), -1) . ", " .
"toDoNotes = '" . mysql_real_escape_string($_POST['wordToDo']) . "', " .
"session = '" . mysql_real_escape_string($_POST['wordSession']) . "', " .
"enteredBy = " . $enteredByPersonID . ", " .
"spokenBy = " . $spokenByPersonID . ", " .
"notes = '" . mysql_real_escape_string($_POST['wordNotes']) . "', " .
"analyzedTone = '" . mysql_real_escape_string($_POST['wordAnalyzedTone']) . "', " .
"morphologicalTypeID = " . max(mysql_real_escape_string($_POST['wordMorphologicalType']), -1) . ", " .
"lastUpdated = sysdate(), " .
"isAutoGenerated = 0" .
" WHERE wordID = " . mysql_real_escape_string($_POST['wordID']);
if(!$wordUpdateResult = mysql_query($wordUpdateQuery)){echo ('Query failed: ' . mysql_error() . "QUERY TEXT: " . $wordUpdateQuery); mysql_query("ROLLBACK"); die();}
doAudioMaintenanceOperations("word", $_POST['wordID']);
if(numQueryResults("SELECT * FROM word_semanticfield WHERE wordID = " . $_POST['wordID']) < 2){
//if the word just has one semantic field, we can assume the user wants Edit Word to overwrite the old with the new
deleteFromTable2Param("word_semanticfield", array("wordID" => $_POST['wordID']));
}
//otherwise if it has more than one, the choice is probably additive in nature
addSemanticFieldToWord($_POST['wordID'], $_POST['wordSemanticField']);
//Done. Now we must determine whether the syllables in this word exist already, or whether they need to be added. If they don't exist, we add them, then we associate them with the word.
doSyllableMaintenanceOperations($_POST['wordID']);
mysql_query("COMMIT");
print "Word successfully updated.";
}
function process_uploadMiscellany_form(){
uploadMiscellaneousFile("miscellaneousFile", "", "miscellany/");
}
function process_addWord_form(){
//Functional overview: 1) Move audio file, if any, to audio file server.
// 2) Update audiofile table, audiofileformat table if necessary. Retain audiofileID for step 3).
// 3) update word table with changes. Retain wordID for step 4).
// 4) update word_syllable and syllable using doSyllableMaintenanceOperations
$enteredByPersonID = getPersonIDOrCreateNew($_POST['wordEnteredBy']);
$spokenByPersonID = getPersonIDOrCreateNew($_POST['wordSpokenBy']);
mysql_query("BEGIN");
//Next we update the word table with the easy stuff
$wordInsertQuery = "INSERT INTO word (wordWrittenForm, etymology, wordDescription, lexicalCategoryID, rootID, toDoNotes, analyzedTone, notes, enteredBy, spokenBy, session, morphologicalTypeID, lastUpdated, isAutoGenerated) VALUES( " .
"'" . mysql_real_escape_string($_POST['wordWrittenForm'])."', ".
"'" . mysql_real_escape_string($_POST['wordEtymology'])."', ".
"'" . mysql_real_escape_string($_POST['wordDescription'])."', ".
max(mysql_real_escape_string($_POST['wordLexCat']), -1) .", ".
max(mysql_real_escape_string($_POST['wordRoot']), -1) . ", " .
"'" . mysql_real_escape_string($_POST['wordToDo']) . "', " .
"'" . mysql_real_escape_string($_POST['wordAnalyzedTone']) . "', " .
"'" . mysql_real_escape_string($_POST['wordNotes']) . "', " .
$enteredByPersonID . ", " .
$spokenByPersonID . ", " .
"'" . mysql_real_escape_string($_POST['wordSession']) . "', " .
max(mysql_real_escape_string($_POST['wordMorphologicalType']), -1) . ", " .
"sysdate(), " .
"0)";
if(!$wordInsertResult = mysql_query($wordInsertQuery)){echo ('Query failed: ' . mysql_error() . " QUERY TEXT: " . $wordInsertQuery); mysql_query("ROLLBACK"); die();}
$wordInsertIDArray = mysql_fetch_array(mysql_query("SELECT LAST_INSERT_ID()"));
$wordInsertID = $wordInsertIDArray[0]; //I wish this intermediary step was not necessary; there may be a better way
//Done. Now we update audioFile and move the uploaded file to its home.
doAudioMaintenanceOperations("word", $wordInsertID);
addSemanticFieldToWord($wordInsertID, max($_POST['wordSemanticField'], -1));
//Done. Now we must determine whether the syllables in this word exist already, or whether they need to be added. If they don't exist, we add them, then we associate them with the word.
doSyllableMaintenanceOperations($wordInsertID);
mysql_query("COMMIT");
print "Word successfully created.";
}
function process_login_form(){
//In this function, we initialize a user's session based on the input of a username and password
//First, query the DB for a valid username match
$pass = getUserPassword($_REQUEST['userName']);
print "<LogonResponse>"; //For CSS
if(strcmp($pass, "") == 0){
//User does not exist
print "We don't have a user like that here. Are you sure you didn't want <a href=\"http://www.40konline.com/community/index.php?board=1.0\">eldar-online</a>?";
}
else if(strcmp($pass, $_REQUEST['passWord']) == 0){
//User exists and password is correct, so set session variable to indicate logged in status
$_SESSION['userName'] = $_REQUEST['userName'];
print "You're now logged in.";
}
else{
//User exists, but password is incorrect
print "Incorrect password for user " . $_REQUEST['userName']. ".";
}
print "</LogonResponse>"; //For CSS
}
function process_registration_form(){
//In this function, we will update a user's password to a new value.
updateTable("person", array("password" => "'".$_POST['passWord']."'"), array("personID" => $_POST['userName']));
}
?>