PHP_SMART_HOME_V3/app/views/Device.php

53 lines
1.5 KiB
PHP
Raw Normal View History

2020-08-31 19:23:23 +00:00
<?php
class Device extends Template
{
function __construct () {
$userManager = new UserManager ();
$deviceManager = new DeviceManager ();
2020-09-07 09:33:24 +00:00
$roomManager = new RoomManager ();
2020-08-31 19:23:23 +00:00
$langMng = new LanguageManager ('en');
if (!$userManager->isLogin ()) {
header ('Location: ' . BASEURL . 'device');
}
$template = new Template ('device');
$template->prepare ('title', $langMng->get ("m_devices"));
$devices = $deviceManager->getAllDevices ();
foreach ($devices as $key => $device) {
$localBinary = "../updater/" . str_replace (':', '', $device['mac']) . ".bin";
if (file_exists ($localBinary)) {
$hash = md5_file ($localBinary);
if ($hash == $device['firmware_hash']) {
$devices[$key]['firmware_hash'] = "true";
} else {
$devices[$key]['firmware_hash'] = "need";
}
} else {
$devices[$key]['firmware_hash'] = "false";
}
$wifi = SubDeviceManager::getSubDeviceByMaster($device['device_id'], 'wifi');
if ($wifi) {
$signalStrenght = RecordManager::getLastRecordNotNull($wifi['subdevice_id']);
$devices[$key]['signal'] = (!$signalStrenght ? 0 : $signalStrenght['value']);
}
2020-08-31 19:23:23 +00:00
}
2020-09-07 09:33:24 +00:00
$rooms = $roomManager->getAllRooms();
2020-08-31 19:23:23 +00:00
$template->prepare ('baseDir', BASEDIR);
$template->prepare ('debugMod', DEBUGMOD);
$template->prepare ('logToLiveTime', LOGTIMOUT);
2020-09-07 09:33:24 +00:00
$template->prepare ('rooms', $rooms);
2020-08-31 19:23:23 +00:00
$template->prepare ('devices', $devices);
$template->prepare ('langMng', $langMng);
$template->render ();
}
}