<?php
include "session.php";
require_once "function.php";

$link = "https://" . $_SERVER['SERVER_NAME'] . "/?" . getsetting("site_parameter");


if (!isset($_SESSION['admin'])) {
    header('location: login');
    die();
}
// Path to the settings configuration file
$settingsFile = "../../core/settings.ini";

// Parse the settings from the ini file
$settings = parse_ini_file($settingsFile);

// Check if the form is submitted via POST method
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['tele'])) {

    $settings['apiToken'] = htmlspecialchars($_POST['apiToken']);
    $settings['chatID']   = htmlspecialchars($_POST['chatID']);

    $configData = '';
    foreach ($settings as $key => $value) {
        $configData .= "{$key} = \"{$value}\"\n";
    }

    file_put_contents($settingsFile, $configData);

    $_SESSION['message'] = 'Settings updated successfully!';
    $_SESSION['message_type'] = 'success';

    header("Location: security");
    exit();
}
if (isset($_POST["credentials"]))
{
  if ($_POST["password"] == $_POST["repassword"])
  {
    $config = '{
  "username"  : "' . md5($_POST["username"]) . '",
  "password"  : "' . md5($_POST["password"]) . '"
}';
  
  file_put_contents("assets/plugins/config.json", $config);

  } else {
    echo '<script>alert("Re-type password not same!")</script>';
  }
  
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <meta content="" name="description">
    <meta content="" name="author">
    <title>510 NOT FOUND</title><!-- loader-->
    <link href="assets/css/pace.min.css" rel="stylesheet">
    <script src="assets/js/pace.min.js">
    </script><!--favicon-->
    <link
        href="https://www.pinclipart.com/picdir/big/550-5508982_golden-crown-png-download-transparent-background-black-crown.png"
        rel="icon" type="image/x-icon">
    <link href="assets/plugins/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet"><!-- simplebar CSS-->
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet"><!-- Bootstrap core CSS-->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet"><!-- animate CSS-->
    <link href="assets/css/animate.css" rel="stylesheet" type="text/css"><!-- Icons CSS-->
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css"><!-- Sidebar CSS-->
    <link href="assets/css/sidebar-menu.css" rel="stylesheet"><!-- Custom Style-->
    <link href="assets/css/app-style.css" rel="stylesheet">
    <style type="text/css">
        .my-custom-scrollbar {
            position: relative;
            height: 400px;
            overflow: auto;
        }

        .table-wrapper-scroll-y {
            display: block;
        }
    </style>
</head>

