|
1 | 1 | <?php |
| 2 | +/* |
| 3 | + * LibreNMS |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License as published by the |
| 7 | + * Free Software Foundation, either version 3 of the License, or (at your |
| 8 | + * option) any later version. Please see LICENSE.txt at the top level of |
| 9 | + * the source code distribution for details. |
| 10 | + * |
| 11 | + * @package LibreNMS |
| 12 | + * @subpackage webui |
| 13 | + * @link https://www.librenms.org |
| 14 | + * @copyright 2024 LibreNMS |
| 15 | + * @author LibreNMS Contributors |
| 16 | +*/ |
2 | 17 |
|
| 18 | +echo '<form method="post" action="" id="result_form">'; |
| 19 | +echo csrf_field(); |
| 20 | +if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) { |
| 21 | + $results = $_POST['results']; |
| 22 | +} else { |
| 23 | + $results = 50; |
| 24 | +} |
| 25 | + |
| 26 | +echo '<div class="panel panel-default">'; |
| 27 | +echo '<div class="pull-right" style="padding-top: 5px;padding-right: 5px;">'; |
| 28 | +echo '<select data-toggle="popover" data-placement="left" data-content="results per page" name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">'; |
| 29 | + |
| 30 | +$result_options = [ |
| 31 | + '10', |
| 32 | + '50', |
| 33 | + '100', |
| 34 | + '250', |
| 35 | + '500', |
| 36 | + '1000', |
| 37 | + '5000', |
| 38 | + |
| 39 | +]; |
| 40 | +foreach ($result_options as $option) { |
| 41 | + echo "<option value='$option'"; |
| 42 | + if ($results == $option) { |
| 43 | + echo ' selected'; |
| 44 | + } |
| 45 | + echo ">$option</option>"; |
| 46 | +} |
| 47 | +echo '</select>'; |
| 48 | +echo '</div>'; |
| 49 | +echo '<div class="panel-heading">'; |
| 50 | +echo '<span class="tw-font-bold">Access Points</span>'; |
| 51 | +echo '</div>'; |
| 52 | +echo '</div>'; |
| 53 | +echo '<br>'; |
3 | 54 | echo "<div style='margin: 0px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>"; |
4 | 55 |
|
5 | 56 | $i = '1'; |
|
9 | 60 | } else { |
10 | 61 | $aps = dbFetchRows("SELECT * FROM `access_points` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `name`,`radio_number` ASC", [$device['device_id']]); |
11 | 62 | } |
| 63 | + |
| 64 | +$count = count($aps); |
| 65 | + |
| 66 | +if (isset($_POST['page_number']) && $_POST['page_number'] > 0 && $_POST['page_number'] <= $count) { |
| 67 | + $page_number = $_POST['page_number']; |
| 68 | +} else { |
| 69 | + $page_number = 1; |
| 70 | +} |
| 71 | + |
| 72 | +$start = (($page_number - 1) * $results); |
| 73 | + |
| 74 | + |
12 | 75 | echo "<div style='margin: 0px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>"; |
| 76 | +$index = 0; |
13 | 77 | foreach ($aps as $ap) { |
| 78 | + $index++; |
| 79 | + |
| 80 | + if ($index < $start) { |
| 81 | + continue; |
| 82 | + } |
| 83 | + if ($index > $start + $results) { |
| 84 | + break; |
| 85 | + } |
| 86 | + |
14 | 87 | include 'includes/html/print-accesspoint.inc.php'; |
15 | 88 | $i++; |
16 | 89 | } |
17 | 90 |
|
18 | 91 | echo '</table></div>'; |
19 | | - |
20 | 92 | echo '</div>'; |
| 93 | + |
| 94 | +if ($count > $results) { |
| 95 | + echo '<div class="table-responsive">'; |
| 96 | + echo '<div class="col pull-left">'; |
| 97 | + echo generate_pagination($count, $results, $page_number); |
| 98 | + echo '</div>'; |
| 99 | + echo '<div class="col pull-right">'; |
| 100 | + $showing_start = ($page_number * $results) - $results + 1; |
| 101 | + $showing_end = $page_number * $results; |
| 102 | + if ($showing_end > $count) { |
| 103 | + $showing_end = $count; |
| 104 | + } |
| 105 | + echo "<p class=\"pagination\">Showing $showing_start to $showing_end of $count access pints</p>"; |
| 106 | + echo '</div>'; |
| 107 | + echo '</div>'; |
| 108 | +} |
| 109 | + |
| 110 | +echo '<input type="hidden" name="page_number" id="page_number" value="' . htmlspecialchars($page_number) . '"> |
| 111 | + <input type="hidden" name="results_amount" id="results_amount" value="' . htmlspecialchars($results) . '"> |
| 112 | + </form>'; |
| 113 | +?> |
| 114 | +<script> |
| 115 | +function updateResults(results) { |
| 116 | + $('#results_amount').val(results.value); |
| 117 | + $('#page_number').val(1); |
| 118 | + $('#result_form').trigger( "submit" ); |
| 119 | +} |
| 120 | + |
| 121 | +function changePage(page,e) { |
| 122 | + e.preventDefault(); |
| 123 | + $('#page_number').val(page); |
| 124 | + $('#result_form').trigger( "submit" ); |
| 125 | +} |
| 126 | +</script> |
0 commit comments