Commit 4fa33735 authored by Michael Ochmann's avatar Michael Ochmann
Browse files

added present statistics

parent 143587be
<?php
use Phinx\Migration\AbstractMigration;
class GuestPresent extends AbstractMigration {
public function change() {
$table = $this->table("users");
$table->addColumn("present", "boolean", ["null" => false, "default" => false])
->save();
}
}
......@@ -39,8 +39,34 @@ $(document).ready(function() {
popAlert("Du musst eingeloggt sein, um einen Platz reservieren zu können.");
}
});
$(".delete").click(function(event) {
event.preventDefault();
const id = $(this).data("id");
$.ajax({
url : `seats/${id}`,
type : "DELETE",
success : response => {
window.self.location.reload();
}
});
});
$(".present").change(function(event) {
event.preventDefault();
const id = $(this).data("user");
$.ajax({
url : `user/${id}/present`,
type : "PUT",
success : response => {
console.log(response);
//window.self.location.reload();
}
});
});
});
function pop(text, idSel){
id = idSel;
$('#pop > span').html(text);
......
......@@ -46,11 +46,14 @@ class NIV {
$this->router->post("/seat/([0-9]+)", \niv\controllers\ClaimSeat::class);
$this->router->delete("/seats", \niv\controllers\UnclaimSeat::class);
$this->router->delete("/seats/([0-9]+)", \niv\controllers\UnclaimSeat::class);
$this->router->get("/infoscreen", \niv\controllers\Infoscreen::class);
$this->router->get("/session/([a-z0-9]+)", \niv\controllers\Session::class);
$this->router->put("/user/([0-9]+)/present", \niv\controllers\GuestPresent::class);
$this->router->route();
......
<?php
namespace niv\controllers;
class GuestPresent extends Controller {
public function __invoke(array $matches, \niv\Services &$services): bool {
$db =& $services[\niv\services\Database::class];
$auth =& $services[\niv\services\Authentication::class];
$user =& $auth->user();
$id = $matches[1];
if (!$user->isAdmin) {
echo '{"status" : 501}';
exit;
}
$query = $db->prepare("SELECT id, present from users WHERE id = ? LIMIT 1");
$query->bind_param("i", $id);
$query->execute();
$result = $query->get_result()->fetch_object();
$present = 1 - (int)$result->present;
$db->query("UPDATE users SET present = '$present' WHERE id = '$result->id'");
echo '{"status" : 200}';
return true;
}
}
......@@ -12,13 +12,17 @@ class UnclaimSeat extends Controller {
if (!$auth->authenticated())
return false;
echo json_encode($user);
if ($user->rft === null) {
$query = $db->prepare("DELETE FROM seats WHERE userID = ?");
$query->bind_param("i", $user->id);
if(count($matches) > 1 && $user->isAdmin) {
$query = $db->prepare("DELETE FROM seats WHERE id = ?");
$query->bind_param("i", $matches[1]);
} else {
$query = $db->prepare("DELETE FROM seats WHERE rft = ?");
$query->bind_param("s", $user->rft);
if ($user->rft === null) {
$query = $db->prepare("DELETE FROM seats WHERE userID = ?");
$query->bind_param("i", $user->id);
} else {
$query = $db->prepare("DELETE FROM seats WHERE rft = ?");
$query->bind_param("s", $user->rft);
}
}
$query->execute();
......
......@@ -21,7 +21,7 @@ class Main extends Info implements Model {
public function loadGuests() {
$this->guests = $this->db->query("
SELECT seats.id seat, users.id, users.rft, users.firstname, users.lastname, users.email FROM users
SELECT seats.id seat, users.id, users.rft, users.firstname, users.lastname, users.email, users.present FROM users
LEFT JOIN seats ON users.id = seats.userID
");
}
......
......@@ -11,11 +11,13 @@ class User implements Model {
public $registrationCode;
public $authenticated;
public $isAdmin;
public $isPresent;
private $db;
public function __construct(\niv\services\Database &$db, int $id = null) {
$this->db =& $db;
$this->isAdmin = false;
$this->db =& $db;
$this->isAdmin = false;
$this->isPresent = false;
if ($id === null && !isset($_SERVER["Shib-Session-ID"])) {
$this->authenticated = false;
......@@ -44,6 +46,7 @@ class User implements Model {
$this->registrationCode = $user->registrationCode;
$this->authenticated = true;
$this->isAdmin = $user->isAdmin == 1;
$this->isPresent = $user->present == 1;
}
private function authShib() {
......
......@@ -40,6 +40,8 @@
<th>Vorname</th>
<th>E-Mail</th>
<th>Sitzplatz</th>
<th style="text-align: center;">Anwesend</th>
<th>&nbsp;</th>
</tr>
{{#guests}}
<tr>
......@@ -49,6 +51,15 @@
<td>{{firstname}}</td>
<td>{{email}}</td>
<td>{{#seat}}{{seat}}{{/seat}}{{^seat}}-{{/seat}}</td>
<td style="text-align: center;">
{{#present}}
<input type="checkbox" class="present" data-user="{{id}}" checked>
{{/present}}
{{^present}}
<input type="checkbox" class="present" data-user="{{id}}">
{{/present}}
</td>
<td>{{#seat}}<a href="#" class="delete" data-id="{{seat}}">X</a>{{/seat}}{{^seat}}{{/seat}}</td>
</tr>
{{/guests}}
</table>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment