Updated edit ports page to use bootstrap

This commit is contained in:
laf
2015-07-20 13:55:35 +01:00
parent 7df1649bf4
commit c579805292
3 changed files with 194 additions and 143 deletions

View File

@@ -1,65 +0,0 @@
<?php
// enable/disable ports/interfaces on devices.
$device_id = intval($_POST['device']);
$rows_updated = 0;
foreach ($_POST as $key => $val) {
if (strncmp($key, 'oldign_', 7) == 0) {
// Interface identifier passed as part of the field name
$port_id = intval(substr($key, 7));
$oldign = intval($val) ? 1 : 0;
$newign = $_POST['ignore_'.$port_id] ? 1 : 0;
// As checkboxes are not posted when unset - we effectively need to do a diff to work
// out a set->unset case.
if ($oldign == $newign) {
continue;
}
$n = dbUpdate(array('ignore' => $newign), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
if ($n < 0) {
$rows_updated = -1;
break;
}
$rows_updated += $n;
}
else if (strncmp($key, 'olddis_', 7) == 0) {
// Interface identifier passed as part of the field name
$port_id = intval(substr($key, 7));
$olddis = intval($val) ? 1 : 0;
$newdis = $_POST['disabled_'.$port_id] ? 1 : 0;
// As checkboxes are not posted when unset - we effectively need to do a diff to work
// out a set->unset case.
if ($olddis == $newdis) {
continue;
}
$n = dbUpdate(array('disabled' => $newdis), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
if ($n < 0) {
$rows_updated = -1;
break;
}
$rows_updated += $n;
}//end if
}//end foreach
if ($rows_updated > 0) {
$update_message = $rows_updated.' Device record updated.';
$updated = 1;
}
else if ($rows_updated = '-1') {
$update_message = 'Device record unchanged. No update necessary.';
$updated = -1;
}
else {
$update_message = 'Device record update error.';
$updated = 0;
}

View File

@@ -0,0 +1,74 @@
<?php
$row = 1;
$device_id = $_POST['device_id'];
$sql = 'FROM `ports` WHERE `device_id` = ?';
$param = array($device_id);
$count_sql = "SELECT COUNT(`port_id`) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`ifIndex` ASC';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = (($current * $rowCount) - ($rowCount));
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
$response[] = array(
'ifIndex' => "<button id='save-form' type='submit' value='Save' class='btn btn-success btn-sm' title='Save current port disable/ignore settings'>Save</button><button type='submit' value='Reset' class='btn btn-danger btn-sm' id='form-reset' title='Reset form to previously-saved settings'>Reset</button>",
'label' => '',
'ifAdminStatus' => '',
'ifOperStatus' => "<button type='submit' value='Alerted' class='btn btn-default btn-sm' id='alerted-toggle' title='Toggle alerting on all currently-alerted ports'>Alerted</button><button type='submit' value='Down' class='btn btn-default btn-sm' id='down-select' title='Disable alerting on all currently-down ports'>Down</button>",
'disabled' => "<button type='submit' value='Toggle' class='btn btn-default btn-sm' id='disable-toggle' title='Toggle polling for all ports'>Toggle</button><button type='submit' value='Select' class='btn btn-default btn-sm' id='disable-select' title='Disable polling on all ports'>Select All</button>",
'ignore' => "<button type='submit' value='Toggle' class='btn btn-default btn-sm' id='ignore-toggle' title='Toggle alerting for all ports'>Toggle</button><button type='submit' value='Select' class='btn btn-default btn-sm' id='ignore-select' title='Disable alerting on all ports'>Select All</button>",
'ifAlias' => ''
);
foreach (dbFetchRows($sql, $param) as $port) {
$port = ifLabel($port);
// Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled
// - as to draw the attention to a possible problem.
$isportbad = ($port['ifOperStatus'] == 'down' && $port['ifAdminStatus'] != 'down') ? 1 : 0;
$dowecare = ($port['ignore'] == 0 && $port['disabled'] == 0) ? $isportbad : !$isportbad;
$outofsync = $dowecare ? " class='red'" : '';
$response[] = array(
'ifIndex' => $port['ifIndex'],
'label' => $port['label'],
'ifAdminStatus' => $port['ifAdminStatus'],
'ifOperStatus' => '<span name="operstatus_'.$port['port_id'].'"'.$outofsync.'>'.$port['ifOperStatus'].'</span>',
'disabled' => '<input type="checkbox" class="disable-check" name="disabled_'.$port['port_id'].'"'.($port['disabled'] ? 'checked' : '').'>
<input type="hidden" name="olddis_'.$port['port_id'].'" value="'.($port['disabled'] ? 1 : 0).'"">',
'ignore' => '<input type="checkbox" class="ignore-check" name="ignore_'.$port['port_id'].'"'.($port['ignore'] ? 'checked' : '').'>
<input type="hidden" name="oldign_'.$port['port_id'].'" value="'.($port['ignore'] ? 1 : 0).'"">',
'ifAlias' => $port['ifAlias']
);
}//end foreach
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
echo _json_encode($output);