summaryrefslogtreecommitdiffstats
path: root/createCharacter.php
blob: f5015bb9dcc80a7bf00b7ed34a13ed6e1e0035f6 (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
<?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);
}

?>