--- /dev/null
+<?php
+
+function smarty_function_pages($tagArgs, $tplObj) {
+ // needed params: controller, pageNo, pages
+ if (!isset($tagArgs['controller'])) throw new Exception("missing 'controller' argument in pages tag");
+ if (!isset($tagArgs['pageNo'])) {
+ if (($tagArgs['pageNo'] = $tplObj->smarty->getTemplateVars('pageNo')) === null) {
+ throw new Exception("missing 'pageNo' argument in pages tag");
+ }
+ }
+ if (!isset($tagArgs['pages'])) {
+ if (($tagArgs['pages'] = $tplObj->smarty->getTemplateVars('pages')) === null) {
+ throw new Exception("missing 'pages' argument in pages tag");
+ }
+ }
+
+ $html = '';
+
+ if ($tagArgs['pages'] > 1) {
+ $link = "index.php?page=".$tagArgs['controller'].(isset($tagArgs['id']) ? "&id=".$tagArgs['id'] : "");
+
+ if (!isset($tagArgs['pageNo'])) {
+ if (($tagArgs['pageNo'] = $tplObj->smarty->getTemplateVars('pageNo')) === null) {
+ $tagArgs['pageNo'] = 0;
+ }
+ }
+
+ // open div and ul
+ $html .= "<nav>\n<ul class='pagination'>\n";
+
+ // previous page
+ $html .= makePreviousLink($link, $tagArgs['pageNo']);
+
+ // first page
+ $html .= makeLink($link, 1, $tagArgs['pageNo'], $tagArgs['pages']);
+
+ // calculate page links
+ $maxLinks = 7;
+ $linksBeforePage = $tagArgs['pageNo'] - 2;
+ if ($linksBeforePage < 0) $linksBeforePage = 0;
+ $linksAfterPage = $tagArgs['pages'] - ($tagArgs['pageNo'] + 1);
+ if ($linksAfterPage < 0) $linksAfterPage = 0;
+ if ($tagArgs['pageNo'] > 1 && $tagArgs['pageNo'] < $tagArgs['pages']) {
+ $maxLinks--;
+ }
+
+ $half = $maxLinks / 2;
+ $left = $right = $tagArgs['pageNo'];
+ if ($left < 1) $left = 1;
+ if ($right < 1) $right = 1;
+ if ($right > $tagArgs['pages'] - 1) $right = $tagArgs['pages'] - 1;
+
+ if ($linksBeforePage >= $half) {
+ $left -= $half;
+ }
+ else {
+ $left -= $linksBeforePage;
+ $right += $half - $linksBeforePage;
+ }
+
+ if ($linksAfterPage >= $half) {
+ $right += $half;
+ }
+ else {
+ $right += $linksAfterPage;
+ $left -= $half - $linksAfterPage;
+ }
+
+ $right = intval(ceil($right));
+ $left = intval(ceil($left));
+ if ($left < 1) $left = 1;
+ if ($right > $tagArgs['pages']) $right = $tagArgs['pages'];
+
+ // left ... links
+ if ($left > 1) {
+ if ($left - 1 < 2) {
+ $html .= makeLink($link, 2, $tagArgs['pageNo'], $tagArgs['pages']);
+ }
+ else {
+ $html .= '<li class="button jumpTo"><a title="Gehe zu Seite" class="ttips">…</a></li>'."\n";
+ }
+ }
+
+ // visible links
+ for ($i = $left + 1; $i < $right; $i++) {
+ $html .= makeLink($link, $i, $tagArgs['pageNo'], $tagArgs['pages']);
+ }
+
+ // right ... links
+ if ($right < $tagArgs['pages']) {
+ if ($tagArgs['pages'] - $right < 2) {
+ $html .= makeLink($link, $tagArgs['pages'] - 1, $tagArgs['pageNo'], $tagArgs['pages']);
+ }
+ else {
+ $html .= '<li class="button jumpTo"><a>…</a></li>'."\n";
+ }
+ }
+
+ // last page
+ $html .= makeLink($link, $tagArgs['pages'], $tagArgs['pageNo'], $tagArgs['pages']);
+
+ // next page
+ $html .= makeNextLink($link, $tagArgs['pageNo'], $tagArgs['pages']);
+
+ // close div and ul
+ $html .= "</ul></nav>\n";
+ }
+
+ // assign html output to template var
+ if (isset($tagArgs['assign'])) {
+ $tplObj->assign($tagArgs['assign'], $html);
+ }
+
+ return $html;
+}
+
+function insertPageNumber($link, $pageNo) {
+ $link = $link ."&pageNo=".$pageNo;
+ return $link;
+}
+
+function makeLink($link, $pageNo, $activePage, $pages) {
+ // first page
+ if ($activePage != $pageNo) {
+ return '<li><a href="'.insertPageNumber($link, $pageNo).'" title="Seite '.$pageNo.'">'.intval($pageNo).'</a></li>'."\n";
+ }
+ else {
+ return '<li class="active"><a>'.intval($pageNo).'</a></li>'."\n";
+ }
+}
+
+function makePreviousLink($link, $pageNo) {
+ if ($pageNo > 1) {
+ return '<li class="skip"><a href="'.insertPageNumber($link, $pageNo - 1).'" title="Vorherige Seite" class="ttips"><span class="fa fa-angle-double-left"></span></a></li>'."\n";
+ }
+ else {
+ return '<li class="skip disabled"><span class="fa fa-angle-double-left disabled"></span></li>'."\n";
+ }
+}
+
+
+function makeNextLink($link, $pageNo, $pages) {
+ if ($pageNo && $pageNo < $pages) {
+ return '<li class="skip"><a href="'.insertPageNumber($link, $pageNo + 1).'" title="Nächste Seite" class="ttips"><span class="fa fa-angle-double-right"></span></a></li>'."\n";
+ }
+ else {
+ return '<li class="skip disabled"><span class="fa fa-angle-double-right disabled"></span></li>'."\n";
+ }
+}
\ No newline at end of file
$domains = array();
$soaIDs = User::getAccessibleDomains();
$idna = new idna_convert();
+
+ $sortField = "id";
+ $sortOrder = "ASC";
+ $sqlOrderBy = "";
+ $validSortFields = array('id', 'origin', 'serial');
+
+ if (isset($_GET['sortField'])) {
+ if (in_array($_GET['sortField'], $validSortFields)) {
+ $sortField = $_GET['sortField'];
+ }
+ }
+
+ if (isset($_GET['sortOrder'])) {
+ if ($_GET['sortOrder'] == "ASC" || $_GET['sortOrder'] == "DESC") {
+ $sortOrder = $_GET['sortOrder'];
+ }
+ }
+
+ if (!empty($sortField) && !empty($sortField)) {
+ $sqlOrderBy = $sortField." ".$sortOrder;
+ }
+
+ $pageNo = 1;
+ if (isset($_GET['pageNo']) && !empty($_GET['pageNo'])) {
+ $pageNo = intval($_GET['pageNo']);
+ }
+
+ $itemsPerPage = 20;
+ $pages = 0;
+
+ $sqlLimit = $itemsPerPage;
+ $sqlOffset = ($pageNo - 1) * $itemsPerPage;
+ $pages = intval(ceil(count($soaIDs) / $itemsPerPage));
+
+
if (count($soaIDs) > 0) {
- $sql = "SELECT * FROM dns_soa WHERE id IN (".str_repeat('?, ', count($soaIDs) - 1). "?)";
+ $sql = "SELECT * FROM dns_soa WHERE id IN (".str_repeat('?, ', count($soaIDs) - 1). "?)".(!empty($sqlOrderBy) ? " ORDER BY ".$sqlOrderBy : '')." LIMIT " . $sqlLimit . " OFFSET " . $sqlOffset;
$res = DNS::getDB()->query($sql, $soaIDs);
while ($row = DNS::getDB()->fetch_array($res)) {
$sql2 = "SELECT count(*) as count FROM dns_rr WHERE zone = ?";
}
}
- DNS::getTPL()->assign(array("domains" => $domains));
+ DNS::getTPL()->assign(array(
+ 'domains' => $domains,
+ 'pageNo' => $pageNo,
+ 'pages' => $pages,
+ 'sortField' => $sortField,
+ 'sortOrder' => $sortOrder
+ ));
}
}
$idna = new idna_convert();
+ $sql = "SELECT count(*) as count FROM dns_rr WHERE zone = ?";
+ $res = DNS::getDB()->query($sql, array($_GET['id']));
+ $row = DNS::getDB()->fetch_array($res);
+ $count = $row['count'];
+
+ $sortField = "type";
+ $sortOrder = "ASC";
+ $sqlOrderBy = "";
+ $validSortFields = array('id', 'name', 'type', 'ttl', 'data');
+
+ if (isset($_GET['sortField'])) {
+ if (in_array($_GET['sortField'], $validSortFields)) {
+ $sortField = $_GET['sortField'];
+ }
+ }
+
+ if (isset($_GET['sortOrder'])) {
+ if ($_GET['sortOrder'] == "ASC" || $_GET['sortOrder'] == "DESC") {
+ $sortOrder = $_GET['sortOrder'];
+ }
+ }
+
+ if (!empty($sortField) && !empty($sortField)) {
+ $sqlOrderBy = $sortField." ".$sortOrder;
+ }
+
+ $pageNo = 1;
+ if (isset($_GET['pageNo']) && !empty($_GET['pageNo'])) {
+ $pageNo = intval($_GET['pageNo']);
+ }
+
+ $itemsPerPage = 20;
+ $pages = 0;
+
+ $sqlLimit = $itemsPerPage;
+ $sqlOffset = ($pageNo - 1) * $itemsPerPage;
+ $pages = intval(ceil($count / $itemsPerPage));
+
$sql = "SELECT * FROM dns_soa WHERE id = ?";
$res = DNS::getDB()->query($sql, array($_GET['id']));
$soa = DNS::getDB()->fetch_array($res);
$records = array();
- $sql = "SELECT * FROM dns_rr WHERE zone = ?";
+ $sql = "SELECT * FROM dns_rr WHERE zone = ?".(!empty($sqlOrderBy) ? " ORDER BY ".$sqlOrderBy : '')." LIMIT " . $sqlLimit . " OFFSET " . $sqlOffset;
$res = DNS::getDB()->query($sql, array($_GET['id']));
while ($row = DNS::getDB()->fetch_array($res)) {
$row['name'] = $idna->decode($row['name']);
}
else {
if ($row['type'] == "TLSA" || $row['type'] == "DS") {
- $row['data'] = $$row['data'];
+ $row['data'] = $row['data'];
}
else {
$row['data'] = $idna->decode($row['data']);
$records[] = $row;
}
- DNS::getTPL()->assign(array("records" => $records, "soa" => $soa));
+ DNS::getTPL()->assign(array(
+ 'records' => $records,
+ 'soa' => $soa,
+ 'pageNo' => $pageNo,
+ 'pages' => $pages,
+ 'sortField' => $sortField,
+ 'sortOrder' => $sortOrder
+ ));
}
}
</div>
</div>
</div>
-
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Domains <span class="badge badge-black">{$domains|count}</span></div>
<div class="panel-body">
+ {pages controller='DomainList'}
<div class="dataTable_wrapper">
- <table class="table table-bordered table-hover radius table-striped dataTable" data-dontsort="4">
+ <table class="table table-bordered table-hover radius table-striped dataTable">
<thead>
<tr>
- <th>ID</th>
- <th>Name</th>
- <th>Serial</th>
+ <th><a class="sorting{if $sortField == 'id'}_{$sortOrder|strtolower}{/if}" href="index.php?page=DomainList&pageNo={$pageNo}&sortField=id&sortOrder={if $sortField == 'id' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">ID</a></th>
+ <th><a class="sorting{if $sortField == 'origin'}_{$sortOrder|strtolower}{/if}" href="index.php?page=DomainList&pageNo={$pageNo}&sortField=origin&sortOrder={if $sortField == 'origin' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">Name</a></th>
+ <th><a class="sorting{if $sortField == 'serial'}_{$sortOrder|strtolower}{/if}" href="index.php?page=DomainList&pageNo={$pageNo}&sortField=serial&sortOrder={if $sortField == 'serial' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">Serial</a></th>
<th>Records</th>
<th>Manage</th>
</tr>
</tbody>
</table>
</div>
+ {pages controller='DomainList'}
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Records <span class="badge badge-black">{$records|count}</span></div>
<div class="panel-body">
+ {pages controller='RecordList' id=$soa['id']}
<div class="dataTable_wrapper">
- <table class="table table-bordered table-hover radius table-striped dataTable" data-dontsort="6" data-sort="asc,3">
+ <table class="table table-bordered table-hover radius table-striped dataTable">
<thead>
<tr>
- <th>ID</th>
- <th>Host</th>
- <th>TTL</th>
- <th>Type</th>
+ <th><a class="sorting{if $sortField == 'id'}_{$sortOrder|strtolower}{/if}" href="index.php?page=RecordList&id={$soa['id']}&pageNo={$pageNo}&sortField=id&sortOrder={if $sortField == 'id' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">ID</th>
+ <th><a class="sorting{if $sortField == 'name'}_{$sortOrder|strtolower}{/if}" href="index.php?page=RecordList&id={$soa['id']}&pageNo={$pageNo}&sortField=name&sortOrder={if $sortField == 'name' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">Host</th>
+ <th><a class="sorting{if $sortField == 'ttl'}_{$sortOrder|strtolower}{/if}" href="index.php?page=RecordList&id={$soa['id']}&pageNo={$pageNo}&sortField=ttl&sortOrder={if $sortField == 'ttl' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">TTL</th>
+ <th><a class="sorting{if $sortField == 'type'}_{$sortOrder|strtolower}{/if}" href="index.php?page=RecordList&id={$soa['id']}&pageNo={$pageNo}&sortField=type&sortOrder={if $sortField == 'type' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">Type</th>
<th>Prio</th>
- <th>Data</th>
+ <th><a class="sorting{if $sortField == 'data'}_{$sortOrder|strtolower}{/if}" href="index.php?page=RecordList&id={$soa['id']}&pageNo={$pageNo}&sortField=data&sortOrder={if $sortField == 'data' && $sortOrder == 'ASC'}DESC{else}ASC{/if}">Data</th>
<th>Manage</th>
</tr>
</thead>
</tbody>
</table>
</div>
+ {pages controller='RecordList' id=$soa['id']}
</div>
</div>
</div>