Commit 201131c0 authored by Bastien Durel's avatar Bastien Durel
Browse files

put some pages

parent fddd8566
......@@ -4,19 +4,41 @@ require 'vendor/autoload.php';
require 'pdo.config.php'; # provides $dbdsn, $dbuser, $dbpass
$f3 = \Base::instance();
$f3->set('TEMP', '/tmp/f3');
$db = new DB\SQL($dbdsn, $dbuser, $dbpass);
$f3->set('DB', $db);
$user = new \DB\SQL\Mapper($db, 'users');
$auth = new BcryptAuth($user, array('id'=>'user_id', 'pw'=>'password'));
$f3->set('auth', $auth);
'GET /admin',
function($f3) {
if (strpos($s, 'mta-sts.') !== 0)
$f3->error(403, "Incorrect HTTP host");
$f3->set('domain', substr($s, 8));
class Admin {
function Home($f3) {
if (!$f3->get('auth')->basic())
echo 'TODO';
$f3->set('result', $f3->get('DB')->exec('select count(1) reports, (select count(distinct organization_name) from report) orgs from report'));
echo Template::instance()->render('tmpl/home.html');
function Reports($f3) {
if (!$f3->get('auth')->basic())
$filter = [];
if ($f3->get(''))
$filter = ['organization_name = ?', $f3->get('')];
$report = new DB\SQL\Mapper($f3->get('DB'), 'report');
$reports = $report->paginate(0, 10, $filter);
$f3->set('reports', $reports);
echo Template::instance()->render('tmpl/reports.html');
$f3->route('GET @home: /admin', 'Admin->Home');
$f3->route('GET @reports: /admin/reports', 'Admin->Reports');
$f3->route('GET @reports_by_org: /admin/reports/by/@org', 'Admin->Reports');
<script src="" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<!DOCTYPE html>
<html lang='fr'>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>MTA-STS admin for {{ @domain }}</title>
<link rel="stylesheet" href="" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{{ 'home' | alias }}">Home</a>
<li class="nav-item">
<a class="nav-link" href="{{ 'reports' | alias }}">Reports</a>
<include href="tmpl/header.html" />
<div class="container-fluid">
<h1>Admin home</h1>
<repeat group="{{ @result }}" value="{{ @item }}">
There are <span>{{ @item.reports }}</span> reports in the database,
coming from {{ @item.orgs }} different organizations.
<include href="tmpl/footer.html" />
<include href="tmpl/header.html" />
[subset] array of mapper objects that match the criteria
[total] sum of all records for all pages
[limit] same value as the size parameter (here 5)
[count] number of of subsets/pages available
[pos] actual subset position
<div class="container-fluid">
<div class="table-responsive">
<table class="table table-hover">
<th scope="col">Organization name</th>
<th scope="col">Report Id</th>
<repeat group="{{ @reports.subset }}" value="{{ @item }}">
<td><a href="{{ 'reports_by_org', 'org='.@item.organization_name | alias }}">{{ @item.organization_name }}</a></td>
<td>{{ @item.report_id }}</td>
<include href="tmpl/footer.html" />
Markdown is supported
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