PHP_SMART_HOME_V3/app/views/Setting.php

63 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2019-08-23 11:39:42 +00:00
<?php
class Setting extends Template
{
function __construct()
{
2019-10-30 14:18:29 +00:00
2019-08-23 11:39:42 +00:00
global $userManager;
2019-10-11 12:12:05 +00:00
global $langMng;
2019-08-23 11:39:42 +00:00
if (!$userManager->isLogin()){
2019-10-11 14:32:05 +00:00
header('Location: ' . BASEDIR . 'login');
2019-08-23 11:39:42 +00:00
}
$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');
2019-10-11 14:38:20 +00:00
$template->prepare('baseDir', BASEDIR);
2020-01-21 10:24:50 +00:00
$template->prepare('debugMod', DEBUGMOD);
2019-08-23 11:39:42 +00:00
$template->prepare('title', 'Automation');
2019-10-11 12:12:05 +00:00
$template->prepare('langMng', $langMng);
2019-08-23 11:39:42 +00:00
$template->prepare('automations', $automations);
2019-10-30 14:18:29 +00:00
$users = $userManager->getUsers();
2020-03-25 14:58:47 +00:00
foreach ($users as $key => $value) {
$users[$key]['gavatar_url'] = $userManager->getAvatarUrl($value['user_id']);
}
2019-10-30 14:18:29 +00:00
$template->prepare('users', $users);
2020-01-21 10:24:50 +00:00
$template->prepare('userName', $userManager->getUserData('username'));
$template->prepare('userEmail', $userManager->getUserData('email'));
$template->prepare('userAvatarUrl', $userManager->getAvatarUrl());
2019-10-30 14:18:29 +00:00
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";
}
2019-11-22 14:09:22 +00:00
$rooms = RoomManager::getAllRooms();
$template->prepare('rooms', $rooms);
2019-10-30 14:18:29 +00:00
2019-08-23 11:39:42 +00:00
$template->render();
}
}