<?php
// mahamudfutureit_tts_config.php for thesylhet.net

$db_host = 'localhost';
$db_name = 'mahamudf_skytimesphp';
$db_user = 'mahamudf_skytimesphp';
$db_pass = 'mahamudf_skytimesphp';

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

$mysqli->query("CREATE TABLE IF NOT EXISTS `mahamudfutureit_tts_settings` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `setting_key` varchar(100) NOT NULL,
    `setting_value` text NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `setting_key` (`setting_key`)
)");

$mysqli->query("INSERT IGNORE INTO `mahamudfutureit_tts_settings` (`setting_key`, `setting_value`) VALUES 
    ('tts_enabled', '1'),
    ('tts_voice', 'male')");

function mahamudfutureit_get_tts_setting($key) {
    global $mysqli;
    $result = $mysqli->query("SELECT setting_value FROM mahamudfutureit_tts_settings WHERE setting_key = '$key'");
    if ($result && $result->num_rows > 0) {
        $row = $result->fetch_assoc();
        return $row['setting_value'];
    }
    return null;
}

function mahamudfutureit_is_tts_enabled() {
    $val = mahamudfutureit_get_tts_setting('tts_enabled');
    return $val == '1';
}

function mahamudfutureit_get_voice_type() {
    $val = mahamudfutureit_get_tts_setting('tts_voice');
    return $val ? $val : 'male';
}
?>