59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\Setting;
|
|
use App\Services\TelegramService;
|
|
use App\Utils\View;
|
|
|
|
class SettingsController
|
|
{
|
|
public function index()
|
|
{
|
|
$settingModel = new Setting();
|
|
$settings = $settingModel->getAll();
|
|
|
|
View::render('layouts.admin', [
|
|
'title' => 'Configurações',
|
|
'content' => __DIR__ . '/../../resources/views/admin/settings/index.php',
|
|
'settings' => $settings
|
|
]);
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$settingModel = new Setting();
|
|
|
|
foreach ($_POST as $key => $value) {
|
|
$settingModel->set($key, $value);
|
|
}
|
|
|
|
$_SESSION['flash_success'] = "Configurações atualizadas com sucesso!";
|
|
View::redirect('/admin/settings');
|
|
}
|
|
|
|
public function testTelegram()
|
|
{
|
|
header('Content-Type: application/json');
|
|
|
|
$telegramService = new TelegramService();
|
|
|
|
// Use sendOrderNotification to test with the configured template
|
|
$response = $telegramService->sendOrderNotification([
|
|
'id' => '12345',
|
|
'title' => 'Teste de Integração',
|
|
'type' => 'Teste'
|
|
], 999);
|
|
|
|
$result = json_decode($response, true);
|
|
|
|
if ($result && isset($result['ok']) && $result['ok']) {
|
|
echo json_encode(['success' => true, 'message' => 'Mensagem enviada com sucesso!']);
|
|
} else {
|
|
$error = $result['description'] ?? 'Erro desconhecido ao contatar API do Telegram.';
|
|
echo json_encode(['success' => false, 'message' => 'Falha ao enviar: ' . $error]);
|
|
}
|
|
exit;
|
|
}
|
|
}
|