-
Notifications
You must be signed in to change notification settings - Fork 0
/
addWord.php
93 lines (83 loc) · 3.85 KB
/
addWord.php
1
<?php header('Content-type: text/html; charset=utf-8'); echo "<center><br>\n"; //Open the database mydb $db = new SQLite3('DatabaseVocabulary.db'); $word = ""; $pronunciation = ""; $translation = ""; $category_id = null; $videos = array(); $results = $db->query('SELECT * FROM temp_word'); while ($row = $results->fetchArray()) { $word_id = $row['word_id']; $word = $row['word']; $pronunciation = $row['pronunciation']; $wordlist_id = $row['wordlist_id']; } echo "<form action='tempSaveWord.php' method='GET'>\n"; echo "<button type='button' onclick='location.href = \"index.php#$word\";'>Cancel</button>\n"; echo "<input type='submit' value='Save'>\n"; echo "<hr width=300>\n"; echo "<script type='text/javascript'>\n"; echo "function addWord() {\n"; echo "if (document.getElementById('file_name') == null) { alert('Select movie_name'); return; }\n"; echo "location.href = 'tempSaveWord.php?word=' + document.getElementById('w').value + '/' + document.getElementById('file_name').value;\n"; echo "}\n"; echo "var videos = [];\n"; echo "var sentences = [];\n"; $results = $db->query('SELECT * FROM temp_video'); while ($row = $results->fetchArray()) { array_push($videos, $row['movie_name'] . '/' . $row['file_name'] ); echo "videos.push('" . $row['movie_name'] . '/' . $row['file_name'] . "');\n"; echo "sentences.push('" . str_replace("\r\n", "\\r\\n", $row['sentence']) . "');\n"; } echo "</script>\n"; echo "<input type='hidden' name='word_id' value='$word_id'>\n"; echo "<table border=0>\n"; echo "<tr><td align='right'>WordList</td><td>\n"; echo "<select id='category_id' name='category_id'>\n"; $wordlist_ids = array(); $results = $db->query('SELECT * FROM wordlist'); while ($row = $results->fetchArray()) { $selected = ""; if ($wordlist_id == $row['id']) $selected = "selected"; echo "<option value='" . $row['id'] . "' $selected>" . $row['wordlist'] . "</option>\n"; $wordlist_ids[ $row['wordlist'] ] = $row['id']; } echo "</select>\n"; echo "</td></tr>\n"; echo "<tr><td align='right'>Word</td><td><input type='text' id='word' name='word' value='$word'></td></tr>\n"; echo "</table>\n"; echo "<hr width=300>\n"; echo "</form>\n"; if (count($videos) > 0) { echo "<button type='button' onclick='location.href = \"tempDeleteVideo.php?videoPath=\" + videos[document.getElementById(\"selectVideos\").value];'>Delete Video</button>\n"; echo "<select id='selectVideos' onchange='selectVideo(this.value)'>\n"; for ($i = 0; $i < count($videos); $i++) { $selected = ""; if ($i == $_GET["selected"]) $selected = "selected"; echo "<option value='" . $i . "' $selected>" . $videos[$i] . "</option>\n"; } echo "</select>\n"; echo "<button type='button' onclick='location.href = \"addVideo.php\";'>Add Video</button><br><br>\n"; echo "<video id='videoPlayer' controls></video><br>\n"; } else { echo "<br>\n"; echo "<button type='button' onclick='location.href = \"addVideo.php\";'>Add Video</button>\n"; echo "<br><br>\n"; } echo "<script type='text/javascript'>\n"; echo "function selectVideo(pos) {\n"; echo "document.getElementById(\"videoPlayer\").src = \"video/\" + videos[pos];\n"; echo "word = '$word';\n"; echo "replace = ''; for (i = 0; i < word.length; i++) replace += '鈥�';\n"; echo "sentence = sentences[pos].split(word).join('<font color=red>' + replace + '</font>');\n"; echo "sentence = sentence.split(\"\\r\\n\").join('<br>');\n"; echo "document.getElementById(\"sentence\").innerHTML = sentence;\n"; echo "if (sentences[pos].length == 0) { document.getElementById('sentence_btn').innerHTML = 'Add sentence'; }\n"; echo "else { document.getElementById('sentence_btn').innerHTML = 'Edit sentence'; }\n"; echo "}\n"; if ($_GET["selected"] != null) echo "selectVideo(" . $_GET["selected"] . ");\n"; echo "</script>\n"; ?>