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;
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 += "<p>The file has finished importing " + rowsImported.toString() + " words.</p>";
// Scroll to the bottom.
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_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++) {

View File

@ -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";
}