summaryrefslogtreecommitdiffstats
path: root/editStory.php
blob: 2e8284d39d29f84d66c3feab02b6cabb757b8b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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/commons/functions.files.inc.php');
require_once(__DIR__.'/lib/functions.stories.inc.php');

$storyName = getMandatoryPostParameter('story-name', '', true);
$storyLogoFile = getOptionalFileParameter('story-logo');
$storyDescription = getOptionalPostParameter('story-description');
$action = getMandatoryPostParameter('story-action');

$pathToStory = generatePath(['stories', $storyName], __DIR__);

if ('edit' == $action) {
    $result = editEntity($pathToStory, $storyDescription, $storyLogoFile, 'logo.png');
} else {
    $result = createEntity($pathToStory, $storyDescription, $storyLogoFile, 'logo.png');
}
if (TRUE !== $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);
}

?>