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

52 lines
1.8 KiB
PHP
Raw Normal View History

2020-03-19 03:40:29 +00:00
<?php declare(strict_types=1);
use function MicroHTML\{PRE};
2020-03-19 03:40:29 +00:00
class ETServer extends Extension
{
public function onPageRequest(PageRequestEvent $event)
{
global $database, $page, $user;
2020-03-19 03:40:29 +00:00
if ($event->page_matches("register.php")) {
error_log("register.php");
if (isset($_POST["data"])) {
$database->execute(
"INSERT INTO registration(data) VALUES(:data)",
["data"=>$_POST["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"],
2020-03-19 15:10:50 +00:00
(string)PRE(["style"=>"text-align: left; overflow: scroll;"], $row["data"]),
"main",
$n++
));
}
}
2020-03-19 03:40:29 +00:00
}
}
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{
global $config, $database;
// shortcut to latest
if ($config->get_int("et_server_version") < 1) {
$database->create_table("registration", "
id SCORE_AIPK,
responded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
data TEXT NOT NULL,
");
$config->set_int("et_server_version", 1);
log_info("et_server", "extension installed");
}
}
}