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);
$f3->route(
'GET /admin',
function($f3) {
$s = $_SERVER['SERVER_NAME'];
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())
die();
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');
}
);
$f3->run();
function Reports($f3) {
if (!$f3->get('auth')->basic())
die();
$filter = [];
if ($f3->get('PARAMS.org'))
$filter = ['organization_name = ?', $f3->get('PARAMS.org')];
$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');
$f3->run();
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body></html>
<!DOCTYPE html>
<html lang='fr'>
<head>
<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="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<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>
</button>
<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>
<li class="nav-item">
<a class="nav-link" href="{{ 'reports' | alias }}">Reports</a>
</li>
</ul>
</div>
</nav>
<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.
</repeat>
</div>
<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">
<thead>
<tr>
<th scope="col">Organization name</th>
<th scope="col">Report Id</th>
</tr>
</thead>
<tbody>
<repeat group="{{ @reports.subset }}" value="{{ @item }}">
<tr>
<td><a href="{{ 'reports_by_org', 'org='.@item.organization_name | alias }}">{{ @item.organization_name }}</a></td>
<td>{{ @item.report_id }}</td>
</tr>
</repeat>
</tbody>
</table>
</div>
</div>
<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