Reputation: 5
I have a big list with mikrotikm(router) nat rules, in one table, and now I want a dynamic search filter to search the list from name, something like this:
I tried with their code but doesn't work.
I use other codes but not working..
This is the full code:
<html>
<head>
<script type='text/javascript' language='javascript' defer>
$("#search").on("keyup paste", function() {
var value = $(this).val().toUpperCase();
var $rows = $("table tr");
if(value === ''){
$rows.show();
return false;
}
$rows.each(function(index) {
if (index !== 0) {
$row = $(this);
var column1 = $row.find("td:first a").html().toUpperCase();
var column2 = $row.find("td").eq(1).text().toUpperCase();
if ((column1.indexOf(value) > -1) || (column2.indexOf(value) > -1)) {
$row.show();
}
else {
$row.hide();
}
}
});
});
</script>
<style type='text/css'>
table tr td{
border:1px solid #000
}
</style>
</head>
<body>
<label for="search">Search:</label> <input type="text" id="search" value=""/>
<?php
use PEAR2\Net\RouterOS;
// require_once 'pear2\src\PEAR2\Autoload.php';
require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';
//Conexion a Mikrotik
//IP MIKROTIK //Usuario //Password
$client = new RouterOS\Client('62.82.4.222', 'victor', 'victor');
//Reiniciar PPP
$remove=new RouterOs\Request("/ppp/active/remove");
$remove->setArgument('numbers', $itemID);
// Tabla
echo "<table align='center' id='natlist'><form action='' method='POST'>";
echo "<thead><tr bgcolor='#D8D8D8'><th align=left size=3>Nombre</th><th align=left size=3>Servicio</th><th size=3>Tiempo Activo</th><th align=left size=3>Direccion</th><th align=left size=3>Reiniciar</th></tr></thead><tbody>";
//Actualizar pagina
//echo "<meta http-equiv='refresh' content='30'>";
$ppps = $client->sendSync(new RouterOS\Request('/ppp/active/print'))->getAllOfType(RouterOS\Response::TYPE_DATA);
$interfaceQuery = RouterOS\Query::where('name', $ppps->getArgument('name'));
while ($ppp = $ppps->next()) {
$interfaceQuery->orWhere('name', $ppp('name'));
}
$activeInterfaces = $client->sendSync(new RouterOS\Request('/interface/pppoe-server/print', $interfaceQuery))->getAllOfType(RouterOS\Response::TYPE_DATA)->toArray();
foreach ($ppps as $ppp) {
$id = $ppp('.id');
$service = '';
foreach ($activeInterfaces as $index => $pppInterface) {
if ($pppInterface('name') === $ppp('name')) {
$service = $pppInterface('service');
break;
}
}
echo "<tr>";
echo "<td class='nombre'>". $ppp('name') ."</td>";
echo "<td>" . $service . "</td>";
echo "<td>" . $ppp('uptime'). "</td>";
echo "<td>". $ppp('address') ."</td>";
echo "<td><button type='submit' value='{$id}' name='act[remove]' >Reiniciar</td></tr>";
}
echo "</form></tbody></table>";
?>
</body>
</html>
Upvotes: 0
Views: 2731