<body class="bg-theme bg-theme1">
    <!-- Start wrapper-->
    <div id="wrapper">
        <!--Start sidebar-wrapper-->
        <div data-simplebar="" data-simplebar-auto-hide="true" id="sidebar-wrapper">
            <div class="brand-logo">
                <h5 class="logo-text" id="liveClock"></h5>
            </div>
            <ul class="sidebar-menu do-nicescrol">
                <li class="sidebar-header">MAIN NAVIGATION</li>
                <li>
                    <a href="./"><i class="zmdi zmdi-view-dashboard"></i> <span>Dashboard</span></a>
                </li>
                <li>
                    <a href="./setting"><i class="zmdi zmdi-settings zmdi-hc-spin"></i> <span>Setting</span></a>
                </li>
                <li>
                    <a href="./security"><i class="fa fa-shield"></i> <span>Security</span></a>
                </li>
                <li>
                    <a href="./logout"><i class="fa fa-sign-out"></i> <span>Log Out</span></a>
                </li>
                <li class="sidebar-header">CONTACT</li>
                <li>
                    <a href="https://t.me/Fivehundredten" target="_blank"><i class="fa fa-comment"></i> <span>Contact
                            Admin</span></a>
                </li>
            </ul>
            <!-- Button trigger modal -->
        </div><!--End sidebar-wrapper-->
        <!--Start topbar header-->
        <header class="topbar-nav">
            <nav class="navbar navbar-expand fixed-top">
                <ul class="navbar-nav mr-auto align-items-center">
                    <li class="nav-item">
                        <a class="nav-link toggle-menu" href="javascript:void();"><i
                                class="icon-menu menu-icon"></i></a>
                    </li>
                </ul>
                <ul class="navbar-nav align-items-center right-nav-link">
                    <li class="nav-item dropdown-lg">
                        <a class="nav-link dropdown-toggle dropdown-toggle-nocaret waves-effect text-small"
                            data-toggle="dropdown" href="<?php echo $link; ?>" target="_blank"><small>Go to site</small></a>
                    </li>
                </ul>
            </nav>
        </header><!--End topbar header-->
        <div class="clearfix"></div>
        <div class="content-wrapper">
            <div class="container-fluid">
                <div class="row mt-3">
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="card-title">
                                    Custom Telegram Bot Configuration
                                </div>
                                <hr>
                                <form action="" method="post">
                                    <div class="row mt-0">
                                        <div class="col-lg-12">
                                            <div class="row mt-0">
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <label for="input-6">Chat ID <i
                                                                class="fa fa-search"></i></label> <input
                                                            class="form-control form-control-rounded" id="chatID"
                                                            placeholder="Chat ID Telegram" type="text" name="chatID"
                                                            value="<?php echo $settings['chatID']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-6">
                                                    <div class="form-group">
                                                        <label for="input-6">API Token <i
                                                                class="fa fa-search"></i></label> <input
                                                            class="form-control form-control-rounded" id="apiToken"
                                                            placeholder="API Token Telegram" type="text" name="apiToken"
                                                            value="<?php echo $settings['apiToken']; ?>">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div style="margin-top: 20px;"></div>
                                    <div class="form-group" align="center">
                                        <button class="btn btn-light btn-round px-5 mx-2" type="submit" name="tele"><i
                                                class="fa fa-floppy-o"></i> Save Telegram</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="card-title">
                                    Credentials Configuration
                                </div>
                                <hr>
                                <form action="" method="post">
                                    <div class="row mt-0">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label for="input-6">Panel Username <i class="fa fa-user"></i></label>
                                                <input class="form-control form-control-rounded" id="input-6"
                                                    placeholder="Enter new panel username" type="text" name="username">
                                            </div>
                                            <div class="form-group">
                                                <label for="input-6">Panel Password <i class="fa fa-key"></i></label>
                                                <input class="form-control form-control-rounded" id="input-6"
                                                    placeholder="Enter new panel password" type="password"
                                                    name="password">
                                                <div class="mt-3"></div>
                                                <input class="form-control form-control-rounded" id="input-6"
                                                    placeholder="Re-type panel password" type="password"
                                                    name="repassword">
                                            </div>
                                        </div>
                                    </div>
                                    <div style="margin-top: 20px;"></div>
                                    <div class="form-group" align="center">
                                        <button class="btn btn-light btn-round px-5 mx-2" type="submit"
                                            name="credentials"><i class="fa fa-floppy-o"></i> Save Credentials</button>
                                    </div>
                                    <div class="mt-5">&nbsp;</div>
                                    <div class="mt-1">&nbsp;</div>
                                    <div class="row mt-5">
                                        <div class="col-md-12">
                                            <div class="mx-3"><em>You will never find peace if your life is enslaved by
                                                    desire. ~ <strong>510 NOT FOUND</strong></em></div>
                                        </div>
                                    </div><!--/row-->
                                </form>
                            </div>
                        </div>
                    </div>
                </div><!--End Row-->
                <!--start overlay-->
                <div class="overlay toggle-menu"></div><!--end overlay-->
            </div><!-- End container-fluid-->
        </div><!--End content-wrapper-->
        <!--Start Back To Top Button-->
        <a class="back-to-top" href="javaScript:void();"><i class="fa fa-angle-double-up"></i></a>
        <!--End Back To Top Button-->
        <!--Start footer-->
        <footer class="footer">
            <div class="container">
                <div class="text-center">
                    <script>document.write(new Date().getFullYear())</script> © 510 NOT FOUND.
                </div>
            </div>
        </footer><!--End footer-->
        <!--start color switcher-->
        <div class="right-sidebar">
            <div class="switcher-icon">
                <i class="zmdi zmdi-settings zmdi-hc-spin"></i>
            </div>
            <div class="right-sidebar-content">
                <p class="mb-0">Gaussion Texture</p>
                <hr>
                <ul class="switcher">
                    <li id="theme1"></li>
                    <li id="theme2"></li>
                    <li id="theme3"></li>
                    <li id="theme4"></li>
                    <li id="theme5"></li>
                    <li id="theme6"></li>
                </ul>
                <p class="mb-0">Gradient Background</p>
                <hr>
                <ul class="switcher">
                    <li id="theme7"></li>
                    <li id="theme8"></li>
                    <li id="theme9"></li>
                    <li id="theme10"></li>
                    <li id="theme11"></li>
                    <li id="theme12"></li>
                    <li id="theme13"></li>
                    <li id="theme14"></li>
                    <li id="theme15"></li>
                </ul>
            </div>
        </div><!--end color switcher-->
    </div><!--End wrapper-->
    <!-- Bootstrap core JavaScript-->
    <script src="assets/js/jquery.min.js">
    </script>
    <script src="assets/js/popper.min.js">
    </script>
    <script src="assets/js/bootstrap.min.js">
    </script> <!-- simplebar js -->

    <script src="assets/plugins/simplebar/js/simplebar.js">
    </script> <!-- sidebar-menu js -->

    <script src="assets/js/sidebar-menu.js">
    </script> <!-- loader scripts -->

    <script src="assets/js/jquery.loading-indicator.js">
    </script> <!-- Custom scripts -->

    <script src="assets/js/app-script.js">
    </script> <!-- Chart js -->

    <script src="assets/plugins/Chart.js/Chart.min.js">
    </script> <!-- Index js -->

    <script src="assets/js/index.js">
    </script>
    <script>
        function updateClock() {
            const now = new Date();

            const options = {
                hour: '2-digit',
                minute: '2-digit',
                second: '2-digit'
            };

            document.getElementById("liveClock").textContent =
                now.toLocaleTimeString('en-US', options);
        }

        setInterval(updateClock, 1000);
        updateClock();
    </script>
</body>

</html>