2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-03-19 03:40:29 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2024-06-11 15:02:52 +00:00
|
|
|
use function MicroHTML\{CODE};
|
2020-03-19 13:37:14 +00:00
|
|
|
|
2020-03-19 03:40:29 +00:00
|
|
|
class ETServer extends Extension
|
|
|
|
{
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event): void
|
2020-03-19 03:40:29 +00:00
|
|
|
{
|
2020-03-19 13:37:14 +00:00
|
|
|
global $database, $page, $user;
|
2020-03-19 03:40:29 +00:00
|
|
|
if ($event->page_matches("register.php")) {
|
2024-02-10 00:08:55 +00:00
|
|
|
$data = $event->get_POST("data");
|
|
|
|
if ($data) {
|
2020-03-19 13:37:14 +00:00
|
|
|
$database->execute(
|
|
|
|
"INSERT INTO registration(data) VALUES(:data)",
|
2024-02-10 00:08:55 +00:00
|
|
|
["data" => $data]
|
2020-03-19 13:37:14 +00:00
|
|
|
);
|
|
|
|
$page->set_title("Thanks!");
|
|
|
|
$page->set_heading("Thanks!");
|
|
|
|
$page->add_block(new Block("Thanks!", "Your data has been recorded~"));
|
2020-03-23 00:06:43 +00:00
|
|
|
} elseif ($user->can(Permissions::VIEW_REGISTRATIONS)) {
|
2020-03-19 13:37:14 +00:00
|
|
|
$page->set_title("Registrations");
|
|
|
|
$page->set_heading("Registrations");
|
2020-03-19 15:10:50 +00:00
|
|
|
$n = 0;
|
2020-03-23 00:06:43 +00:00
|
|
|
foreach ($database->get_all("SELECT responded, data FROM registration ORDER BY responded DESC") as $row) {
|
2020-03-19 13:37:14 +00:00
|
|
|
$page->add_block(new Block(
|
|
|
|
$row["responded"],
|
2024-06-11 15:02:52 +00:00
|
|
|
CODE(["style" => "text-align: left; overflow: scroll;"], $row["data"]),
|
2020-03-19 15:10:50 +00:00
|
|
|
"main",
|
|
|
|
$n++
|
2020-03-19 13:37:14 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 03:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
2020-03-19 03:40:29 +00:00
|
|
|
{
|
2020-10-29 00:57:58 +00:00
|
|
|
global $database;
|
2020-03-19 03:40:29 +00:00
|
|
|
|
|
|
|
// shortcut to latest
|
2020-10-29 00:57:58 +00:00
|
|
|
if ($this->get_version("et_server_version") < 1) {
|
2020-03-19 03:40:29 +00:00
|
|
|
$database->create_table("registration", "
|
|
|
|
id SCORE_AIPK,
|
|
|
|
responded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
data TEXT NOT NULL,
|
|
|
|
");
|
2020-10-29 00:57:58 +00:00
|
|
|
$this->set_version("et_server_version", 1);
|
2020-03-19 03:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|