Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: Fix Ports Table AdminDown Search #5426

Merged
merged 1 commit into from Jan 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 30 additions & 16 deletions html/includes/table/ports.inc.php
Expand Up @@ -28,23 +28,23 @@
$sql = 'FROM `ports`';

if (is_admin() === false && is_read() === false) {
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `ports`.`device_id` = `DP`.`device_id`';
$sql .= ' LEFT JOIN `ports_perms` AS `PP` ON `ports`.`port_id` = `PP`.`port_id`';
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `ports`.`device_id` = `DP`.`device_id`';
$sql .= ' LEFT JOIN `ports_perms` AS `PP` ON `ports`.`port_id` = `PP`.`port_id`';

$where .= ' AND (`DP`.`user_id`=? OR `PP`.`user_id`=?)';
$where .= ' AND (`DP`.`user_id`=? OR `PP`.`user_id`=?)';
$param[] = $_SESSION['user_id'];
$param[] = $_SESSION['user_id'];
}

$sql .= ' LEFT JOIN `devices` AS `D` ON `ports`.`device_id` = `D`.`device_id`';

if (!empty($_POST['hostname'])) {
$where .= ' AND `D`.`hostname` LIKE ?';
$where .= ' AND `D`.`hostname` LIKE ?';
$param[] = '%' . $_POST['hostname'] . '%';
}

if (!empty($_POST['location'])) {
$where .= " AND `D`.`location` = ?";
$where .= " AND `D`.`location` = ?";
$param[] = $_POST['location'];
}

Expand All @@ -55,13 +55,27 @@
}

if (!empty($_POST['device_id'])) {
$sql .= ' AND `ports`.`device_id`=?';
$sql .= ' AND `ports`.`device_id`=?';
$param[] = $_POST['device_id'];
}

if (!empty($_POST['state'])) {
$sql .= ' AND `ports`.`ifOperStatus`=?';
$param[] = $_POST['state'];
switch ($_POST['state']) {
case "down":
$sql .= " AND `ports`.`ifAdminStatus` = ? AND `ports`.`ifOperStatus` = ?";
$param[] = "up";
$param[] = "down";
break;
case "up":
$sql .= " AND `ports`.`ifAdminStatus` = ? AND `ports`.`ifOperStatus` = ?";
$param[] = "up";
$param[] = "up";
break;
case "admindown":
$sql .= " AND `ports`.`ifAdminStatus` = ? AND `D`.`ignore` = 0";
$param[] = "down";
break;
}
}

if (!empty($_POST['ifSpeed'])) {
Expand All @@ -81,16 +95,16 @@

if (!empty($_POST['ifAlias'])) {
$sql .= ' AND `ports`.`ifAlias` LIKE ?';
$param[] = '%'.$_POST['ifAlias'].'%';
$param[] = '%' . $_POST['ifAlias'] . '%';
}

$sql .= ' AND `ports`.`disabled`=?';
$sql .= ' AND `ports`.`disabled`=?';
$param[] = (int)(isset($_POST['disabled']) && $_POST['disabled']);

$sql .= ' AND `ports`.`ignore`=?';
$sql .= ' AND `ports`.`ignore`=?';
$param[] = (int)(isset($_POST['ignore']) && $_POST['ignore']);

$sql .= ' AND `ports`.`deleted`=?';
$sql .= ' AND `ports`.`deleted`=?';
$param[] = (int)(isset($_POST['deleted']) && $_POST['deleted']);

$count_sql = "SELECT COUNT(`ports`.`port_id`) $sql";
Expand All @@ -110,7 +124,7 @@
}

if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}

Expand Down Expand Up @@ -160,10 +174,10 @@
}

$output = array(
'current' => $current,
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
'rows' => $response,
'total' => $total,
);

echo _json_encode($output);