2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-03-19 03:40:29 +00:00
|
|
|
|
2020-03-19 13:37:14 +00:00
|
|
|
use function MicroHTML\{PRE};
|
|
|
|
|
2020-03-19 03:40:29 +00:00
|
|
|
class ETServer extends Extension
|
|
|
|
{
|
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
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")) {
|
2020-03-19 13:37:14 +00:00
|
|
|
error_log("register.php");
|
2020-03-23 00:06:43 +00:00
|
|
|
if (isset($_POST["data"])) {
|
2020-03-19 13:37:14 +00:00
|
|
|
$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~"));
|
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"],
|
2020-03-19 15:10:50 +00:00
|
|
|
(string)PRE(["style"=>"text-align: left; overflow: scroll;"], $row["data"]),
|
|
|
|
"main",
|
|
|
|
$n++
|
2020-03-19 13:37:14 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 03:40:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|