|
|
@@ -70,6 +70,8 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response |
|
|
|
if (isset($_SESSION['username'])) { |
|
|
|
if ($request->getMethod() == 'GET') { |
|
|
|
addNavbar($response); |
|
|
|
$response->getBody()->write($_SESSION['error']); |
|
|
|
$response->getBody()->write('<hr/>'); |
|
|
|
$response->getBody()->write('<form action="/blog/create" method="POST">'); |
|
|
|
$response->getBody()->write('<label for="slug">slug:</label>'); |
|
|
|
$response->getBody()->write('<input type="text" name="slug"/><br/>'); |
|
|
@@ -79,10 +81,21 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response |
|
|
|
$response->getBody()->write('<textarea type="textarea" name="content"></textarea><br/>'); |
|
|
|
$response->getBody()->write('<input type="submit"/>'); |
|
|
|
addFooter($response); |
|
|
|
unset($_SESSION['error']); |
|
|
|
} else { |
|
|
|
$data = $request->getParsedBody(); |
|
|
|
$_SESSION['blogs'][] = ["slug" => $data['slug'], "title" => $data['title'], "content" => "Lorem ipsum 4"]; |
|
|
|
return $response->withHeader('Location', '/')->withStatus(302); |
|
|
|
global $db; |
|
|
|
$sql = "INSERT INTO blogs (slug, title, content) VALUES ('" . $data['slug'] . "', '" . $data['title'] . "', '" . $data['content'] . "')"; |
|
|
|
$ret = $db->exec($sql); |
|
|
|
//$_SESSION['blogs'][] = ["slug" => $data['slug'], "title" => $data['title'], "content" => "Lorem ipsum 4"]; |
|
|
|
|
|
|
|
if ($ret) { |
|
|
|
return $response->withHeader('Location', '/')->withStatus(302); |
|
|
|
} else { |
|
|
|
$err = $db->lastErrorMsg(); |
|
|
|
$_SESSION['error'] = $err; |
|
|
|
return $response->withHeader('Location', '/blog/create')->withStatus(302); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
addNavbar($response); |