Fixed switching dicitonaries, added deletion and addition of dictionaries, added next_word_id to dictionary, added warning for logging in with non-new dictionary.
Commented out ads/tracking, so be sure to add that before prod.
This commit is contained in:
parent
8861ca24b5
commit
ade8d57281
|
@ -8,10 +8,12 @@
|
|||
</label>
|
||||
<div id="loginError" style="font-weight:bold;color:red;"></div>
|
||||
<button type="submit" id="loginSubmitButton" onclick="ValidateLogin(); return false;">Log In</button>
|
||||
<div id="dictionaryWarn"></div>
|
||||
</form></div>
|
||||
<div class="settingsCol"><form id="createAccountForm" method="post" action="?createaccount">
|
||||
<h2>Create a New Account</h2>
|
||||
<p>Creating an account allows you to save and switch between up to 10 dictionaries and access them from any device for free! Plus if you allow us to send you emails, you'll be the first to hear about any new features that get added or if any of our policies change for any reason.</p>
|
||||
<p style="font-size: 12px;">Creating an account allows you to save and switch between up to 10 dictionaries and access them from any device for free!</p>
|
||||
<p style="font-size: 12px;">Plus if you allow us to send you emails, we'll never spam you or sell your information. It'll just make sure that you'll be the first to hear about any new features that get added or if any of our policies change for any reason.</p>
|
||||
<label><span>Email</span>
|
||||
<input type="email" id="createAccountEmailField" name="email" />
|
||||
</label>
|
||||
|
@ -21,7 +23,7 @@
|
|||
<label><span>Confirm Password</span>
|
||||
<input type="password" id="createAccountPasswordConfirmField" name="confirmpassword" />
|
||||
</label>
|
||||
<label><span>Public Name <span class="clickable" onclick="alert(\'This is the name we greet you with. It is also the name displayed if you ever decide to share any of your dictionaries.\n\nNote: this is not a username, and as such may not be unique. Use something people will recognize you as to differentiate from other people who might use the same name!\')">?</span></span>
|
||||
<label><span>Public Name <span class="clickable" onclick="ExplainPublicName()" style="font-size:11px;vertical-align:top;background:#e0c19c;padding:4px 7px;">?</span></span>
|
||||
<input type="text" id="createAccountPublicNameField" name="publicname" />
|
||||
</label>
|
||||
<label><b>Allow Emails</b>
|
||||
|
|
|
@ -84,7 +84,7 @@ input, textarea, select, option, button {
|
|||
border-color: #d09b84 #915237 #915237 #d09b84;
|
||||
}
|
||||
|
||||
#dictionaryDescription, .management, #settingsOptions, #infoPage {
|
||||
#dictionaryDescription, .management, #settingsOptions, #infoPage, #loadAfterDeletePage {
|
||||
background: #f2d5b2;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,20 @@ input[type=checkbox] {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
#dictionaryWarn {
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.exportWarnText {
|
||||
display: inline;
|
||||
color: red;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#aboutButton {
|
||||
display: inline;
|
||||
margin: 0 10px 0 0;
|
||||
|
@ -273,7 +287,7 @@ searchTerm {
|
|||
margin: 10px;
|
||||
}
|
||||
|
||||
#settingsBackgroundFade, #infoBackgroundFade {
|
||||
#settingsBackgroundFade, #infoBackgroundFade, #loadAfterDeleteFade {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
@ -283,7 +297,7 @@ searchTerm {
|
|||
opacity: 0.75;
|
||||
}
|
||||
|
||||
#settingsOptions, #infoPage {
|
||||
#settingsOptions, #infoPage, #loadAfterDeletePage {
|
||||
position: fixed;
|
||||
top: 6%;
|
||||
left: 6%;
|
||||
|
@ -295,6 +309,7 @@ searchTerm {
|
|||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
background: #ffffff;
|
||||
opacity: 1;
|
||||
border-radius: 5px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
|
28
index.php
28
index.php
|
@ -78,6 +78,8 @@ elseif (isset($_GET['success']) && $current_user <= 0) {
|
|||
}
|
||||
elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
||||
$notificationMessage = "You have been successfully logged out.<br>You will only be able to use the dictionary saved to your browser.";
|
||||
} elseif ($current_user > 0) {
|
||||
$notificationMessage = "Welcome back, " . Get_Public_Name($current_user) . "!";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
|
@ -146,7 +148,7 @@ elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
|||
|
||||
<div id="dictionaryContainer">
|
||||
<span id="settingsButton" class="clickable" onclick="ShowSettings()">Settings</span>
|
||||
|
||||
|
||||
<h1 id="dictionaryName"></h1>
|
||||
|
||||
<span id="descriptionToggle" class="clickable" onclick="ToggleDescription();">Show Description</span>
|
||||
|
@ -176,7 +178,7 @@ elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
|||
</div>
|
||||
|
||||
<div id="rightColumn" class="googleads" style="float:right;width:20%;max-width:300px;min-width:200px;overflow:hidden;">
|
||||
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/adsense.php"); } ?>
|
||||
<?php //if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/adsense.php"); } ?>
|
||||
</div>
|
||||
|
||||
<div id="settingsScreen" style="display:none;">
|
||||
|
@ -233,7 +235,11 @@ elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
|||
<input type="file" id="importFile" />
|
||||
<button type="button" onclick="ImportDictionary(); return false;">Import</button>
|
||||
</label>
|
||||
<label><button type="button" onclick="EmptyWholeDictionary()" style="cursor:pointer;">Empty Current Dictionary</button></label>
|
||||
<?php if ($current_user > 0) { //If logged in, show the log out button. ?>
|
||||
<label><button type="button" onclick="DeleteCurrentDictionary()" style="cursor:pointer;">Delete Current Dictionary</button></label>
|
||||
<?php } else { //If logged in, show the log out button. ?>
|
||||
<label><button type="button" onclick="EmptyWholeDictionary()" style="cursor:pointer;">Empty Current Dictionary</button></label>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div id="settingsSaveButtons">
|
||||
<span id="settingsErrorMessage"></span><br>
|
||||
|
@ -251,6 +257,20 @@ elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
|||
<div id="infoText"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loadAfterDeleteScreen" style="display:none;">
|
||||
<div id="loadAfterDeleteFade"></div>
|
||||
<div id="loadAfterDeletePage">
|
||||
<div class="settingsCol">
|
||||
<h1>Dictionary Deleted</h1>
|
||||
<label>Select dictionary to load:<br />
|
||||
<select id="loadAfterDelete" onchange="ChangeDictionary(this);document.getElementById('loadAfterDeleteScreen').style.display = 'none';"></select>
|
||||
</label>
|
||||
<p>Or</p>
|
||||
<label><button type="button" onclick="CreateNewDictionary();document.getElementById('loadAfterDeleteScreen').style.display = 'none';" style="cursor:pointer;">Create a New Dictionary</button></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</contents>
|
||||
<footer>
|
||||
Dictionary Builder only guaranteed to work with most up-to-date HTML5 browsers. <a href="https://github.com/Alamantus/DictionaryBuilder/issues" target="_blank">Report a Problem</a> | <span class="clickable" onclick="ShowInfo('terms')" style="font-size:12px;">Terms</span> <span class="clickable" onclick="ShowInfo('privacy')" style="font-size:12px;">Privacy</span>
|
||||
|
@ -263,7 +283,7 @@ elseif (isset($_GET['loggedout']) && $current_user <= 0) {
|
|||
<!-- Main Script -->
|
||||
<script src="js/dictionaryBuilder.js"></script>
|
||||
<script src="js/ui.js"></script>
|
||||
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
|
||||
<?php //if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
|
|
|
@ -285,7 +285,6 @@ function SaveSettings() {
|
|||
currentDictionary.description = htmlEntities(document.getElementById("dictionaryDescriptionEdit").value);
|
||||
|
||||
CheckForPartsOfSpeechChange();
|
||||
LoadUserDictionaries();
|
||||
|
||||
currentDictionary.settings.allowDuplicates = document.getElementById("dictionaryAllowDuplicates").checked;
|
||||
currentDictionary.settings.caseSensitive = document.getElementById("dictionaryCaseSensitive").checked;
|
||||
|
@ -297,6 +296,7 @@ function SaveSettings() {
|
|||
HideSettingsWhenComplete();
|
||||
|
||||
SaveAndUpdateDictionary(true);
|
||||
LoadUserDictionaries();
|
||||
}
|
||||
|
||||
function CheckForPartsOfSpeechChange() {
|
||||
|
@ -310,22 +310,51 @@ function CheckForPartsOfSpeechChange() {
|
|||
|
||||
function EmptyWholeDictionary() {
|
||||
if (confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")) {
|
||||
ResetDictionaryToDefault();
|
||||
SaveAndUpdateDictionary(false);
|
||||
SetPartsOfSpeech();
|
||||
HideSettings();
|
||||
CreateNewDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
function CreateNewDictionary() {
|
||||
// This is EmptyWholeDictionary() without the confirmation. ONLY USE WHEN LOGGED IN.
|
||||
ResetDictionaryToDefault();
|
||||
SaveAndUpdateDictionary(false);
|
||||
LoadUserDictionaries();
|
||||
SetPartsOfSpeech();
|
||||
HideSettings();
|
||||
}
|
||||
|
||||
function DeleteCurrentDictionary() {
|
||||
if (confirm("This will delete the current dictionary from the database. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")) {
|
||||
ResetDictionaryToDefault();
|
||||
|
||||
var deleteDictionary = new XMLHttpRequest();
|
||||
deleteDictionary.open('POST', "php/ajax_dictionarymanagement.php?action=delete");
|
||||
deleteDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
deleteDictionary.onreadystatechange = function() {
|
||||
if (deleteDictionary.readyState == 4 && deleteDictionary.status == 200) {
|
||||
if (deleteDictionary.responseText.length < 31) {
|
||||
console.log(deleteDictionary.responseText);
|
||||
CreateNewDictionary();
|
||||
} else {
|
||||
HideSettings();
|
||||
document.getElementById('loadAfterDeleteScreen').style.display = 'block';
|
||||
//Parse response into the list that forces you to load one and reload select in settings.
|
||||
ParseUserDictionariesIntoSelect(document.getElementById("loadAfterDelete"), deleteDictionary.responseText);
|
||||
ParseUserDictionariesIntoSelect(document.getElementById("userDictionaries"), deleteDictionary.responseText);
|
||||
|
||||
if (document.getElementById("loadAfterDelete").options.length == 0) {
|
||||
document.getElementById('loadAfterDeleteScreen').style.display = 'none';
|
||||
CreateNewDictionary();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
deleteDictionary.send();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function ResetDictionaryToDefault() {
|
||||
currentDictionary = JSON.parse(defaultDictionaryJSON);
|
||||
}
|
||||
|
@ -351,9 +380,9 @@ function SendDictionary(sendWords) {
|
|||
postString = DataToSend(sendWords);
|
||||
} else {
|
||||
action = "new";
|
||||
postString = DataToSend(true);
|
||||
postString = DataToSend(true, true);
|
||||
}
|
||||
|
||||
|
||||
var sendDictionary = new XMLHttpRequest();
|
||||
sendDictionary.open('POST', "php/ajax_dictionarymanagement.php?action=" + action);
|
||||
sendDictionary.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
|
@ -361,12 +390,15 @@ function SendDictionary(sendWords) {
|
|||
if (sendDictionary.readyState == 4 && sendDictionary.status == 200) {
|
||||
if (sendDictionary.responseText == "updated successfully") {
|
||||
console.log(sendDictionary.responseText);
|
||||
} else if (!isNaN(parseInt(sendDictionary.responseText))) {
|
||||
LoadUserDictionaries();
|
||||
ProcessLoad();
|
||||
} else if (isNaN(parseInt(sendDictionary.responseText))) {
|
||||
console.log(sendDictionary.responseText);
|
||||
} else { // It will only be a number if it is a new dictionary.
|
||||
currentDictionary.externalID = parseInt(sendDictionary.responseText);
|
||||
LoadUserDictionaries();
|
||||
ProcessLoad();
|
||||
console.log("saved successfully");
|
||||
} else {
|
||||
console.log(sendDictionary.responseText);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
@ -376,35 +408,39 @@ function SendDictionary(sendWords) {
|
|||
sendDictionary.send(postString);
|
||||
}
|
||||
|
||||
function DataToSend(doSendWords) {
|
||||
function DataToSend(doSendWords, sendAll) {
|
||||
sendAll = (typeof sendAll !== 'undefined' && sendAll != null) ? sendAll : false;
|
||||
var data = "";
|
||||
if (currentDictionary.externalID == 0) {
|
||||
data = "name=" + encodeURIComponent(currentDictionary.name) + "&description=" + encodeURIComponent(currentDictionary.description) + "&words=" + encodeURIComponent(JSON.stringify(currentDictionary.words));
|
||||
data += "&allowduplicates=" + ((currentDictionary.settings.allowDuplicates) ? "1" : "0") + "&casesensitive=" + ((currentDictionary.settings.caseSensitive) ? "1" : "0");
|
||||
data += "&nextwordid=" + currentDictionary.nextWordId + "&allowduplicates=" + ((currentDictionary.settings.allowDuplicates) ? "1" : "0") + "&casesensitive=" + ((currentDictionary.settings.caseSensitive) ? "1" : "0");
|
||||
data += "&partsofspeech=" + encodeURIComponent(currentDictionary.settings.partsOfSpeech) + "&sortbyequivalent=" + ((currentDictionary.settings.sortByEquivalent) ? "1" : "0") + "&iscomplete=" + ((currentDictionary.settings.isComplete) ? "1" : "0") + "&ispublic=0";
|
||||
} else {
|
||||
if (currentDictionary.name != previousDictionary.name) {
|
||||
if (sendAll || currentDictionary.name != previousDictionary.name) {
|
||||
data += "name=" + encodeURIComponent(currentDictionary.name);
|
||||
}
|
||||
if (currentDictionary.description != previousDictionary.description) {
|
||||
if (sendAll || currentDictionary.description != previousDictionary.description) {
|
||||
data += ((data=="") ? "" : "&") + "description=" + encodeURIComponent(currentDictionary.description);
|
||||
}
|
||||
if (doSendWords) {
|
||||
if (sendAll || doSendWords) {
|
||||
data += ((data=="") ? "" : "&") + "words=" + encodeURIComponent(JSON.stringify(currentDictionary.words));
|
||||
}
|
||||
if (currentDictionary.settings.allowDuplicates != previousDictionary.allowDuplicates) {
|
||||
if (sendAll || currentDictionary.nextWordId != previousDictionary.nextWordId) {
|
||||
data += ((data=="") ? "" : "&") + "nextwordid=" + currentDictionary.nextWordId;
|
||||
}
|
||||
if (sendAll || currentDictionary.settings.allowDuplicates != previousDictionary.allowDuplicates) {
|
||||
data += ((data=="") ? "" : "&") + "allowduplicates=" + ((currentDictionary.settings.allowDuplicates) ? "1" : "0");
|
||||
}
|
||||
if (currentDictionary.settings.caseSensitive != previousDictionary.caseSensitive) {
|
||||
if (sendAll || currentDictionary.settings.caseSensitive != previousDictionary.caseSensitive) {
|
||||
data += ((data=="") ? "" : "&") + "casesensitive=" + ((currentDictionary.settings.caseSensitive) ? "1" : "0");
|
||||
}
|
||||
if (currentDictionary.settings.partsOfSpeech != previousDictionary.partsOfSpeech) {
|
||||
if (sendAll || currentDictionary.settings.partsOfSpeech != previousDictionary.partsOfSpeech) {
|
||||
data += ((data=="") ? "" : "&") + "partsofspeech=" + encodeURIComponent(currentDictionary.settings.partsOfSpeech);
|
||||
}
|
||||
if (currentDictionary.settings.sortByEquivalent != previousDictionary.sortByEquivalent) {
|
||||
if (sendAll || currentDictionary.settings.sortByEquivalent != previousDictionary.sortByEquivalent) {
|
||||
data += ((data=="") ? "" : "&") + "sortbyequivalent=" + ((currentDictionary.settings.sortByEquivalent) ? "1" : "0");
|
||||
}
|
||||
if (currentDictionary.settings.isComplete != previousDictionary.isComplete) {
|
||||
if (sendAll || currentDictionary.settings.isComplete != previousDictionary.isComplete) {
|
||||
data += ((data=="") ? "" : "&") + "iscomplete=" + ((currentDictionary.settings.isComplete) ? "1" : "0");
|
||||
}
|
||||
data += ((data=="") ? "" : "&") + "ispublic=0";
|
||||
|
@ -419,25 +455,24 @@ function LoadDictionary() {
|
|||
loadDictionary.onreadystatechange = function() {
|
||||
if (loadDictionary.readyState == 4 && loadDictionary.status == 200) {
|
||||
if (loadDictionary.responseText == "no dictionaries") {
|
||||
SendDictionary(false);
|
||||
} else if (loadDictionary.responseText.length > 50) {
|
||||
// If there are no dictionaries in the database and there's one in memory, remove the id and send it as a new one.
|
||||
currentDictionary.externalID = 0;
|
||||
SendDictionary(true);
|
||||
} else if (loadDictionary.responseText.length < 60) {
|
||||
console.log(loadDictionary.responseText);
|
||||
} else {
|
||||
currentDictionary = JSON.parse(loadDictionary.responseText);
|
||||
SaveDictionary(false, false);
|
||||
ProcessLoad();
|
||||
} else {
|
||||
console.log(loadDictionary.responseText);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
ProcessLoad();
|
||||
}
|
||||
loadDictionary.send();
|
||||
}
|
||||
|
||||
function ChangeDictionary() {
|
||||
var userDictionariesSelect = document.getElementById("userDictionaries");
|
||||
if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 1) {
|
||||
function ChangeDictionary(userDictionariesSelect) {
|
||||
userDictionariesSelect = (typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null) ? userDictionariesSelect : document.getElementById("userDictionaries");
|
||||
if (currentDictionary.externalID != userDictionariesSelect.value && userDictionariesSelect.options.length > 0) {
|
||||
var changeDictionaryRequest = new XMLHttpRequest();
|
||||
changeDictionaryRequest.open('POST', "php/ajax_dictionarymanagement.php?action=switch");
|
||||
changeDictionaryRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
|
@ -445,19 +480,17 @@ function ChangeDictionary() {
|
|||
changeDictionaryRequest.onreadystatechange = function() {
|
||||
if (changeDictionaryRequest.readyState == 4 && changeDictionaryRequest.status == 200) {
|
||||
if (changeDictionaryRequest.responseText == "no dictionaries") {
|
||||
SendDictionary(false);
|
||||
console.log(changeDictionaryRequest.responseText);
|
||||
} else if (changeDictionaryRequest.responseText.length > 50) {
|
||||
SendDictionary(false);
|
||||
} else if (changeDictionaryRequest.responseText.length < 60) {
|
||||
console.log(changeDictionaryRequest.responseText);
|
||||
} else {
|
||||
currentDictionary = JSON.parse(changeDictionaryRequest.responseText);
|
||||
SaveDictionary(false, false);
|
||||
ProcessLoad();
|
||||
LoadUserDictionaries();
|
||||
HideSettings();
|
||||
} else {
|
||||
console.log(changeDictionaryRequest.responseText);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
changeDictionaryRequest.send(postString);
|
||||
|
@ -467,7 +500,7 @@ function ChangeDictionary() {
|
|||
function LoadLocalDictionary() {
|
||||
if (localStorage.getItem('dictionary')) {
|
||||
var tmpDictionary = JSON.parse(localStorage.getItem('dictionary'));
|
||||
if (tmpDictionary.words.length > 0) {
|
||||
if (tmpDictionary.words.length > 0 || tmpDictionary.description != "A new dictionary." || tmpDictionary.name != "New") {
|
||||
currentDictionary = JSON.parse(localStorage.getItem('dictionary'));
|
||||
}
|
||||
tmpDictionary = null;
|
||||
|
@ -498,6 +531,7 @@ function SavePreviousDictionary () {
|
|||
previousDictionary = {
|
||||
name: currentDictionary.name,
|
||||
description: currentDictionary.description,
|
||||
nextWordId: currentDictionary.nextWordId,
|
||||
allowDuplicates: currentDictionary.settings.allowDuplicates,
|
||||
caseSensitive: currentDictionary.settings.caseSensitive,
|
||||
partsOfSpeech: currentDictionary.settings.partsOfSpeech,
|
||||
|
@ -507,7 +541,7 @@ function SavePreviousDictionary () {
|
|||
}
|
||||
|
||||
function ExportDictionary() {
|
||||
var downloadName = currentDictionary.name.replace(/\W/g, '');
|
||||
var downloadName = stripHtmlEntities(currentDictionary.name).replace(/\W/g, '');
|
||||
if (downloadName == "") {
|
||||
downloadName = "export";
|
||||
}
|
||||
|
@ -515,7 +549,7 @@ function ExportDictionary() {
|
|||
}
|
||||
|
||||
function ImportDictionary() {
|
||||
if (confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")) {
|
||||
if (currentDictionary.externalID > 0 || confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")) {
|
||||
if (!window.FileReader) {
|
||||
alert('Your browser is not supported');
|
||||
return false;
|
||||
|
@ -584,6 +618,11 @@ function htmlEntitiesParse(string) {
|
|||
return String(string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/<br>/g, '\n');
|
||||
}
|
||||
|
||||
function stripHtmlEntities(string) {
|
||||
// This is for the export name.
|
||||
return String(string).replace(/&/g, '').replace(/</g, '').replace(/>/g, '').replace(/"/g, '').replace(/'/g, "").replace(/<br>/g, '');
|
||||
}
|
||||
|
||||
function dynamicSort(property) {
|
||||
/* Retrieved from http://stackoverflow.com/a/4760279
|
||||
Usage: theArray.sort(dynamicSort("objectProperty"));*/
|
||||
|
|
43
js/ui.js
43
js/ui.js
|
@ -18,29 +18,31 @@ function LoadUserDictionaries() {
|
|||
getDictionariesRequest.open('GET', "php/ajax_dictionarymanagement.php?action=getall");
|
||||
getDictionariesRequest.onreadystatechange = function() {
|
||||
if (getDictionariesRequest.readyState == 4 && getDictionariesRequest.status == 200) {
|
||||
if (userDictionariesSelect.options.length > 0) {
|
||||
for (var i = userDictionariesSelect.options.length - 1; i >= 0; i--) {
|
||||
userDictionariesSelect.removeChild(userDictionariesSelect.options[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var dictionaries = getDictionariesRequest.responseText.split("_DICTIONARYSEPARATOR_");
|
||||
for (var j = 0; j < dictionaries.length - 1; j++) {
|
||||
var dictionaryOption = document.createElement('option');
|
||||
var dictionaryValues = dictionaries[j].split("_IDNAMESEPARATOR_");
|
||||
dictionaryOption.appendChild(document.createTextNode(dictionaryValues[1]));
|
||||
dictionaryOption.value = dictionaryValues[0];
|
||||
userDictionariesSelect.appendChild(dictionaryOption);
|
||||
}
|
||||
if (dictionaries.length > 1) {
|
||||
userDictionariesSelect.value = currentDictionary.externalID;
|
||||
}
|
||||
ParseUserDictionariesIntoSelect(userDictionariesSelect, getDictionariesRequest.responseText);
|
||||
}
|
||||
}
|
||||
getDictionariesRequest.send();
|
||||
}
|
||||
}
|
||||
|
||||
function ParseUserDictionariesIntoSelect(selectToPopulate, dicitonaryList) {
|
||||
if (selectToPopulate.options.length > 0) {
|
||||
for (var i = selectToPopulate.options.length - 1; i >= 0; i--) {
|
||||
selectToPopulate.removeChild(selectToPopulate.options[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var dictionaries = dicitonaryList.split("_DICTIONARYSEPARATOR_");
|
||||
for (var j = 0; j < dictionaries.length - 1; j++) {
|
||||
var dictionaryOption = document.createElement('option');
|
||||
var dictionaryValues = dictionaries[j].split("_IDNAMESEPARATOR_");
|
||||
dictionaryOption.appendChild(document.createTextNode(htmlEntitiesParse(dictionaryValues[1])));
|
||||
dictionaryOption.value = dictionaryValues[0];
|
||||
selectToPopulate.appendChild(dictionaryOption);
|
||||
}
|
||||
selectToPopulate.value = (currentDictionary.externalID > 0) ? currentDictionary.externalID : "";
|
||||
}
|
||||
|
||||
function GetTextFile(filename) {
|
||||
var readmeFileRequest = new XMLHttpRequest();
|
||||
readmeFileRequest.open('GET', filename);
|
||||
|
@ -118,6 +120,10 @@ function ValidateCreateAccount() {
|
|||
}
|
||||
}
|
||||
|
||||
function ExplainPublicName() {
|
||||
alert("This is the name we greet you with. It's also the name displayed if you ever decide to share any of your dictionaries.\n\nNote: this is not a username, and as such is not guaranteed to be unique. Use something people will recognize you as to differentiate from other people who might use the same name!");
|
||||
}
|
||||
|
||||
function CloseUpdateConflictArea() {
|
||||
document.getElementById("updateConflict").style.display = "none";
|
||||
}
|
||||
|
@ -156,6 +162,9 @@ function ShowInfo(text) {
|
|||
document.getElementById("infoText").innerHTML = privacyText;
|
||||
} else if (text == "login") {
|
||||
document.getElementById("infoText").innerHTML = loginForm;
|
||||
if (currentDictionary.words.length > 0 || currentDictionary.name != "New" || currentDictionary.description != "A new dictionary.") {
|
||||
document.getElementById("dictionaryWarn").innerHTML = "If your current dictionary is not already saved to your account, be sure to <span class='exportWarnText' onclick='ExportDictionary()'>export it before logging in</span> so you don't lose anything!";
|
||||
}
|
||||
} else {
|
||||
document.getElementById("infoText").innerHTML = aboutText;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
require_once("../required.php");
|
||||
// require_once("../required.php");
|
||||
require_once('config.php');
|
||||
require_once(SITE_LOCATION . '/php/functions.php');
|
||||
|
||||
$email = htmlspecialchars($_GET['email']);
|
||||
|
||||
|
|
|
@ -21,46 +21,42 @@ elseif ($_GET['action'] == 'switch') {
|
|||
Switch_Current_Dictionary($_POST['newdictionaryid'], true);
|
||||
}
|
||||
elseif ($_GET['action'] == 'delete') {
|
||||
Switch_Current_Dictionary($_POST['deletedictionaryid']);
|
||||
Delete_Current_Dictionary();
|
||||
}
|
||||
|
||||
function Get_Dictionaries($return_list = true) {
|
||||
if (isset($_SESSION['user'])) {
|
||||
if ($_SESSION['user'] > 0) {
|
||||
$query = "SELECT `id`, `name` FROM `dictionaries` WHERE `user`=" . $_SESSION['user'] . " ORDER BY `name` ASC;";
|
||||
$dictionaries = query($query);
|
||||
|
||||
if ($dictionaries) {
|
||||
if (num_rows($dictionaries) > 0) {
|
||||
if ($return_list) {
|
||||
$list = "";
|
||||
$_SESSION['dictionaries'] = [];
|
||||
while ($dict = fetch($dictionaries)) {
|
||||
$_SESSION['dictionaries'][] = $dict['id']; // Save a list of all dictionaries user has.
|
||||
//list for the switch dictionaries dropdown.
|
||||
$list .= $dict['id'] . '_IDNAMESEPARATOR_' . $dict['name'] . '_DICTIONARYSEPARATOR_';
|
||||
}
|
||||
echo $list;
|
||||
if ($_SESSION['user'] > 0) {
|
||||
$query = "SELECT `id`, `name` FROM `dictionaries` WHERE `user`=" . $_SESSION['user'] . " ORDER BY `name` ASC;";
|
||||
$dictionaries = query($query);
|
||||
|
||||
if ($dictionaries) {
|
||||
if (num_rows($dictionaries) > 0) {
|
||||
if ($return_list) {
|
||||
$list = "";
|
||||
$_SESSION['dictionaries'] = [];
|
||||
while ($dict = fetch($dictionaries)) {
|
||||
$_SESSION['dictionaries'][] = $dict['id']; // Save a list of all dictionaries user has.
|
||||
//list for the switch dictionaries dropdown.
|
||||
$list .= $dict['id'] . '_IDNAMESEPARATOR_' . $dict['name'] . '_DICTIONARYSEPARATOR_';
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
echo "no dictionaries";
|
||||
echo $list;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
echo "could not load";
|
||||
echo "no dictionaries";
|
||||
}
|
||||
} else {
|
||||
echo "not signed in";
|
||||
echo "could not load";
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not signed in";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Load_Current_Dictionary() {
|
||||
if (isset($_SESSION['user'])) {
|
||||
$query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`words`, `d`.`allow_duplicates`, `d`.`case_sensitive`, `d`.`parts_of_speech`, `d`.`is_complete` ";
|
||||
if ($_SESSION['user'] > 0) {
|
||||
$query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`words`, `d`.`next_word_id`, `d`.`allow_duplicates`, `d`.`case_sensitive`, `d`.`parts_of_speech`, `d`.`is_complete` ";
|
||||
$query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `user`=`u`.`id` WHERE `is_current`=1 AND `user`=" . $_SESSION['user'] . ";";
|
||||
$dictionary = query($query);
|
||||
|
||||
|
@ -73,6 +69,7 @@ function Load_Current_Dictionary() {
|
|||
$json .= '"description":"' . $dict['description'] . '",';
|
||||
$json .= '"createdBy":"' . $dict['public_name'] . '",';
|
||||
$json .= '"words":' . $dict['words'] . ',';
|
||||
$json .= '"nextWordId":' . $dict['next_word_id'] . ',';
|
||||
$json .= '"settings":{';
|
||||
$json .= '"allowDuplicates":' . (($dict['allow_duplicates'] == 1) ? 'true' : 'false') . ',';
|
||||
$json .= '"caseSensitive":' . (($dict['case_sensitive'] == 1) ? 'true' : 'false') . ',';
|
||||
|
@ -93,28 +90,28 @@ function Load_Current_Dictionary() {
|
|||
echo "could not load";
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not logged in";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Save_Current_DictionaryAsNew() {
|
||||
if (isset($_SESSION['user'])) {
|
||||
if ($_SESSION['user'] > 0) {
|
||||
$dbconnection = new PDO('mysql:host=' . DATABASE_SERVERNAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD);
|
||||
$dbconnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
$query = "INSERT INTO `dictionaries`(`user`, `is_current`, `name`, `description`, `words`, `allow_duplicates`, `case_sensitive`, `parts_of_speech`, `sort_by_equivalent`, `is_complete`, `is_public`) ";
|
||||
$query .= "VALUES (" . $_SESSION['user'] . ",0,'" . $_POST['name'] . "','" . $_POST['description'] . "','" . $_POST['words'] . "'," . $_POST['allowduplicates'] . "," . $_POST['casesensitive'] . ",'" . $_POST['partsofspeech'] . "'," . $_POST['sortbyequivalent'] . "," . $_POST['iscomplete'] . "," . $_POST['ispublic'] . ")";
|
||||
$query = "INSERT INTO `dictionaries`(`user`, `is_current`, `name`, `description`, `words`, `next_word_id`, `allow_duplicates`, `case_sensitive`, `parts_of_speech`, `sort_by_equivalent`, `is_complete`, `is_public`) ";
|
||||
$query .= "VALUES (" . $_SESSION['user'] . ",0,'" . $_POST['name'] . "','" . $_POST['description'] . "','" . $_POST['words'] . "'," . $_POST['nextwordid'] . "," . $_POST['allowduplicates'] . "," . $_POST['casesensitive'] . ",'" . $_POST['partsofspeech'] . "'," . $_POST['sortbyequivalent'] . "," . $_POST['iscomplete'] . "," . $_POST['ispublic'] . ")";
|
||||
|
||||
try {
|
||||
$update = $dbconnection->prepare($query);
|
||||
$update->execute();
|
||||
$_SESSION['dictionary'] = $conn->lastInsertId;
|
||||
$_SESSION['dictionary'] = $dbconnection->lastInsertId();
|
||||
$_SESSION['dictionaries'][] = $_SESSION['dictionary']; //Add new id to valid dictionaries.
|
||||
Switch_Current_Dictionary($_SESSION['dictionary'], false);
|
||||
echo $_SESSION['dictionary'];
|
||||
Switch_Current_Dictionary($_SESSION['dictionary'], false);
|
||||
return true;
|
||||
}
|
||||
catch (PDOException $ex) {
|
||||
|
@ -122,110 +119,119 @@ function Save_Current_DictionaryAsNew() {
|
|||
echo "could not update:\n" . $errorMessage[2] . "\n" . $query;
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not logged in";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Update_Current_Dictionary() {
|
||||
if (isset($_SESSION['dictionary'])) {
|
||||
$query = "UPDATE `dictionaries` SET ";
|
||||
|
||||
if (isset($_POST['name'])) {
|
||||
$query .= "`name`='" . $_POST['name'] . "', ";
|
||||
}
|
||||
if (isset($_POST['description'])) {
|
||||
$query .= "`description`='" . $_POST['description'] . "', ";
|
||||
}
|
||||
if (isset($_POST['words'])) {
|
||||
$query .= "`words`='" . $_POST['words'] . "', ";
|
||||
}
|
||||
if (isset($_POST['allowDuplicates'])) {
|
||||
$query .= "`allow_duplicates`=" . $_POST['allowduplicates'] . ", ";
|
||||
}
|
||||
if (isset($_POST['casesensitive'])) {
|
||||
$query .= "`case_sensitive`=" . $_POST['casesensitive'] . ", ";
|
||||
}
|
||||
if (isset($_POST['partsofspeech'])) {
|
||||
$query .= "`parts_of_speech`='" . $_POST['partsofspeech'] . "', ";
|
||||
}
|
||||
if (isset($_POST['sortbyequivalent'])) {
|
||||
$query .= "`sort_by_equivalent`='" . $_POST['sortbyequivalent'] . "', ";
|
||||
}
|
||||
if (isset($_POST['iscomplete'])) {
|
||||
$query .= "`is_complete`=" . $_POST['iscomplete'] . ", ";
|
||||
}
|
||||
if (isset($_POST['ispublic'])) {
|
||||
$query .= "`is_public`=" . $_POST['ispublic'] . ", ";
|
||||
}
|
||||
|
||||
$query .= "`last_updated`='" . date("Y-m-d H:i:s") . "'";
|
||||
$query .= " WHERE `id`=" . $_SESSION['dictionary'] . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
echo "updated successfully";
|
||||
return true;
|
||||
if ($_SESSION['user'] > 0) {
|
||||
if (isset($_SESSION['dictionary'])) {
|
||||
$query = "UPDATE `dictionaries` SET ";
|
||||
|
||||
if (isset($_POST['name'])) {
|
||||
$query .= "`name`='" . $_POST['name'] . "', ";
|
||||
}
|
||||
if (isset($_POST['description'])) {
|
||||
$query .= "`description`='" . $_POST['description'] . "', ";
|
||||
}
|
||||
if (isset($_POST['words'])) {
|
||||
$query .= "`words`='" . $_POST['words'] . "', ";
|
||||
}
|
||||
if (isset($_POST['nextwordid'])) {
|
||||
$query .= "`next_word_id`=" . $_POST['nextwordid'] . ", ";
|
||||
}
|
||||
if (isset($_POST['allowDuplicates'])) {
|
||||
$query .= "`allow_duplicates`=" . $_POST['allowduplicates'] . ", ";
|
||||
}
|
||||
if (isset($_POST['casesensitive'])) {
|
||||
$query .= "`case_sensitive`=" . $_POST['casesensitive'] . ", ";
|
||||
}
|
||||
if (isset($_POST['partsofspeech'])) {
|
||||
$query .= "`parts_of_speech`='" . $_POST['partsofspeech'] . "', ";
|
||||
}
|
||||
if (isset($_POST['sortbyequivalent'])) {
|
||||
$query .= "`sort_by_equivalent`='" . $_POST['sortbyequivalent'] . "', ";
|
||||
}
|
||||
if (isset($_POST['iscomplete'])) {
|
||||
$query .= "`is_complete`=" . $_POST['iscomplete'] . ", ";
|
||||
}
|
||||
if (isset($_POST['ispublic'])) {
|
||||
$query .= "`is_public`=" . $_POST['ispublic'] . ", ";
|
||||
}
|
||||
|
||||
$query .= "`last_updated`='" . date("Y-m-d H:i:s") . "'";
|
||||
$query .= " WHERE `id`=" . $_SESSION['dictionary'] . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
echo "updated successfully";
|
||||
return true;
|
||||
} else {
|
||||
echo "could not update";
|
||||
}
|
||||
} else {
|
||||
echo "could not update";
|
||||
Save_Current_DictionaryAsNew();
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not logged in";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Switch_Current_Dictionary($newdictionaryid, $returndictionary = true) {
|
||||
if (isset($newdictionaryid) && isset($_SESSION['user'])) {
|
||||
if (in_array($newdictionaryid, $_SESSION['dictionaries'])) {
|
||||
//Clear is_current from all user's dictionaries and then update the one they chose, only if the chosen dictionary is valid.
|
||||
$query = "UPDATE `dictionaries` SET `is_current`=0 WHERE `user`=" . $_SESSION['user'] . ";";
|
||||
$query .= "UPDATE `dictionaries` SET `is_current`=1 WHERE `id`=" . $newdictionaryid . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
if ($returndictionary) {
|
||||
Load_Current_Dictionary();
|
||||
if ($_SESSION['user'] > 0) {
|
||||
if (isset($newdictionaryid)) {
|
||||
if (in_array($newdictionaryid, $_SESSION['dictionaries'])) {
|
||||
//Clear is_current from all user's dictionaries and then update the one they chose, only if the chosen dictionary is valid.
|
||||
$query = "UPDATE `dictionaries` SET `is_current`=0 WHERE `user`=" . $_SESSION['user'] . ";";
|
||||
$query .= "UPDATE `dictionaries` SET `is_current`=1 WHERE `id`=" . $newdictionaryid . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
if ($returndictionary) {
|
||||
Load_Current_Dictionary();
|
||||
} else {
|
||||
echo "dictionary switched";
|
||||
}
|
||||
// return true;
|
||||
} else {
|
||||
echo "dictionary switched";
|
||||
echo "could not update";
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
echo "could not update";
|
||||
echo "invalid dictionary";
|
||||
}
|
||||
} else {
|
||||
echo "invalid dictionary";
|
||||
echo "no info provided";
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not logged in";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*function Delete_Current_Dictionary($deletedictionaryid) {
|
||||
if (isset($deletedictionaryid) && isset($_SESSION['user'])) {
|
||||
if (in_array($deletedictionaryid, $_SESSION['dictionaries'])) {
|
||||
//Clear is_current from all user's dictionaries and then update the one they chose, only if the chosen dictionary is valid.
|
||||
$query = "DELETE FROM `dictionaries` WHERE `id`=" . $deletedictionaryid . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
Get_Dictionaries(false);
|
||||
$query = "UPDATE `dictionaries` SET `is_current`=1 WHERE `id`=" . $_SESSION['dictionaries'][0] . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
function Delete_Current_Dictionary() {
|
||||
if ($_SESSION['user'] > 0) {
|
||||
if (isset($_SESSION['dictionary'])) {
|
||||
if (in_array($_SESSION['dictionary'], $_SESSION['dictionaries'])) {
|
||||
//Clear is_current from all user's dictionaries and then update the one they chose, only if the chosen dictionary is valid.
|
||||
$query = "DELETE FROM `dictionaries` WHERE `id`=" . $_SESSION['dictionary'] . " AND `user`=" . $_SESSION['user'] . ";";
|
||||
$update = query($query);
|
||||
|
||||
if ($update) {
|
||||
Load_Current_Dictionary();
|
||||
Get_Dictionaries(true);
|
||||
} else {
|
||||
echo "could not delete";
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
echo "could not update";
|
||||
echo "invalid dictionary";
|
||||
}
|
||||
} else {
|
||||
echo "invalid dictionary";
|
||||
echo "no current dictionary";
|
||||
}
|
||||
} else {
|
||||
echo "no info provided";
|
||||
echo "not logged in";
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue