From 9f07b0f57a709b9c2d0a9feec442b666ed6a5616 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 16 Jun 2016 13:22:13 -0600 Subject: [PATCH] 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. --- js/dictionaryBuilder.js | 31 ++++++++++++++++++------------- php/ajax_dictionarymanagement.php | 4 ++-- php/notificationconditiontree.php | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index 02a5040..5e82999 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -166,7 +166,6 @@ function UpdateWord(wordIndex, word, pronunciation, partOfSpeech, simpleDefiniti currentDictionary.words[wordIndex].longDefinition = longDefinition; SaveAndUpdateWords("update", wordIndex); - ClearForm(); window.scroll(savedScroll.x, savedScroll.y); @@ -181,14 +180,14 @@ function DeleteWord(index) { deleteWord.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); deleteWord.onreadystatechange = function() { 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 (document.getElementById("editIndex").value != "") - ClearForm(); + // if (document.getElementById("editIndex").value != "") + // ClearForm(); currentDictionary.words.splice(index, 1); - SaveAndUpdateDictionary(true); + SaveWords(false); } console.log(deleteWord.responseText); return true; @@ -444,12 +443,8 @@ function SaveAndUpdateWords(action, wordIndex) { sendWords.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); sendWords.onreadystatechange = function() { if (sendWords.readyState == 4 && sendWords.status == 200) { - if (!currentDictionary.settings.sortByEquivalent) { - currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech'])); - } else { - currentDictionary.words.sort(dynamicSort(['simpleDefinition', 'partOfSpeech'])); - } - ProcessLoad(); + SaveWords(); + ClearForm(); console.log(sendWords.responseText); return true; } else { @@ -459,6 +454,16 @@ function SaveAndUpdateWords(action, wordIndex) { 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) { // if (!currentDictionary.settings.sortByEquivalent) { // currentDictionary.words.sort(dynamicSort(['name', 'partOfSpeech'])); @@ -697,7 +702,7 @@ function ImportDictionary() { document.getElementById("importFile").value = ""; } else { var errorString = "File is missing:"; - if (!tmpDicitonary.hasOwnProperty("name")) + if (!tmpDicitonary.hasOwnProperty("name")) errorString += " name"; if (!tmpDicitonary.hasOwnProperty("description")) errorString += " description"; @@ -757,7 +762,7 @@ function ImportWords() { document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; }, complete: function(results) { - SaveAndUpdateDictionary(); + SaveAndUpdateWords("all"); resultsArea.innerHTML += "

The file has finished importing " + rowsImported.toString() + " words.

"; // Scroll to the bottom. document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; diff --git a/php/ajax_dictionarymanagement.php b/php/ajax_dictionarymanagement.php index 2af7db0..2532bff 100644 --- a/php/ajax_dictionarymanagement.php +++ b/php/ajax_dictionarymanagement.php @@ -214,8 +214,8 @@ function Save_New_Word($multiple = false) { $dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); - $query = "UPDATE `dictionaries` SET `next_word_id`=" . $_GET['nextwordid'] . " WHERE `id`=" . $_SESSION['dictionary'] . "; "; - $query .= "INSERT INTO `words`(`dictionary`, `word_id`, `name`, `pronunciation`, `part_of_speech`, `simple_definition`, `long_definition`) "; + $query = "UPDATE `dictionaries` SET `next_word_id`=" . $_GET['nextwordid'] . ", `last_updated`='" . date("Y-m-d H:i:s") . "' WHERE `id`=" . $_SESSION['dictionary'] . "; "; + $query .= "INSERT IGNORE INTO `words`(`dictionary`, `word_id`, `name`, `pronunciation`, `part_of_speech`, `simple_definition`, `long_definition`) "; $query .= "VALUES "; if ($multiple) { for ($i = 0; $i < count($worddata); $i++) { diff --git a/php/notificationconditiontree.php b/php/notificationconditiontree.php index 8dc0b5c..45dbcf6 100644 --- a/php/notificationconditiontree.php +++ b/php/notificationconditiontree.php @@ -103,6 +103,7 @@ elseif (isset($_GET['login']) && $current_user <= 0) { if (EmailExists($_POST['email'])) { if (Validate_Login($_POST['email'], $_POST['password'])) { $_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 { $_SESSION['current_status'] = "loginfailed"; }