summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin.html98
-rw-r--r--createStory.php25
-rw-r--r--index.php8
-rw-r--r--lib/functions.stories.php33
4 files changed, 159 insertions, 5 deletions
diff --git a/admin.html b/admin.html
new file mode 100644
index 0000000..ba5d37f
--- /dev/null
+++ b/admin.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html lang="de">
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="https://www.sl-its.de/css/bootstrap.spacelab.min.css">
+ <script src="https://www.sl-its.de/js/jquery-1.11.2.min.js"></script>
+ <script src="js/bootstrap.min.js"></script>
+ <script>
+ function uploadSeriesLogo() {
+ var data = new FormData($('#create-story-form')[0]);
+ //var file = $('#story-logo').prop('files')[0];
+ //data.append('file', file);
+ jQuery.ajax({
+ url: 'createStory.php',
+ data: data,
+ cache: false,
+ contentType: false,
+ processData: false,
+ method: 'POST'
+ }).done(function(data, textStatus){
+ console.log("Success: Files sent!");
+ console.log(data);
+ console.log(textStatus);
+ }).fail(function(jqXHR, textStatus){
+ console.log("An error occurred, the files couldn't be sent!");
+ console.log(jqXHR);
+ console.log(textStatus);
+ });
+ }
+ </script>
+ <style type="text/css">
+ .figure-desc {
+ text-align: justify;
+ }
+ .figure-pic {
+ height: 300px;
+ width: 300px;
+ }
+ .spacer {
+ height: 55px;
+ }
+ </style>
+ <title>Kindergeschichten - Admin</title>
+ </head>
+ <body>
+ <nav class="navbar navbar-default navbar-fixed-top navbar-right">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">Kindergeschichten - Admin</a>
+ <button type="button" class="navbar-toggle navbar-toggle-si" data-toggle="collapse" data-target=".navbar-collapse">
+ <span class="sr-only">Toggle navigation</span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </button>
+ </div>
+ <div class="container-fluid">
+ <div class="collapse navbar-collapse" id="myNavbar">
+ <ul class="nav navbar-nav">
+ </ul>
+ </div>
+ </div>
+ </nav>
+ <div class="spacer"></div>
+
+ <div class="container">
+ <!-- Trigger the modal with a button -->
+ <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#newSeriesModal">Neue Kindergeschichte</button>
+
+ <!-- Modal -->
+ <div class="modal fade" id="newSeriesModal" role="dialog">
+ <div class="modal-dialog">
+
+ <!-- Modal content-->
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal">&times;</button>
+ <h4 class="modal-title">Neue Kindergeschichte anlegen</h4>
+ </div>
+ <div class="modal-body">
+ <form action="" method="post" enctype="multipart/form-data" id="create-story-form">
+ <div class="form-group">
+ <label for="name">Name der Kindergeschichte:</label>
+ <input type="text" class="form-control" id="story-name">
+ </div>
+ <div class="form-group">
+ <input type="file" name="story-logo" id="story-logo">
+ </div>
+ <button type="submit" class="btn btn-info btn-sm">Anlegen</button>
+ </form>
+ </div>
+ </div>
+
+ </div>
+ </div>
+
+ </div>
+ </body>
+</html> \ No newline at end of file
diff --git a/createStory.php b/createStory.php
new file mode 100644
index 0000000..906a302
--- /dev/null
+++ b/createStory.php
@@ -0,0 +1,25 @@
+<?php
+/*
+ *
+ * createStory.php
+ *
+ */
+
+require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'commons'.DIRECTORY_SEPARATOR.'functions.common.inc.php');
+require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'commons'.DIRECTORY_SEPARATOR.'functions.http.inc.php');
+require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'functions.stories.inc.php');
+
+$storyName = getMandatoryPostParameter('story-name', '', true);
+$storyLogoFile = getOptionalPostParameter('story-logo');
+$storyDescription = getOptionalPostParameter('story-description');
+
+$pathToStory = __DIR__.DIRECTORY_SEPARATOR.generateDirectoryName($storyName);
+
+$result = createEntity($pathToStory, $storyDescription, $storyLogoFile, 'logo.png');
+if (TRUE !== $result) {
+ sendHttpReturnCodeAndJson(500, $result);
+} else {
+ sendHttpReturnCodeAndMessage(201);
+}
+
+?>
diff --git a/index.php b/index.php
index 9c96bfb..d4dff95 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,7 @@
<?php
+require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'functions.stories.php');
+
$tvSeriesDir = ".";
$tvSeriesDirContent = array_diff(scandir($tvSeriesDir), array('..', '.'));
@@ -26,10 +28,6 @@ foreach ($tvSeriesDirContent as $tvSeriesName) {
}
}
-function visibleName($nameWithUnderscore) {
- return str_replace('_', ' ', $nameWithUnderscore);
-}
-
$currentTvSeriesName = visibleName($currentTvSeries);
?>
@@ -93,7 +91,7 @@ $currentTvSeriesName = visibleName($currentTvSeries);
</div>
<?php
foreach ($characters as $character=>$characterDescription) {
- $characterName = str_replace('_', ' ', $character);
+ $characterName = visibleName($character);
?>
<!-- <?=$characterName;?> -->
<div class="row">
diff --git a/lib/functions.stories.php b/lib/functions.stories.php
new file mode 100644
index 0000000..a8102c3
--- /dev/null
+++ b/lib/functions.stories.php
@@ -0,0 +1,33 @@
+<?php
+/*
+ * functions.stories.php
+ */
+
+
+function visibleName($nameWithUnderscore) {
+ //return str_replace('_', ' ', $nameWithUnderscore);
+ return urldecode($nameWithUnderscore);
+}
+
+function generateDirectoryName($storyName) {
+ return urlencode($storyName);
+}
+
+function createEntity($path, $description, $file, $filename) {
+ if (!dir_exists($path)) {
+ // create directory for story
+ if (mkdir($path)) {
+ // create description file
+ if (file_put_contents($path.DIRECTORY_SEPARATOR.'description.txt', $description) === FALSE) {
+ // Error on writing description file
+ }
+ // move uploaded logo
+ if (NULL === $file || move_uploaded_file($file['tmp_name'], $path.DIRECTORY_SEPARATOR.$filename)) {
+ return TRUE;
+ }
+ } else {
+ // Error on directory creation
+ }
+ }
+}
+?>