sentences editor in admin

This commit is contained in:
Tristan Schneider 2021-01-11 21:33:42 +01:00
parent 56c689af6a
commit 1eef45693e
3 changed files with 41 additions and 1 deletions

View File

@ -57,6 +57,7 @@ $config_data = json_decode($raw_json_config, false);
if ($login):
?>
<div>
<h3>Archiv erstellen</h3>
Bisherige Archive:
@ -74,6 +75,15 @@ $config_data = json_decode($raw_json_config, false);
Linktext: <span id="archive_link_preview"></span><br>
Inhalt: <span class="sentences" id="archive_sentences_preview"></span><br>
<button onclick="createArchive();">erstellen</button>
</div>
<div>
<h3>Text bearbeiten</h3>
<div class="sentences" id="edit_sentences_preview"></div>
<textarea id="edit_sentences_textarea" name="textarea" rows="25" style="width: 90%; font: inherit; background: transparent; border: 2px solid white; color: inherit;" oninput="refreshTextArea();"></textarea>
<button onclick="saveEditedSentences();">speichern</button>
</div>
<?php elseif (file_exists('data/admin_pwd')): ?>
@ -147,7 +157,18 @@ $config_data = json_decode($raw_json_config, false);
data.append('filename', encodeURI(document.getElementById("archive_filename_preview").innerText));
data.append('linktext', encodeURI(document.getElementById("archive_link_preview").innerText));
const Http = new XMLHttpRequest();
Http.open('POST', './archive_creator.php');
Http.open('POST', 'archive_creator.php');
Http.onreadystatechange=(e)=>{
location.reload();
}
Http.send(data);
}
function saveEditedSentences() {
var data = new FormData();
data.append('sentences', encodeURI(document.getElementById("edit_sentences_textarea").value));
const Http = new XMLHttpRequest();
Http.open('POST', 'sentences_saver.php');
Http.onreadystatechange=(e)=>{
location.reload();
}
@ -169,9 +190,17 @@ $config_data = json_decode($raw_json_config, false);
document.getElementById("lastday").valueAsNumber = Date.now()
}
function refreshTextArea() {
document.getElementById("edit_sentences_preview").innerHTML = document.getElementById("edit_sentences_textarea").value;
}
fetchSentences();
setTimeout(previewNewArchive, 500);
defaultNewArchive();
setTimeout(function () {
document.getElementById("edit_sentences_preview").innerHTML = sentences;
document.getElementById("edit_sentences_textarea").value = sentences;
}, 500);
</script>

View File

@ -80,6 +80,7 @@ $config_data = json_decode($raw_json_config, false);
</tr>
</table>
<a style="float: right;" href="admin.php">Admin</a>
<p>
<?php
$content = file_get_contents("./data/archive-links.txt") or die("ungültiger Dateiname");

10
sentences_saver.php Normal file
View File

@ -0,0 +1,10 @@
<?php
$sentences = urldecode($_REQUEST['sentences']);
file_put_contents("data/sentences.txt", $sentences);
http_response_code(200);
print("Sätze bearbeitet.");
?>