Apply fixes from StyleCI (#12120)

This commit is contained in:
Jellyfrog
2020-09-21 15:40:17 +02:00
committed by GitHub
parent 77c531527c
commit 82f43cb98d
1733 changed files with 18337 additions and 18540 deletions

View File

@@ -12,14 +12,14 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' => 1, 'message' => 'You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' => 1, 'message' => 'You need to be admin'];
} else {
if (isset($_POST['viewtype'])) {
if ($_POST['viewtype'] == 'fulllist') {
$deps_query = "SELECT a.device_id as id, a.hostname as hostname, a.sysName as sysName, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id = a1.parent_device_id GROUP BY a.device_id, a.hostname, a.sysName";
if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) {
if (isset($_POST['searchPhrase']) && ! empty($_POST['searchPhrase'])) {
$deps_query .= " HAVING parent LIKE ? OR hostname LIKE ? OR sysName LIKE ? ";
$count_query = "SELECT COUNT(*) FROM (" . $deps_query . ") AS rowcount";
} else {
@@ -42,17 +42,15 @@ if (!Auth::user()->hasGlobalAdmin()) {
if (is_numeric($_POST['rowCount']) && is_numeric($_POST['current'])) {
$rows = $_POST['rowCount'];
$current = $_POST['current'];
$deps_query .= " LIMIT ".$rows * ($current - 1).", ".$rows;
$deps_query .= " LIMIT " . $rows * ($current - 1) . ", " . $rows;
}
} else {
$deps_query .= " ORDER BY a.hostname";
}
if (isset($_POST['format']) && !empty($_POST['searchPhrase'])) {
$searchphrase = '%'.mres($_POST['searchPhrase']).'%';
$search_arr = array($searchphrase, $searchphrase, $searchphrase);
if (isset($_POST['format']) && ! empty($_POST['searchPhrase'])) {
$searchphrase = '%' . mres($_POST['searchPhrase']) . '%';
$search_arr = [$searchphrase, $searchphrase, $searchphrase];
$device_deps = dbFetchRows($deps_query, $search_arr);
$rec_count = dbFetchCell($count_query, $search_arr);
} else {
@@ -60,9 +58,8 @@ if (!Auth::user()->hasGlobalAdmin()) {
$rec_count = dbFetchCell($count_query);
}
if (isset($_POST['format'])) {
$res_arr = array();
$res_arr = [];
foreach ($device_deps as $myrow) {
if ($myrow['parent'] == null || $myrow['parent'] == '') {
$parent = 'None';
@@ -74,9 +71,9 @@ if (!Auth::user()->hasGlobalAdmin()) {
$sysname = ($hostname == $myrow['sysName']) ? $myrow['hostname'] : $myrow['sysName'];
array_push($res_arr, ["deviceid" => $myrow['id'], "hostname" => $hostname, "sysname" => $sysname, "parent" => $parent, "parentid" => $myrow['parentid']]);
}
$status = array('current' => $_POST['current'], 'rowCount' => $_POST['rowCount'], 'rows' => $res_arr, 'total' => $rec_count);
$status = ['current' => $_POST['current'], 'rowCount' => $_POST['rowCount'], 'rows' => $res_arr, 'total' => $rec_count];
} else {
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
} else {
// Get childs from parent id(s)
@@ -85,25 +82,25 @@ if (!Auth::user()->hasGlobalAdmin()) {
$device_deps = dbFetchRows('SELECT `device_id`,`hostname` from `devices` as a LEFT JOIN `device_relationships` as b ON b.`child_device_id` = a.`device_id` WHERE b.`child_device_id` is null ORDER BY `hostname`');
} else {
$parents = implode(',', $_POST['parent_ids']);
$device_deps = dbFetchRows("SELECT a.device_id as device_id, a.hostname as hostname, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname HAVING parentid = ?", array($parents));
$device_deps = dbFetchRows("SELECT a.device_id as device_id, a.hostname as hostname, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname HAVING parentid = ?", [$parents]);
}
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
}
} else {
// Find devices by child.
if (!is_numeric($_POST['device_id'])) {
$status = array('status' => 1, 'message' => 'Wrong device id!');
if (! is_numeric($_POST['device_id'])) {
$status = ['status' => 1, 'message' => 'Wrong device id!'];
} else {
$deps_query = 'SELECT `device_id`, `hostname` FROM `devices` AS a INNER JOIN `device_relationships` AS b ON a.`device_id` = b.`parent_device_id` WHERE ';
// device_id == 0 is the case where we have no parents.
if ($_POST['device_id'] == 0) {
$device_deps = dbFetchRows($deps_query. ' b.`parent_device_id` is null OR b.`parent_device_id` = 0 ');
$device_deps = dbFetchRows($deps_query . ' b.`parent_device_id` is null OR b.`parent_device_id` = 0 ');
} else {
$device_deps = dbFetchRows($deps_query. ' b.`child_device_id` = ?', array($_POST['device_id']));
$device_deps = dbFetchRows($deps_query . ' b.`child_device_id` = ?', [$_POST['device_id']]);
}
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
}
}