PHP_SMART_HOME_V3/app/views/Setting.php

64 lines
1.9 KiB
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
class Setting extends Template
{
function __construct()
{
$userManager = new UserManager();
2020-07-23 13:16:44 +00:00
$langMng = new LanguageManager('en');
2020-05-16 15:18:27 +00:00
if (!$userManager->isLogin()){
header('Location: ' . BASEURL . 'login');
}
$automations = [];
$automationsData = AutomationManager::getAll();
foreach ($automationsData as $automationKey => $automationData) {
$automations[$automationData['automation_id']] = [
'name' => '',
'onDays' => $automationData['on_days'],
'ifSomething' => $automationData['if_something'],
'doSomething' => $automationData['do_something'],
];
}
$template = new Template('setting');
$template->prepare('baseDir', BASEDIR);
2020-12-09 11:19:19 +00:00
$template->prepare('baseUrl', BASEURL);
2020-05-16 15:18:27 +00:00
$template->prepare('debugMod', DEBUGMOD);
$template->prepare('title', 'Automation');
$template->prepare('langMng', $langMng);
$template->prepare('automations', $automations);
$users = $userManager->getUsers();
foreach ($users as $key => $value) {
$users[$key]['gavatar_url'] = $userManager->getAvatarUrl($value['user_id']);
}
$template->prepare('users', $users);
$template->prepare('userName', $userManager->getUserData('username'));
$template->prepare('userEmail', $userManager->getUserData('email'));
$template->prepare('userAvatarUrl', $userManager->getAvatarUrl());
if ($userManager->getUserData('ota') == ''){
$ga = new PHPGangsta_GoogleAuthenticator();
$otaSecret = $ga->createSecret();
$qrCodeUrl = $ga->getQRCodeGoogleUrl('Smart Home', $otaSecret);
$oneCode = $ga->getCode($otaSecret);
$template->prepare('qrUrl', $qrCodeUrl);
$template->prepare('otaSecret', $otaSecret);
$template->prepare('otaCode', $oneCode);
// echo "Secret is: ".$secret."\n\n";
// echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n";
// echo "Checking Code '$oneCode' and Secret '$otaSecret':\n";
}
$rooms = RoomManager::getAllRooms();
$template->prepare('rooms', $rooms);
2020-10-05 19:12:06 +00:00
2020-05-16 15:18:27 +00:00
$template->render();
}
}