Deploy on 2026-06-05 16:08:53

This commit is contained in:
Hamza-Ayed
2026-06-05 16:08:53 +03:00
parent c0da60069f
commit 54065628bf
12 changed files with 316 additions and 167 deletions

View File

@@ -24,18 +24,12 @@ class SettingsController extends Controller
public function index(Request $request, Response $response): string
{
$lang = $this->session->get('lang', 'en');
$langFile = __DIR__ . "/../../resources/lang/{$lang}.php";
$t = file_exists($langFile) ? require $langFile : [];
// Get telegram settings from database
$tgToken = $this->getSetting('telegram_bot_token', '');
$tgChatId = $this->getSetting('telegram_chat_id', '');
$tgEnabled = $this->getSetting('telegram_enabled', '0');
return $this->render('admin/settings/index', [
't' => $t,
'lang' => $lang,
'tg_token' => $tgToken,
'tg_chat_id' => $tgChatId,
'tg_enabled' => $tgEnabled,
@@ -47,33 +41,29 @@ class SettingsController extends Controller
$tgToken = $request->post('telegram_bot_token', '');
$tgChatId = $request->post('telegram_chat_id', '');
$tgEnabled = $request->post('telegram_enabled', '0');
$action = $request->post('action', 'save');
$this->saveSetting('telegram_bot_token', $tgToken);
$this->saveSetting('telegram_chat_id', $tgChatId);
$this->saveSetting('telegram_enabled', $tgEnabled);
$this->session->setFlash('success', 'Settings saved successfully.');
$response->redirect('/admin/settings');
}
public function testTelegram(Request $request, Response $response): void
{
$tgToken = $request->post('telegram_bot_token', '');
$tgChatId = $request->post('telegram_chat_id', '');
$this->notifier->configure($tgToken, $tgChatId);
if ($this->notifier->sendTest()) {
$this->session->setFlash('success', 'Test notification sent to Telegram!');
if ($action === 'test') {
$this->notifier->configure($tgToken, $tgChatId);
if ($this->notifier->sendTest()) {
$this->session->setFlash('success', 'Settings saved and test notification sent to Telegram!');
} else {
$err = $this->notifier->getLastError() ?: 'Check your token and chat ID.';
$this->session->setFlash('error', 'Settings saved, but failed to send Telegram notification: ' . $err);
}
} else {
$this->session->setFlash('error', 'Failed to send Telegram notification. Check your token and chat ID.');
$this->session->setFlash('success', 'Settings saved successfully.');
}
$response->redirect('/admin/settings');
}
public function switchLang(Request $request, Response $response): void
public function switchLang(Request $request, Response $response, string $lang = 'en'): void
{
$lang = $request->get('lang', 'en');
$lang = $request->routeParam('lang', $lang);
if (in_array($lang, ['ar', 'en'])) {
$this->session->set('lang', $lang);
}