139 lines
2.7 KiB
PHP
139 lines
2.7 KiB
PHP
<?php
|
|
require_once(__DIR__ . '/helpers.php');
|
|
require_once(__DIR__ . '/logic.php');
|
|
|
|
|
|
\rosavox\logic\docs_init();
|
|
|
|
$mode = ($_GET['mode'] ?? 'list');
|
|
$id_encoded = (! empty($_GET['id']) ? $_GET['id'] : null);
|
|
$id = (($id_encoded === null) ? null : \intval($id_encoded));
|
|
|
|
|
|
function nav(string $mode, array $args) : void
|
|
{
|
|
$a = \array_merge($args, ['mode' => $mode]);
|
|
$target = \implode(
|
|
'&',
|
|
\array_map(
|
|
fn ($key) => \rosavox\helpers\string_coin(
|
|
'{{key}}={{value}}',
|
|
[
|
|
'key' => $key,
|
|
'value' => $a[$key],
|
|
]
|
|
),
|
|
\array_keys($a)
|
|
)
|
|
);
|
|
\rosavox\helpers\navigate('?' . $target);
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<link rel="stylesheet" type="text/css" href="/style.css"/>
|
|
</head>
|
|
<body>
|
|
<h1>rosavox</h1>
|
|
<?php
|
|
switch ($mode)
|
|
{
|
|
case 'list':
|
|
{
|
|
echo(
|
|
\rosavox\helpers\render(
|
|
'docs-list',
|
|
[
|
|
'entries' => \implode(
|
|
"\n",
|
|
\array_map(
|
|
fn ($entry) => \rosavox\helpers\render(
|
|
'docs-list-entry',
|
|
[
|
|
'link_open' => \rosavox\helpers\string_coin(
|
|
'?mode=edit&id={{id}}',
|
|
[
|
|
'id' => $entry['id'],
|
|
]
|
|
),
|
|
'link_read' => '#not_implemented',
|
|
'link_hear' => \rosavox\logic\docs_audio_path($entry['id']),
|
|
'text' => $entry['value']['title'],
|
|
]
|
|
),
|
|
\rosavox\logic\docs_list()
|
|
)
|
|
),
|
|
'link_new' => '?mode=make',
|
|
]
|
|
)
|
|
);
|
|
break;
|
|
}
|
|
case 'make':
|
|
{
|
|
echo(
|
|
\rosavox\helpers\render(
|
|
'docs-edit',
|
|
[
|
|
'id' => '',
|
|
'title' => '',
|
|
'authors' => '',
|
|
'content' => '',
|
|
'reasoning' => '',
|
|
'link_back' => '?mode=list',
|
|
]
|
|
)
|
|
);
|
|
break;
|
|
}
|
|
case 'edit':
|
|
{
|
|
$doc = \rosavox\logic\docs_read($id);
|
|
echo(
|
|
\rosavox\helpers\render(
|
|
'docs-edit',
|
|
[
|
|
'id' => $id_encoded,
|
|
'title' => $doc['title'],
|
|
'authors' => \implode(', ', $doc['authors']),
|
|
'content' => $doc['content'],
|
|
'reasoning' => $doc['reasoning'],
|
|
'link_back' => '?mode=list',
|
|
]
|
|
)
|
|
);
|
|
break;
|
|
}
|
|
case 'save':
|
|
{
|
|
$doc = [
|
|
'title' => $_GET['title'],
|
|
'authors' => \explode(',', $_GET['authors']),
|
|
'content' => $_GET['content'],
|
|
'reasoning' => (empty($_GET['reasoning']) ? null : $_GET['reasoning']),
|
|
];
|
|
if ($id === null)
|
|
{
|
|
$id = \rosavox\logic\docs_create($doc);
|
|
}
|
|
else
|
|
{
|
|
\rosavox\logic\docs_update($id, $doc);
|
|
}
|
|
// nav('edit', ['id' => \rosavox\logic\docs_id_encode($id)]);
|
|
nav('list', []);
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
throw (new \Exception(\sprintf('invalid mode: %s', $mode)));
|
|
break;
|
|
}
|
|
}
|
|
?>
|
|
</body>
|
|
</html>
|