2020-08-31 19:23:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class Device extends Template
|
|
|
|
{
|
2020-11-18 20:40:13 +00:00
|
|
|
function __construct($sortBy = null, $sortType = null)
|
|
|
|
{
|
|
|
|
$userManager = new UserManager();
|
|
|
|
$deviceManager = new DeviceManager();
|
|
|
|
$subDeviceManager = new SubDeviceManager();
|
|
|
|
$recordManager = new RecordManager();
|
|
|
|
$roomManager = new RoomManager();
|
|
|
|
$langMng = new LanguageManager('en');
|
|
|
|
|
|
|
|
if (!$userManager->isLogin()) {
|
2020-10-25 23:01:30 +00:00
|
|
|
header('Location: ' . BASEURL . 'login');
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$template = new Template('device');
|
|
|
|
$template->prepare('title', $langMng->get("m_devices"));
|
2020-08-31 19:23:23 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$sortWordBook = [
|
|
|
|
"id" => "device_id",
|
|
|
|
"name" => "name",
|
|
|
|
"room" => "room_id",
|
|
|
|
"ip" => "ip_address",
|
|
|
|
"mac" => "mac",
|
|
|
|
"token" => "token",
|
|
|
|
"signal" => "signal",
|
|
|
|
"firmware" => "firmware_hash",
|
|
|
|
"icon" => "icon"
|
|
|
|
];
|
2020-09-09 18:24:10 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$sortIcons = [
|
|
|
|
"ASC" => "",
|
|
|
|
"DESC" => "",
|
|
|
|
];
|
2020-09-09 18:24:10 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$nextSort = [
|
|
|
|
"ASC" => "DESC",
|
|
|
|
"DESC" => "ASC",
|
|
|
|
];
|
2020-09-09 18:24:10 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$devices = $deviceManager->getAllDevices();
|
|
|
|
|
|
|
|
if (empty($sortBy) && empty($sortType)) {
|
|
|
|
$sortBy = "id";
|
|
|
|
$sortType = "DESC";
|
2020-09-09 18:24:10 +00:00
|
|
|
}
|
2020-08-31 19:23:23 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$template->prepare('sortIcon', [$sortBy => $sortIcons[$sortType]]);
|
|
|
|
|
2020-08-31 19:23:23 +00:00
|
|
|
foreach ($devices as $key => $device) {
|
2020-11-18 20:40:13 +00:00
|
|
|
//Signal Stenght
|
|
|
|
$subdevice = $subDeviceManager->getSubDeviceByMasterAndType($device['device_id'], "wifi");
|
|
|
|
$devices[$key]['signal'] = "";
|
|
|
|
if (!empty($subdevice['subdevice_id'])) {
|
2020-09-15 14:38:11 +00:00
|
|
|
$record = $recordManager->getLastRecord($subdevice['subdevice_id']);
|
2020-11-18 20:40:13 +00:00
|
|
|
if (!empty($record)) {
|
2020-09-15 14:38:11 +00:00
|
|
|
$devices[$key]['signal'] = $record['value'] . " " . $subdevice['unit'];
|
2020-11-18 20:40:13 +00:00
|
|
|
}
|
2020-09-15 14:38:11 +00:00
|
|
|
}
|
2020-11-18 20:40:13 +00:00
|
|
|
|
|
|
|
//Firmware Status
|
|
|
|
$localBinary = "../updater/" . str_replace(':', '', $device['mac']) . ".bin";
|
|
|
|
$devices[$key]['firmware_hash'] = "";
|
|
|
|
if (file_exists($localBinary)) {
|
|
|
|
$hash = md5_file($localBinary);
|
2020-08-31 19:23:23 +00:00
|
|
|
if ($hash == $device['firmware_hash']) {
|
|
|
|
$devices[$key]['firmware_hash'] = "true";
|
|
|
|
} else {
|
|
|
|
$devices[$key]['firmware_hash'] = "need";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$devices[$key]['firmware_hash'] = "false";
|
|
|
|
}
|
2020-09-09 18:24:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$devices = Utilities::sortArrayByKey($devices, $sortWordBook[$sortBy], strtolower($sortType));
|
2020-08-31 19:23:23 +00:00
|
|
|
|
2020-09-07 09:33:24 +00:00
|
|
|
$rooms = $roomManager->getAllRooms();
|
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$template->prepare('baseUrl', BASEURL);
|
|
|
|
$template->prepare('baseDir', BASEDIR);
|
|
|
|
|
|
|
|
$template->prepare('debugMod', DEBUGMOD);
|
|
|
|
$template->prepare('logToLiveTime', LOGTIMOUT);
|
|
|
|
$template->prepare('rooms', $rooms);
|
|
|
|
$template->prepare('sortType', $nextSort[$sortType]);
|
|
|
|
$template->prepare('devices', $devices);
|
|
|
|
$template->prepare('langMng', $langMng);
|
2020-08-31 19:23:23 +00:00
|
|
|
|
2020-11-18 20:40:13 +00:00
|
|
|
$template->render();
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|
|
|
|
}
|