This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/et_server/main.php

55 lines
1.7 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
2020-03-19 03:40:29 +00:00
namespace Shimmie2;
2024-06-11 15:02:52 +00:00
use function MicroHTML\{CODE};
2020-03-19 03:40:29 +00:00
class ETServer extends Extension
{
public function onPageRequest(PageRequestEvent $event): void
2020-03-19 03:40:29 +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) {
$database->execute(
"INSERT INTO registration(data) VALUES(:data)",
2024-02-10 00:08:55 +00:00
["data" => $data]
);
$page->set_title("Thanks!");
$page->set_heading("Thanks!");
$page->add_block(new Block("Thanks!", "Your data has been recorded~"));
} elseif ($user->can(Permissions::VIEW_REGISTRATIONS)) {
$page->set_title("Registrations");
$page->set_heading("Registrations");
2020-03-19 15:10:50 +00:00
$n = 0;
foreach ($database->get_all("SELECT responded, data FROM registration ORDER BY responded DESC") as $row) {
$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 03:40:29 +00:00
}
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
2020-03-19 03:40:29 +00:00
{
global $database;
2020-03-19 03:40:29 +00:00
// shortcut to latest
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,
");
$this->set_version("et_server_version", 1);
2020-03-19 03:40:29 +00:00
}
}
}