Got words and dictionaries saving properly again, make uploads add only new words to db, make dictionary last_updated column when when adding words, add last_login column to users table.

This commit is contained in:
Robbie Antenesse 2016-06-16 13:22:13 -06:00
parent 6370de1651
commit 9f07b0f57a
3 changed files with 21 additions and 15 deletions

View File

@ -166,7 +166,6 @@ function UpdateWord(wordIndex, word, pronunciation, partOfSpeech, simpleDefiniti
currentDictionary.words[wordIndex].longDefinition = longDefinition; currentDictionary.words[wordIndex].longDefinition = longDefinition;
SaveAndUpdateWords("update", wordIndex); SaveAndUpdateWords("update", wordIndex);
ClearForm();
window.scroll(savedScroll.x, savedScroll.y); window.scroll(savedScroll.x, savedScroll.y);
@ -181,14 +180,14 @@ function DeleteWord(index) {
deleteWord.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); deleteWord.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
deleteWord.onreadystatechange = function() { deleteWord.onreadystatechange = function() {
if (deleteWord.readyState == 4 && deleteWord.status == 200) { if (deleteWord.readyState == 4 && deleteWord.status == 200) {
if (deleteWord.responseText == "deleted successfully") { if (deleteWord.responseText == "deleted successfully" || deleteWord.responseText == "not signed in") {
// If updated successfully, then reload the dictionary from server. // If updated successfully, then reload the dictionary from server.
if (document.getElementById("editIndex").value != "") // if (document.getElementById("editIndex").value != "")
ClearForm(); // ClearForm();
currentDictionary.words.splice(index, 1); currentDictionary.words.splice(index, 1);
SaveAndUpdateDictionary(true); SaveWords(false);
} }
console.log(deleteWord.responseText); console.log(deleteWord.responseText);
return true; return true;
@ -444,12 +443,8 @@ function SaveAndUpdateWords(action, wordIndex) {
sendWords.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); sendWords.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
sendWords.onreadystatechange = function() { sendWords.onreadystatechange = function() {
if (sendWords.readyState == 4 && sendWords.status == 200) { if (sendWords.readyState == 4 && sendWords.status == 200) {
if (!currentDictionary.settings.sortByEquivalent) { SaveWords();
currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech'])); ClearForm();
} else {
currentDictionary.words.sort(dynamicSort(['simpleDefinition', 'partOfSpeech']));
}
ProcessLoad();
console.log(sendWords.responseText); console.log(sendWords.responseText);
return true; return true;
} else { } else {
@ -459,6 +454,16 @@ function SaveAndUpdateWords(action, wordIndex) {
sendWords.send(dataToSend); sendWords.send(dataToSend);
} }
function SaveWords() {
if (!currentDictionary.settings.sortByEquivalent) {
currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech']));
} else {
currentDictionary.words.sort(dynamicSort(['simpleDefinition', 'partOfSpeech']));
}
SaveDictionary(false);
ProcessLoad();
}
function SaveAndUpdateDictionary(keepFormContents) { function SaveAndUpdateDictionary(keepFormContents) {
// if (!currentDictionary.settings.sortByEquivalent) { // if (!currentDictionary.settings.sortByEquivalent) {
// currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech'])); // currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech']));
@ -757,7 +762,7 @@ function ImportWords() {
document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight;
}, },
complete: function(results) { complete: function(results) {
SaveAndUpdateDictionary(); SaveAndUpdateWords("all");
resultsArea.innerHTML += "<p>The file has finished importing " + rowsImported.toString() + " words.</p>"; resultsArea.innerHTML += "<p>The file has finished importing " + rowsImported.toString() + " words.</p>";
// Scroll to the bottom. // Scroll to the bottom.
document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight;

View File

@ -214,8 +214,8 @@ function Save_New_Word($multiple = false) {
$dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$query = "UPDATE `dictionaries` SET `next_word_id`=" . $_GET['nextwordid'] . " WHERE `id`=" . $_SESSION['dictionary'] . "; "; $query = "UPDATE `dictionaries` SET `next_word_id`=" . $_GET['nextwordid'] . ", `last_updated`='" . date("Y-m-d H:i:s") . "' WHERE `id`=" . $_SESSION['dictionary'] . "; ";
$query .= "INSERT INTO `words`(`dictionary`, `word_id`, `name`, `pronunciation`, `part_of_speech`, `simple_definition`, `long_definition`) "; $query .= "INSERT IGNORE INTO `words`(`dictionary`, `word_id`, `name`, `pronunciation`, `part_of_speech`, `simple_definition`, `long_definition`) ";
$query .= "VALUES "; $query .= "VALUES ";
if ($multiple) { if ($multiple) {
for ($i = 0; $i < count($worddata); $i++) { for ($i = 0; $i < count($worddata); $i++) {

View File

@ -103,6 +103,7 @@ elseif (isset($_GET['login']) && $current_user <= 0) {
if (EmailExists($_POST['email'])) { if (EmailExists($_POST['email'])) {
if (Validate_Login($_POST['email'], $_POST['password'])) { if (Validate_Login($_POST['email'], $_POST['password'])) {
$_SESSION['user'] = Get_User_Id($_POST['email']); $_SESSION['user'] = Get_User_Id($_POST['email']);
query("UPDATE `users` SET `last_login`='" . date("Y-m-d H:i:s") . "' WHERE `id`=" . $_SESSION['user'] . ";");
} else { } else {
$_SESSION['current_status'] = "loginfailed"; $_SESSION['current_status'] = "loginfailed";
} }