summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-12-10 20:22:33 +0100
committersteckbrief <steckbrief@chefmail.de>2017-12-10 20:22:33 +0100
commit2ec5cbc2aa2fe992d2cccaf6d160950adef521ef (patch)
tree726ff2e5907825469d81ea8af9e900a864ebc4a6
parent6bf09a069577fa9fcefdb0f92da81001465a50e0 (diff)
create story and character improved
-rw-r--r--config/config.inc.php3
-rw-r--r--config/text.inc.php4
-rw-r--r--createCharacter.php39
-rw-r--r--createStory.php13
-rw-r--r--index.php22
-rw-r--r--js/stories.js42
m---------lib/commons0
-rw-r--r--lib/functions.stories.inc.php8
-rw-r--r--lib/new-character-dialog.inc.php41
-rw-r--r--lib/new-story-dialog.inc.php6
10 files changed, 168 insertions, 10 deletions
diff --git a/config/config.inc.php b/config/config.inc.php
new file mode 100644
index 0000000..f4ea2f5
--- /dev/null
+++ b/config/config.inc.php
@@ -0,0 +1,3 @@
+<?php
+return [];
+?>
diff --git a/config/text.inc.php b/config/text.inc.php
new file mode 100644
index 0000000..b5ec213
--- /dev/null
+++ b/config/text.inc.php
@@ -0,0 +1,4 @@
+<?php
+return [];
+?>
+
diff --git a/createCharacter.php b/createCharacter.php
new file mode 100644
index 0000000..f5015bb
--- /dev/null
+++ b/createCharacter.php
@@ -0,0 +1,39 @@
+<?php
+/*
+ *
+ * createStory.php
+ *
+ */
+
+require_once(__DIR__.'/lib/commons/functions.common.inc.php');
+require_once(__DIR__.'/lib/commons/functions.http.inc.php');
+require_once(__DIR__.'/lib/functions.stories.inc.php');
+
+//print_r($_POST);exit();
+
+$storyName = getMandatoryPostParameter('story-name', NULL, true);
+$charName = getMandatoryPostParameter('char-name', NULL, true);
+$charPassphoto = getOptionalFileParameter('char-passphoto');
+$charDescription = getOptionalPostParameter('char-description');
+
+//$pathToChar = __DIR__.DIRECTORY_SEPARATOR.'stories'.DIRECTORY_SEPARATOR.generateDirectoryName($storyName).DIRECTORY_SEPARATOR.generateDirectoryName($charName);
+
+$pathToChar = generatePath(['stories', $storyName, $charName], __DIR__);
+echo $pathToChar;
+$result = createEntity($pathToChar, $charDescription, $charPassphoto, 'passphoto.png');
+if (TRUE !== $result) {
+ switch ($result) {
+ case 1:
+ sendHttpReturnCodeAndJson(409, 'Character exists already');
+ break;
+ case 2:
+ sendHttpReturnCodeAndJson(500, 'Could not create directory for character');
+ break;
+ default:
+ sendHttpReturnCodeAndJson(500, 'Unexpected error');
+ }
+} else {
+ sendHttpReturnCodeAndMessage(201);
+}
+
+?>
diff --git a/createStory.php b/createStory.php
index 83d9000..f3c5666 100644
--- a/createStory.php
+++ b/createStory.php
@@ -13,11 +13,20 @@ $storyName = getMandatoryPostParameter('story-name', '', true);
$storyLogoFile = getOptionalFileParameter('story-logo');
$storyDescription = getOptionalPostParameter('story-description');
-$pathToStory = __DIR__.DIRECTORY_SEPARATOR.'stories'.DIRECTORY_SEPARATOR.generateDirectoryName($storyName);
+$pathToStory = generatePath(['stories', $storyName], __DIR__);
$result = createEntity($pathToStory, $storyDescription, $storyLogoFile, 'logo.png');
if (TRUE !== $result) {
- sendHttpReturnCodeAndJson(500, $result);
+ switch ($result) {
+ case 1:
+ sendHttpReturnCodeAndJson(409, 'Story exists already');
+ break;
+ case 2:
+ sendHttpReturnCodeAndJson(500, 'Could not create directory for story');
+ break;
+ default:
+ sendHttpReturnCodeAndJson(500, 'Unexpected error');
+ }
} else {
sendHttpReturnCodeAndMessage(201);
}
diff --git a/index.php b/index.php
index a7c71a5..d5654a2 100644
--- a/index.php
+++ b/index.php
@@ -1,16 +1,20 @@
<?php
-require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'commons'.DIRECTORY_SEPARATOR.'functions.common.inc.php');
-require_once(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'functions.stories.inc.php');
+include_once(__DIR__.'/lib/commons/functions.common.inc.php');
+include_once(__DIR__.'/lib/commons/functions.http.inc.php');
+include_once(__DIR__.'/lib/functions.stories.inc.php');
-$storiesDir = __DIR__.DIRECTORY_SEPARATOR.'stories';
+$config = require(__DIR__.'/config/config.inc.php');
+$txt = require(__DIR__.'/config/text.inc.php');
+
+$storiesDir = __DIR__.'/stories';
$storiesDirContent = getDirectoryContent($storiesDir);
$isAuthenticated = true;
$isAdmin = true;
-$currentStory = $_GET['story'];
+$currentStory = getOptionalGetParameter('story');
$currentStoryIsSet = isset($currentStory) && !empty($currentStory);
$stories = array();
$characters = array();
@@ -21,7 +25,7 @@ foreach ($storiesDirContent as $storyName) {
$storyDescription = file_get_contents($storyPath.DIRECTORY_SEPARATOR.'description.txt');
$stories[$storyName] = $storyDescription;
- if ($currentStoryIsSet && $currentStory == $storyName) {
+ if ($currentStoryIsSet && urlencode($currentStory) == $storyName) {
$charactersDirContent = array_diff(scandir($storyPath), array('..', '.'));
foreach ($charactersDirContent as $character) {
@@ -69,6 +73,7 @@ function printEntities($entities, $storyName = NULL) {
<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 src="js/stories.js"></script>
<style type="text/css">
.figure-desc {
text-align: justify;
@@ -80,6 +85,9 @@ function printEntities($entities, $storyName = NULL) {
.story-header {
font-size: 2em;
}
+ .navbar {
+ height: 50px;
+ }
.spacer {
height: 55px;
}
@@ -146,7 +154,9 @@ function printEntities($entities, $storyName = NULL) {
<?php
if ($isAuthenticated && $isAdmin) {
if (!$currentStoryIsSet) {
- include(__DIR__.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'new-story-dialog.inc.php');
+ include(__DIR__.'/lib/new-story-dialog.inc.php');
+ } else {
+ include(__DIR__.'/lib/new-character-dialog.inc.php');
}
}
?>
diff --git a/js/stories.js b/js/stories.js
new file mode 100644
index 0000000..535bb85
--- /dev/null
+++ b/js/stories.js
@@ -0,0 +1,42 @@
+function createNewCharacter() {
+ var formName = 'create-char-form';
+ var url = 'createCharacter.php';
+ var modalName = 'newCharModal';
+ create(formName, url, modalName);
+}
+
+function createNewStory() {
+ var formName = 'create-story-form';
+ var url = 'createStory.php';
+ var modalName = 'newStoryModal';
+ create(formName, url, modalName);
+}
+
+function create(formName, url, modalName) {
+ var form = $('#' + formName)[0];
+ var data = new FormData(form);
+ //var file = $('#story-logo').prop('files')[0];
+ //data.append('file', file);
+ jQuery.ajax({
+ url: url,
+ data: data,
+ cache: false,
+ contentType: false,
+ processData: false,
+ method: 'POST'
+ }).done(function(data, textStatus) {
+ console.log("Success!");
+ console.log(data);
+ console.log(textStatus);
+ $('#' + modalName).modal('hide');
+ }).fail(function(jqXHR, textStatus) {
+ if (409 == jqXHR.status) {
+ var errorElement = $('<div id="error">').text('Ein Charakter mit diesem Namen existiert bereits');
+ $(form).append(errorElement);
+ } else if (500 == jqXHR.status) {
+ }
+ console.log("An error occurred, the files couldn't be sent!");
+ console.log(jqXHR);
+ console.log(textStatus);
+ });
+}
diff --git a/lib/commons b/lib/commons
-Subproject c906747e7aef1308b956a62c911d726065a39ad
+Subproject eb2e78a12505b8d41e0ef62cb1b321cdc540e5f
diff --git a/lib/functions.stories.inc.php b/lib/functions.stories.inc.php
index a8102c3..b882869 100644
--- a/lib/functions.stories.inc.php
+++ b/lib/functions.stories.inc.php
@@ -9,8 +9,8 @@ function visibleName($nameWithUnderscore) {
return urldecode($nameWithUnderscore);
}
-function generateDirectoryName($storyName) {
- return urlencode($storyName);
+function generateDirectoryName($name) {
+ return urlencode($name);
}
function createEntity($path, $description, $file, $filename) {
@@ -27,7 +27,11 @@ function createEntity($path, $description, $file, $filename) {
}
} else {
// Error on directory creation
+ // return 'Could not create directory "'.$path;
+ return 2;
}
+ } else {
+ return 1;
}
}
?>
diff --git a/lib/new-character-dialog.inc.php b/lib/new-character-dialog.inc.php
new file mode 100644
index 0000000..5cf25c0
--- /dev/null
+++ b/lib/new-character-dialog.inc.php
@@ -0,0 +1,41 @@
+<?php
+?>
+ <span id="add-new-character-btn" class="floating-action-btn" data-toggle="modal" data-target="#newCharacterModal">
+ +
+ </span>
+ <!-- Modal -->
+ <div class="modal fade" id="newCharacterModal" 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">Neuen Charakter anlegen</h4>
+ </div>
+ <div class="modal-body">
+ <form action="" method="post" enctype="multipart/form-data" id="create-char-form">
+ <input type="hidden" name="story-name" id="story-name" value="<?=$currentStory;?>">
+ <div class="form-group">
+ <label for="name">Name des Charakters:</label>
+ <input type="text" class="form-control" id="char-name" name="char-name">
+ </div>
+ <div class="form-group">
+ <label for="story-description">Beschreibung des Charakters:</label>
+ <textarea class="form-control" rows="5" id="char-description" name="char-description"></textarea>
+ </div>
+ <div class="form-group">
+ <label for="story-logo">Foto des Charakters:</label>
+ <input type="file" name="char-passphoto" id="char-passphoto">
+ </div>
+ <button type="submit" class="btn btn-info btn-sm">Anlegen</button>
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+ <script>
+ $('#create-char-form').submit(function(event) {
+ createNewCharacter();
+ event.preventDefault();
+ });
+ </script>
diff --git a/lib/new-story-dialog.inc.php b/lib/new-story-dialog.inc.php
index ee55e4b..73c6abf 100644
--- a/lib/new-story-dialog.inc.php
+++ b/lib/new-story-dialog.inc.php
@@ -36,3 +36,9 @@
</div>
</div>
</div>
+ <script>
+ $('#create-story-form').submit(function(event) {
+ createNewStory();
+ event.preventDefault();
+ });
+ </script>