<html>
<head>
    <title>Verify Account</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php 
include 'functions.php';
/*check exists*/
if (!isset($_GET['email']) || !login_demo($_GET['email'])) {
    $msg = 'Không tìm thấy trang này, liên hệ: 01663.930.250<br/>';
    $msg .= 'Nhấn vào đây để tạo tài khoản demo.<a href="demo.php">Create Account</a>';
    show404($msg);
}
//verify
if (isset($_POST['submit'])) {
    $update = array('phone' => $_POST['phone'], 'fullname' => $_POST['fullname']);
    $r = verify_account($_POST['email'], $_POST['activation_code'], $update);
    if ($r) {
        $logs[] = 'Tài khoản của bạn đã được xác thực thành công ! Nhấn vào đây để đăng nhập: <a href="demo.php">Đăng nhập</a>';
    } else {
        $logs[] = 'Sai code, tài khoản của bạn chưa được xác thực. Nhấn <a href="demo.php">vào đây</a> để gửi lại code.';
    }
}
//show logs
show_logs();
?>
<!-- activation form -->
<h2>Activation Code</h2>
<form method="post">
<input type="hidden" name="email" value="<?php 
}
/*login demo user*/
if (isset($_POST['login'])) {
    $_POST['email'] = mysql_real_escape_string($_POST['email']);
    //valid input
    //get ref info
    $ref = 'IP:' . $_SERVER['REMOTE_ADDR'] . ', from: ' . $_SERVER['HTTP_REFERER'] . ', browser: ' . $_SERVER['HTTP_USER_AGENT'];
    //generate code
    $code = RandomString(10);
    $subject = 'Demo quang cao tren google';
    //subject
    //body
    $body = 'Ma code: ' . $code;
    $body .= '<br/>Vui long copy & paste URL sau vào trinh duyet: http://app-ads.hoangweb.com/ksn-crx/verify_demo.php?email=' . $_POST['email'];
    $body .= '<br/>Nhap ma code tren va nhan nut Verify de hoan tat.';
    $demo = login_demo($_POST['email']);
    if ($demo) {
        if (!$demo['verify']) {
            $logs[] = 'Bạn chưa kích hoạt email.';
            mysql_update('crx_demo_users', array('email' => $_POST['email'], 'verify' => '0', 'activation_code' => $code, 'ref_pc' => $ref), 'email="' . $_POST['email'] . '"');
            //send activation code via email
            if (send_mail($_POST['email'], $subject, $body)) {
                $logs[] = 'Vui lòng kiểm tra email để kích hoạt tài khoản.';
            }
        } else {
            $_SESSION['vcn_extension']['demo'] = $demo;
        }
    } else {
        $logs[] = 'Đã khởi tạo tài khoản demo.';
        //add user to crx_demo_users table
        $id = mysql_insert('crx_demo_users', array('email' => $_POST['email'], 'verify' => '0', 'activation_code' => $code, 'ref_pc' => $ref));