<?php 
    $page_title='Verify Purchase';
    include("includes/header.php");
    require("includes/lb_helper.php");
    require("language/language.php");
    
    if(!isset($_SESSION['admin_type'])){
        if($_SESSION['admin_type'] == 0){
            session_destroy();
            header( "Location:index.php");
            exit;
        }
    }
    
    $qry="SELECT * FROM tbl_settings where id='1'";
    $result=mysqli_query($mysqli,$qry);
    $settings_row=mysqli_fetch_assoc($result);
    
    if(isset($_POST['submit'])){

        $purchase = verification_license(trim($_POST['purchase_code']));
        
		if($purchase['status'] != true){
			
            $data = array(
                'purchase_code' => trim($_POST['purchase_code']),
            );
                
            $settings_edit =Update('tbl_settings', $data, "WHERE id = '1'"); 

            $_SESSION['class']="error";
            $_SESSION['msg']="18";
            header( "Location:verification.php");
            exit;
            
        } else {
			
            $data = array(
                'purchase_code' => trim($_POST['purchase_code']),
            );
                
            $settings_edit =Update('tbl_settings', $data, "WHERE id = '1'"); 

            $_SESSION['class']="success";
            $_SESSION['msg']="19";
            header( "Location:verification.php?status=2");
            exit;
            
        }
    }
    
?>

<!-- Start: main -->
<main id="nsofts_main">
    <div class="nsofts-container">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb align-items-center">
                <li class="breadcrumb-item d-inline-flex"><a href="dashboard.php"><i class="ri-home-4-fill"></i></a></li>
                <li class="breadcrumb-item d-inline-flex active" aria-current="page"><?php echo (isset($page_title)) ? $page_title : "" ?></li>
            </ol>
        </nav>
            
        <div class="row g-4">
            <div class="col-12">
                <div class="card h-100">
                    <div class="card-body p-4">
                        <h5 class="mb-3"><?=$page_title ?></h5>
                        <form action="" name="addverify" method="POST" enctype="multipart/form-data">
                            
                            <div class="mb-3 row">
                                <label class="col-sm-2 col-form-label">Purchase Code</label>
                                <div class="col-sm-10">
                                    <input type="text" name="purchase_code"class="form-control" placeholder="Enter your item purchase code" value="<?php echo $settings_row['purchase_code'];?>" autocomplete="off" required>
                                </div>
                            </div>
                            
                            <div class="mb-3 row">
                                <label class="col-sm-2 col-form-label">ApiKey</label>
                                <div class="col-sm-10">
                                    <div class="pb-clipboard mb-2">
                                        <span class="pb-clipboard__url"><span id="clipboard_api_key"><?=$settings_row['api_key'] ?></span></span>
                                        <a class="pb-clipboard__link btn_api_key" href="javascript:void(0);" data-clipboard-action="copy" data-clipboard-target="#clipboard_api_key" data-bs-toggle="tooltip" data-bs-placement="top" title="Copy">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" /></svg>
                                        </a>
                                    </div>
                                </div>
                            </div>
                            


                            <button type="submit" name="submit" class="btn btn-primary" style="min-width: 120px;">Verify</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row g-4 mt-2">
            <div class="col-12">
                <div class="card h-100">
                    <div class="card-body p-4">
                        <h5 class="mb-3">License</h5>
                        
                        <div class="alert alert-primary alert-dismissible" role="alert">
                          <h6 class="alert-heading d-flex align-items-center fw-bold mb-1">Regular License</h6>
                          <p class="mb-0">Only one app can be active at a time. If you register new package name previous app cant be access by users.</p>
                        </div>
                        
                        <div class="alert alert-primary alert-dismissible" role="alert">
                          <h6 class="alert-heading d-flex align-items-center fw-bold mb-1">Extended License</h6>
                          <p class="mb-0">Unlimited apps can be created and publish at same time.</p>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
        
    </div>
</main>
<!-- End: main -->
    
<?php include("includes/footer.php");?> 

<script type="text/javascript">

    $(document).ready(function(event) {
        
        $(document).on("click", ".btn_api_key", function(e) {
            var el = document.getElementById('clipboard_api_key');
            var successful = copyToClipboard(el);
            if (successful) {
                $.notify('Copied!', { position:"top right",className: 'success'} );
            } else {
                $.notify('Whoops, not copied!', { position:"top right",className: 'error'} );
            }
        });

    });

</script>  