Chủ Nhật, 1 tháng 11, 2026

Debug Ghi Lỗi trong File

Cách 1: có file php-error.log sẵn trên server


 if (!function_exists('vb_debug')) {

    function vb_debug($msg){

        // Đường dẫn tới public_html/php-error.log

        $file = $_SERVER['DOCUMENT_ROOT'].'/php-error.log';

        @error_log(date('Y-m-d H:i:s').' '.$msg."\n", 3, $file);

    }

}

$today   = date('Y-m-d');

$tag       = 'SPMODE userid='.$userid.' level='.$userlevel.' today='.$today.' => ';

vb_debug($tag.'ROW begin='.$begin.' end='.$end);

Cách 1: chưa có file php-error.log trên server

if (!function_exists('vb_debug')) {

    function vb_debug($msg){

        $root = !empty($_SERVER['DOCUMENT_ROOT']) ? rtrim($_SERVER['DOCUMENT_ROOT'], '/\\') : dirname(__FILE__);

        $file = $root . '/php-error.log';

        // Chưa có file thì tạo

        if (!file_exists($file)) {

            if (@file_put_contents($file, '') === false) {

                return false;   // không tạo được: thư mục không có quyền ghi

            }

            @chmod($file, 0644);

        }

        if (!is_writable($file)) return false;

        return @error_log(date('Y-m-d H:i:s') . ' ' . $msg . "\n", 3, $file);

    }

}

===> Ghi lỗi

$tag   = 'SPMODE userid='.$userid.' level='.$userlevel.' today='.$today.' => ';

vb_debug($tag.'STOP: SQL error');

## Ghi Nhận Code và chức năng của hàm ##

Số 3 là kiểu ghi của hàm error_log():
Số  Ý nghĩa:
0   Ghi vào log mặc định của PHP
1   Gửi qua email
3   Ghi nối tiếp (append) vào file chỉ định ở tham số thứ 3
4   Gửi thẳng vào SAPI logger

Zalopay + Send Email

 Down Load: Tại đây

** Code:

include_once 'zalopay_process.php';

$mail_content = array(

    'Tài khoản'   => $mbrow['congty_vi'],

    'Email'       => $mbrow['user_email'],

    'Mã số thuế'  => $tax_code,

    'Gói dịch vụ' => $item_name,

    'Số tiền'     => number_format($amount_vnd, 0, ',', '.') . ' VNĐ',

    'Mã chuyển khoản' => $transfer_code

);

$mail_ok = false;

if (function_exists('zp_mail_request')) {

    $mail_ok = zp_mail_request($mail_content , $mbrow['user_email'],$mbrow['username'],"superpage");

}

echo zp_json(array(

    "status"     => 1,

    "mail"       => $mail_ok ? 1 : 0,

    "mail_error" => $mail_ok ? '' : (isset($GLOBALS['zp_mail_error']) ? $GLOBALS['zp_mail_error'] : ''),  // xóa dòng này khi chạy thật

    "message"    => "Đăng ký thành công! Chúng tôi đã ghi nhận yêu cầu của bạn" .

    ($mail_ok ? " và gửi email xác nhận." : ". (Email xác nhận chưa gửi được, quản trị viên sẽ liên hệ với bạn.)")

));

exit;

   

# 👉 zalopay_process.php 

<?php

/**

 * zalopay_process.php

 * Logic dùng chung: kích hoạt gói + gửi mail + tiện ích JSON.

 * Tương thích PHP 5.3.

 */


// Khóa bí mật để ký link giả lập (đổi thành chuỗi ngẫu nhiên của bạn)

if (!defined('ZP_MOCK_SECRET')) define('ZP_MOCK_SECRET', 'DOI_CHUOI_BI_MAT_NAY_123456');

// Bật/tắt chế độ giả lập. KHI LÊN PRODUCTION: đặt false

if (!defined('ZP_MOCK_ENABLED')) define('ZP_MOCK_ENABLED', true);

/* ==========

 *  KÍCH HOẠT GÓI

 * ========== */

/**

 * Kích hoạt gói cho user. An toàn khi gọi nhiều lần (idempotent):

 * chỉ cập nhật + gửi mail ở lần đầu tiên (status chưa = 1).

 *

 * @return array ['ok'=>bool, 'already'=>bool, 'package'=>string, 'mail'=>bool, 'msg'=>string]

 */

function zp_activate_package($db, $user_id)

{

    $res = array('ok' => false, 'already' => false, 'package' => '', 'mail' => false, 'msg' => '');

    $user_id = intval($user_id);

    if ($user_id <= 0) { $res['msg'] = 'user_id không hợp lệ'; return $res; }


    $q = $db->sql_query("SELECT * FROM api_verified_payment WHERE shopid = '$user_id' ORDER BY id DESC LIMIT 1");

    $payment_row = $db->sql_fetch_assoc($q);

    if (!$payment_row) { $res['msg'] = 'Không tìm thấy đơn thanh toán'; return $res; }


    $package_type = trim($payment_row['package_type']);

    // Gói gia hạn (V-...) cùng cấp với gói gốc

    $levels = array(

        'BUSINESS' => 3, 'FACTORY' => 4, 'GLOBAL' => 5,

        'V-BUSINESS' => 3, 'V-FACTORY' => 4, 'V-GLOBAL' => 5

    );

    if (!isset($levels[$package_type])) { $res['msg'] = 'Gói không hợp lệ'; return $res; }


    $res['package'] = $package_type;


    // Đã xử lý trước đó -> không làm lại, không gửi mail lại

    if (intval($payment_row['status']) === 1) {

        $res['ok'] = true;

        $res['already'] = true;

        return $res;

    }


    $user_level = $levels[$package_type];

    $payment_id = intval($payment_row['id']);


    // 1. Cập nhật dữ liệu

    $db->sql_query("UPDATE nvb8bbf_users SET user_level = $user_level WHERE user_id = '$user_id'");

    $db->sql_query("UPDATE api_verified_payment SET status = 1 WHERE id = $payment_id");


    // 2. Gửi mail cho khách

    $uq = $db->sql_query("SELECT email, username FROM nvb8bbf_users WHERE user_id = '$user_id' LIMIT 1");

    $user = $db->sql_fetch_assoc($uq);

    if ($user && !empty($user['email'])) {

        $res['mail'] = zp_send_mail($user['email'], $user['username'], $package_type);

    }


    $res['ok'] = true;

    return $res;

}


/* ==========================================================

 *  EMAIL (dùng PHPMailer + cấu hình SMTP có sẵn của site)

 *  Cần các file của site:

 *    includes/data/mail_config.php  ($mail_mailserver, $mail_username, $mail_password, $mail_email)

 *    classes/class.phpmailer.php

 *    classes/class.smtp.php

 * ========================================================== */


/** Tự dò thư mục gốc của site (nơi có thư mục classes/ và includes/) */

function zp_find_root()

{

    $here = dirname(__FILE__);

    $candidates = array(

        $here . '/',

        $here . '/../',

        $here . '/../../',

        $here . '/../../../'

    );

    if (!empty($_SERVER['DOCUMENT_ROOT'])) {

        $candidates[] = rtrim($_SERVER['DOCUMENT_ROOT'], '/\\') . '/';

    }

    foreach ($candidates as $c) {

        if (file_exists($c . 'classes/class.phpmailer.php') && file_exists($c . 'includes/data/mail_config.php')) {

            return $c;

        }

    }

    return false;

}


/** Một dòng "Nhãn: giá trị" trong mail (bỏ qua nếu rỗng) */

function zp_mail_row($label, $val)

{

    $val = trim((string)$val);

    if ($val === '') return '';

    return '<p style="line-height:1.6;margin:6px 0"><b>' . htmlspecialchars($label) . ':</b> ' . htmlspecialchars($val) . '</p>';

}


/** Khung mail chung (logo + tiêu đề + nội dung + footer) */

function zp_mail_template($title, $content_html)

{

    global $site_live, $ThemeSel;

    $logo = (isset($site_live) ? $site_live : '') . 'themes/' . (isset($ThemeSel) ? $ThemeSel : '') . '/images/logo.png';

    return '

    <div style="max-width:600px;margin:20px auto;background:#fff;border-radius:12px;overflow:hidden;border:1px solid #ccc;font-family:Roboto,Arial,sans-serif">

        <div style="background:#f1f1f1;padding:20px">

            <img src="' . $logo . '" alt="Logo" style="max-height:70px">

        </div>

        <div style="padding:30px;color:#333">

            <h2 style="margin-top:0;color:#ED3237">' . $title . '</h2>

            ' . $content_html . '

            <p style="line-height:1.6">Trân trọng,<br>Đội ngũ ban quản trị vietb2b.com</p>

        </div>

        <div style="background:#ED3237;color:#fff;text-align:center;padding:15px;font-size:14px">

            Mọi thắc mắc và hỗ trợ, vui lòng liên hệ HOTLINE: 0903018626

        </div>

    </div>';

}


/** Ghi lỗi gửi mail vào biến toàn cục + file zalopay_mail_error.log (cùng thư mục) */

function zp_mail_fail($msg)

{

    global $zp_mail_error;

    $zp_mail_error = $msg;

    $GLOBALS['zp_mail_error'] = $msg;

    @file_put_contents(dirname(__FILE__) . '/zalopay_mail_error.log', date('Y-m-d H:i:s') . ' - ' . $msg . "\n", FILE_APPEND);

    return false;

}


/**

 * Gửi mail qua SMTP của site.

 * $to / $cc: mảng array(array(email, tên), ...). $to rỗng => gửi cho admin ($mail_email)

 * @return bool

 */

function zp_mail_send($subject, $body, $to = array(), $cc = array()){


    global $zp_mail_error, $zp_mail_debug;

    $zp_mail_error = '';

    $GLOBALS['zp_mail_error'] = '';


    $root = zp_find_root();

    if ($root === false) {

        return zp_mail_fail('Không tìm thấy classes/class.phpmailer.php hoặc includes/data/mail_config.php (thử trong ' . dirname(__FILE__) . ' và các thư mục cha)');

    }


    // include (không _once) để các biến cấu hình luôn có trong hàm này

    include $root . 'includes/data/mail_config.php';


    // Chỉ nạp PHPMailer nếu site chưa nạp (tránh "Cannot redeclare class PHPMailer")

    if (!class_exists('PHPMailer')) {

        require_once $root . 'classes/class.smtp.php';

        require_once $root . 'classes/class.phpmailer.php';

    }

    if (!class_exists('PHPMailer')) return zp_mail_fail('Không có class PHPMailer');

    if (empty($mail_mailserver) || empty($mail_username)) {

        return zp_mail_fail('mail_config.php thiếu $mail_mailserver / $mail_username');

    }


    $mail = new PHPMailer();

    $mail->CharSet    = 'UTF-8';

    $mail->IsSMTP();

    $mail->Host       = $mail_mailserver;

    $mail->SMTPAuth   = true;

    $mail->Username   = $mail_username;

    $mail->Password   = $mail_password;

    $mail->SMTPSecure = 'ssl';

    $mail->Port       = 465;

    $mail->Timeout    = 20;

    if (!empty($zp_mail_debug)) $mail->SMTPDebug = 2;   // chỉ bật trong file test

    $mail->SetFrom($mail_username, 'VietB2B.com');


    if (empty($to) && !empty($mail_email)) $to = array(array($mail_email, 'Admin VietB2B'));

    $has_to = false;

    foreach ($to as $t) {

        if (!empty($t[0]) && filter_var($t[0], FILTER_VALIDATE_EMAIL)) {

            $mail->AddAddress($t[0], isset($t[1]) ? $t[1] : '');

            $has_to = true;

        }

    }

    if (!$has_to) return zp_mail_fail('Không có địa chỉ người nhận hợp lệ (kiểm tra $mail_email trong mail_config.php)');


    foreach ($cc as $c) {

        if (!empty($c[0]) && filter_var($c[0], FILTER_VALIDATE_EMAIL)) {

            $mail->AddCC($c[0], isset($c[1]) ? $c[1] : '');

        }

    }


    $mail->IsHTML(true);

    $mail->Subject = $subject;

    $mail->Body    = $body;

    $mail->AltBody = strip_tags($body);


    if ($mail->Send()) return true;

    return zp_mail_fail('SMTP lỗi: ' . $mail->ErrorInfo);

}


##┌────────────────────────────────────────────────┐     

function zp_mail_types()

{

    return array(

        'verified' => array(

            'title'         => 'Đăng ký dịch vụ xác thực doanh nghiệp',

            'subject_admin' => 'Xác thực doanh nghiệp Verified',

            'subject_cust'  => 'VIETB2B - Đã nhận yêu cầu xác thực doanh nghiệp',

            'intro'         => 'VIETB2B đã nhận được yêu cầu đăng ký dịch vụ xác thực doanh nghiệp của bạn với thông tin sau:'

        ),

        'superpage' => array(

            'title'         => 'Đăng ký dịch vụ Superpage',

            'subject_admin' => 'Đăng ký dịch vụ Superpage',

            'subject_cust'  => 'VIETB2B - Đã nhận yêu cầu đăng ký Superpage',

            'intro'         => 'VIETB2B đã nhận được yêu cầu đăng ký dịch vụ Superpage của bạn với thông tin sau:'

        ),

        'verified_upgrade' => array(

            'title'         => 'Nâng cấp gói dịch vụ Verified',

            'subject_admin' => 'Nâng cấp gói dịch vụ Verified',

            'subject_cust'  => 'VIETB2B - Đã nhận yêu cầu nâng cấp gói dịch vụ Verified',

            'intro'         => 'VIETB2B đã nhận được yêu cầu nâng cấp gói dịch vụ Verified của bạn với thông tin sau:'

        ),

        'verified_renew' => array(

            'title'         => 'Gia hạn gói dịch vụ Verified',

            'subject_admin' => 'Gia hạn gói dịch vụ Verified',

            'subject_cust'  => 'VIETB2B - Đã nhận yêu cầu gia hạn gói dịch vụ Verified',

            'intro'         => 'VIETB2B đã nhận được yêu cầu gia hạn gói dịch vụ Verified của bạn với thông tin sau:'

        ),

        'superpage_renew' => array(

            'title'         => 'Gia hạn gói Superpage',

            'subject_admin' => 'Gia hạn gói Superpage',

            'subject_cust'  => 'VIETB2B - Đã nhận yêu cầu gia hạn gói Superpage',

            'intro'         => 'VIETB2B đã nhận được yêu cầu gia hạn gói Superpage của bạn với thông tin sau:'

        )

    );

}


function zp_mail_request($rows, $cust_email = '', $cust_name = '', $type = 'verified')

{

    $types = zp_mail_types();

    $cfg   = isset($types[$type]) ? $types[$type] : $types['verified'];


    $html = '';

    foreach ($rows as $label => $val) $html .= zp_mail_row($label, $val);


    $cust_email = trim((string)$cust_email);

    $cust_ok    = ($cust_email !== '' && filter_var($cust_email, FILTER_VALIDATE_EMAIL));


    // 1. Gửi admin (KHÔNG CC khách, vì khách đã nhận mail riêng ở bước 2 -> tránh khách nhận 2 mail)

    $body_admin = zp_mail_template($cfg['title'], $html);

    $ok_admin   = zp_mail_send($cfg['subject_admin'], $body_admin, array(), array());

    $err_admin  = isset($GLOBALS['zp_mail_error']) ? $GLOBALS['zp_mail_error'] : '';


    // 2. Gửi RIÊNG một mail cho khách (chắc chắn hơn CC)

    $ok_cust = false;

    if ($cust_ok) {

        $intro  = '<p>Xin chào <b>' . htmlspecialchars($cust_name) . '</b>,</p>';

        $intro .= '<p>' . $cfg['intro'] . '</p>';

        $body_c = zp_mail_template($cfg['title'], $intro . $html);

        $ok_cust = zp_mail_send($cfg['subject_cust'], $body_c, array(array($cust_email, $cust_name)));

    } else {

        zp_mail_fail('Không gửi được cho khách: email rỗng hoặc không hợp lệ ("' . $cust_email . '")');

    }

    $err_cust = isset($GLOBALS['zp_mail_error']) ? $GLOBALS['zp_mail_error'] : '';


    // Gộp thông báo lỗi để hiện ở mail_error

    $errs = array();

    if (!$ok_admin) $errs[] = 'Admin: ' . $err_admin;

    if (!$ok_cust)  $errs[] = 'Khách: ' . $err_cust;

    $GLOBALS['zp_mail_error'] = implode(' | ', $errs);

    return ($ok_admin && $ok_cust);

}

##└────────────────────────────────────────────────┘


/** Mail "Yêu cầu xác thực Super Page": gửi admin, CC khách. $rows = array('Nhãn' => 'giá trị') */

function zp_mail_request__BanGoc($rows, $cust_email = '', $cust_name = ''){


    $html = '';

    foreach ($rows as $label => $val) $html .= zp_mail_row($label, $val);

    $body = zp_mail_template('Đăng ký dịch vụ xác thực doanh nghiệp', $html);

    $cc   = $cust_email ? array(array($cust_email, $cust_name)) : array();

    return zp_mail_send('Xác thực doanh nghiệp Verified', $body, array(), $cc);

}

/** Mail báo đăng ký gói Superpage thành công: gửi cho khách */

function zp_send_mail($to, $username, $package)

{

    $html  = '<p>Xin chào <b>' . htmlspecialchars($username) . '</b>,</p>';

    $html .= '<p>Bạn đã đăng ký thành công gói <b>Superpage (' . htmlspecialchars($package) . ')</b> trên VIETB2B.</p>';

    $html .= '<p>Tài khoản của bạn đã được nâng cấp và có thể sử dụng ngay các quyền lợi của gói.</p>';

    $body  = zp_mail_template('Đăng ký gói Superpage thành công!', $html);

    return zp_mail_send('VIETB2B - Đăng ký gói Superpage thành công', $body, array(array($to, $username)));

}

/* =============

 *  LINK GIẢ LẬP (chống người khác tự gõ URL để nâng cấp gói)

 * ============= */

function zp_mock_sign($user_id, $apptransid, $status, $ts){

    return hash_hmac('sha256', $user_id . '|' . $apptransid . '|' . $status . '|' . $ts, ZP_MOCK_SECRET);

}

function zp_mock_verify($user_id, $apptransid, $status, $ts, $sig)

{

    if (!ZP_MOCK_ENABLED) return false;

    if (abs(time() - intval($ts)) > 600) return false; // link hết hạn sau 10 phút

    return zp_safe_equals(zp_mock_sign($user_id, $apptransid, $status, $ts), (string)$sig);

}

/** So sánh chuỗi an toàn (thay hash_equals vì PHP 5.3 chưa có) */

function zp_safe_equals($a, $b)

{

    if (strlen($a) !== strlen($b)) return false;

    $diff = 0;

    for ($i = 0, $n = strlen($a); $i < $n; $i++) {

        $diff |= ord($a[$i]) ^ ord($b[$i]);

    }

    return $diff === 0;

}

/* ==========================================================

 *  JSON giữ nguyên tiếng Việt (PHP 5.3 chưa có JSON_UNESCAPED_UNICODE)

 *  Cần bật extension mbstring.

 * ========================================================== */

function zp_json($data)

{

    $json = json_encode($data);

    return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', 'zp_json_unescape_cb', $json);

}

function zp_json_unescape_cb($m)

{

    $code = hexdec($m[1]);

    // Giữ nguyên ký tự ASCII, surrogate (emoji) và dấu phân tách dòng để JSON không bị hỏng

    if ($code < 0x80 || ($code >= 0xD800 && $code <= 0xDFFF) || $code == 0x2028 || $code == 0x2029) {

        return $m[0];

    }

    return mb_convert_encoding(pack('H*', $m[1]), 'UTF-8', 'UCS-2BE');

}

Thứ Ba, 27 tháng 10, 2026

Check Errors

 if (!function_exists('vb_debug')) {

    function vb_debug($msg){

        // Đường dẫn tới public_html/php-error.log

        $file = $_SERVER['DOCUMENT_ROOT'].'/php-error.log';

        @error_log(date('Y-m-d H:i:s').' '.$msg."\n", 3, $file);

    }

}

function vb_superpage_mode($userid, $userlevel){

    global $db;

    $userid = (int)$userid;

    $today  = date('Y-m-d');

    $tag    = 'SPMODE uid='.$userid.' level='.$userlevel.' today='.$today.' => ';


    if (!in_array((int)$userlevel, array(3, 4, 5))) {

        vb_debug($tag.'STOP: level khong thuoc 3,4,5');

        return 0;

    }

    if ($userid <= 0) {

        vb_debug($tag.'STOP: userid <= 0');

        return 0;

    }

    $result = $db->sql_query("SELECT superpage, date_active, date_expired

        FROM superpage_config

        WHERE shopid = ".$userid."

        ORDER BY id DESC");

    if (!$result) {

        vb_debug($tag.'STOP: SQL error');

        return 0;

    }


    $found = 0;

    while ($row = $db->sql_fetchrow($result)) {

        $found++;

        $begin = substr(trim((string)$row['date_active']), 0, 10);

        $end   = substr(trim((string)$row['date_expired']), 0, 10);

        vb_debug($tag.'ROW superpage='.$row['superpage'].' begin='.$begin.' end='.$end);


        if (!desk_has_date($end))                     continue;

        if ($end < $today)                            continue;

        if (desk_has_date($begin) && $begin > $today) continue;


        $mode = (int)$row['superpage'];

        vb_debug($tag.'OK mode='.$mode);

        return ($mode === 1 || $mode === 2) ? $mode : 0;

    }


    vb_debug($tag.'STOP: '.($found ? 'co dong nhung het han/chua toi ngay' : 'KHONG co dong nao voi shopid nay'));

    return 0;

}

Thứ Ba, 6 tháng 10, 2026

JS + CSS Giỏ Hàng

 

## JS

<script>

    function load__giohang(callback) {        

        var $container = $('.cart-drawer-body');        

        // Thêm hiệu ứng xoay/mờ khi đang tải dữ liệu

        $container.css('opacity', '0.5');

        $.ajax({

            url: '/modules.php',

            type: 'POST',

            dataType: 'html',

            data: {

                name: 'Shoping',

                op: 'load_cart_drawer_ajax'

            },

            success: function(response) {

                $container.html(response).css('opacity', '1');

                if (typeof callback === 'function') callback();

            },

            error: function(xhr, status, error) {

                console.error("Lỗi nạp giỏ hàng:", error);

                $container.css('opacity', '1').html('<p style="text-align:center; padding: 20px; color: #888;">Không thể tải danh sách giỏ hàng.</p>');

            }

        });

    }

    $(document).on("click", ".buy-fast", function(e) {

            e.preventDefault();

            var pid     = $(this).attr("data-pid");

            var soluong = $(this).attr("data-soluong") || 1;

            $.ajax({

                url: '/modules.php',

                type: 'POST',

                dataType: 'html',

                data: { name: 'Shoping', op: 'add_basket_ajax', pid: pid, soluong: soluong },

            })

            .done(function(data) {

                // Nạp dữ liệu mới vào .cart-drawer-body, hoàn tất mới mở Drawer

                load__giohang(function() {

                    $("#cart-drawer-overlay").addClass("active");

                    $("#cart-drawer").addClass("open");

                });

                load__tien__muasp();

                load__soluong__sanpham();

            })

            .fail(function(err) {

                console.error("Lỗi thêm giỏ hàng:", err);

            });

        });

</script>

## Module - Shoping

function add_basket_ajax(){

    global $db, $prefix,$module_name, $cur,$currentlang,$site_live;

    $client = base64_decode(set_session());    

    if(empty($client)){

        Header("Location: modules.php?name=$module_name"); exit();

    }

    $hle2 = 14 * 86400;    

    $langid = get_lang_id();    

    $past_time = time() - $hle2;    

    $db->sql_query("DELETE FROM ".$prefix."_shop_usercat WHERE g_date < '$past_time'");    

        $pid = (int)$_POST['pid'];

        if($pid != 0){

        $gresult = $db->sql_query("SELECT * FROM ".$prefix."_shop a ,".$prefix."_shop_lang b WHERE a.pid=b.pid and b.lang_id=".$langid." and a.pid='$pid'");        

        $goods = $db->sql_fetchrow($gresult);        

        $testg = $db->sql_numrows($gresult);        

        if ($testg != 1){

            Header("Location: modules.php?name=$module_name"); exit();

        }        

        $gnnn = $db->sql_query("SELECT * FROM ".$prefix."_shop_usercat WHERE g_uname='$client' AND g_pid='$goods[pid]'");

        $g2nnn = $db->sql_fetchrow($gnnn);        

        $nnn = $db->sql_numrows($gnnn);    

        if ($nnn == 0) {

            if($goods["saleoff_price"]==0 ){ 

                $price = $goods['price'];

            }else{

                $price = $goods['saleoff_price'];

            }            

            $xdate = time();            

            if(isset($_POST["soluong"])){

                $counter=$_POST["soluong"];

            }else{

                $counter=1;

            }            

            if($db->sql_query("INSERT INTO ".$prefix."_shop_usercat (gid, g_uname, g_pid, g_title, g_price,g_count, g_date) VALUES (NULL, '$client', '$goods[pid]', '$goods[title]', '$price', '$counter', '$xdate')"))

            echo 1;        

        }else{        

            $gidnnn = $g2nnn[gid];

            $gcountnnn = $g2nnn[g_count];

            // $gcountnnn = $gcountnnn+1;

            $gcountnnn  = $gcountnnn + $_POST["soluong"];

            if($db->sql_query("UPDATE ".$prefix."_shop_usercat SET g_count='$gcountnnn' WHERE gid='$gidnnn'"))

            echo 1;

        }    

    }

}

function load__giohang__sanpham(){

    global $db, $prefix, $site_live;

    $client = base64_decode(set_session());

    $data = admin__data__ShopOrders($client);

    if(empty($data)){

        echo '<div class="cart-empty">Giỏ hàng của bạn đang trống!</div>';

        return;

    }

    $sum = 0;

    $total_items = count($data);

    // Thêm class 'cart-scroll' nếu danh sách vượt quá 5 sản phẩm

    $scroll_class = ($total_items > 5) ? ' cart-scroll' : '';

    echo '<div class="card-global-out'.$scroll_class.'">';

        foreach ($data as $key => $value) {

            $price = (float)$value['g_price'];

            $gid   = $value['gid'];

            $title = $value['g_title'];

            $count = (int)$value['g_count'];

            $total = $count * $price;

            $sum   += $total;

            $dataimg = admin__shopimages($value["g_pid"]);

            echo '<div class="card-items" id="cart-item-'.$gid.'">

                <div class="items-pic">

                    <a href="javascript:void(0);">

                        <img src="'.$site_live.'uploads/shop/pic/'.$dataimg.'" alt="'.htmlspecialchars($title).'">

                    </a>

                </div>

                <div class="items-info">

                    <div class="items-title">'.$title.'</div>

                    <div class="items-price">'.format_price($price).'₫</div>

                    

                    <!-- Khung điều chỉnh số lượng -->

                    <div class="cart-qty-box">

                        <button type="button" class="qty-btn" onclick="updateCartQty('.$gid.', '.($count - 1).')">-</button>

                        <input type="number" class="qty-input" value="'.$count.'" min="1" onchange="updateCartQty('.$gid.', this.value)">

                        <button type="button" class="qty-btn" onclick="updateCartQty('.$gid.', '.($count + 1).')">+</button>

                    </div>

                </div>

                <div class="items-right-box">

                    <div class="items-delete" onclick="deleteCartItem('.$gid.')" title="Xóa">&times;</div>

                    <div class="items-total">'.format_price($total).'₫</div>

                </div>

            </div>';

        }

    echo '</div>';

    echo '<div class="cart-sum-box">

        <p>Tổng tiền thanh toán</p>

        <span class="sum-price">'.format_price($sum).'₫</span>

    </div>';

    ?>

        <style type="text/css">

            /* Khung chứa danh sách sản phẩm */

            .card-global-out {

                display: flex;

                flex-direction: column;

                gap: 12px;

            }

            /* CSS Cuộn tự động khi giỏ hàng có trên 5 sản phẩm */

            .card-global-out.cart-scroll {

                max-height: 430px; /* Giới hạn chiều cao cho 5 sản phẩm */

                overflow-y: auto;

                padding-right: 5px;

            }

            /* Tùy chỉnh thanh cuộn đẹp mắt */

            .card-global-out.cart-scroll::-webkit-scrollbar {

                width: 5px;

            }

            .card-global-out.cart-scroll::-webkit-scrollbar-track {

                background: #f1f1f1;

                border-radius: 4px;

            }

            .card-global-out.cart-scroll::-webkit-scrollbar-thumb {

                background: #ccc;

                border-radius: 4px;

            }

            .card-global-out.cart-scroll::-webkit-scrollbar-thumb:hover {

                background: #999;

            }

            /* Item giỏ hàng */

            .card-items {

                display: flex;

                align-items: center;

                padding: 10px;

                background: #fff;

                border: 1px solid #eee;

                border-radius: 8px;

                gap: 10px;

            }

            .items-pic {

                width: 55px;

                height: 55px;

                flex-shrink: 0;

                border-radius: 6px;

                overflow: hidden;

                border: 1px solid #eee;

            }

            .items-pic img {

                width: 100%;

                height: 100%;

                object-fit: cover;

            }

            .items-info {

                flex: 1;

                min-width: 0;

            }

            .items-title {

                font-size: 13px;

                font-weight: 600;

                color: #333;

                white-space: nowrap;

                overflow: hidden;

                text-overflow: ellipsis;

            }

            .items-price {

                font-size: 12px;

                color: #777;

                margin: 2px 0 4px;

            }

            /* Bố cục bộ tăng giảm số lượng */

            .cart-qty-box {

                display: inline-flex;

                align-items: center;

                border: 1px solid #ddd;

                border-radius: 4px;

                overflow: hidden;

                height: 24px;

            }

            .qty-btn {

                width: 24px;

                height: 100%;

                background: #f5f5f5;

                border: none;

                cursor: pointer;

                font-weight: bold;

                font-size: 14px;

                line-height: 1;

                color: #333;

            }

            .qty-btn:hover {

                background: #e0e0e0;

            }

            .qty-input {

                width: 32px;

                height: 100%;

                border: none;

                text-align: center;

                font-size: 12px;

                font-weight: bold;

                -moz-appearance: textfield;

            }

            .qty-input::-webkit-outer-spin-button,

            .qty-input::-webkit-inner-spin-button {

                -webkit-appearance: none;

                margin: 0;

            }

            /* Cột bên phải (Thành tiền & Xóa) */

            .items-right-box {

                display: flex;

                flex-direction: column;

                align-items: flex-end;

                justify-content: space-between;

                height: 55px;

            }

            .items-delete {

                color: #bbb;

                font-size: 18px;

                cursor: pointer;

                line-height: 1;

            }

            .items-delete:hover {

                color: #da1111;

            }

            .items-total {

                font-size: 13px;

                font-weight: bold;

                color: #da1111;

            }

            /* Khung tổng tiền bên dưới */

            .cart-sum-box {

                margin-top: 15px;

                padding-top: 12px;

                border-top: 2px dashed #eee;

                display: flex;

                justify-content: space-between;

                align-items: center;

            }

            .cart-sum-box p {

                margin: 0;

                font-weight: 500;

            }

            .cart-sum-box .sum-price {

                font-size: 16px;

                font-weight: bold;

                color: #da1111;

            }

        </style>

    <?php

}

case "load_cart_drawer_ajax":

    load__giohang__sanpham();

break;

function popup__giohang(){

    echo'

    <div id="cart-drawer-overlay" onclick="closeCartDrawer()"></div>


    <div id="cart-drawer" class="cart-drawer">

        <div class="cart-drawer-header">

            <h3>Giỏ hàng của bạn</h3>

            <button type="button" class="cart-drawer-close" onclick="closeCartDrawer()">&times;</button>

        </div>        

        <div class="cart-drawer-body">';

            // load__giohang(); tai day

            echo'<div id="fadein_fadeout"></div>

        </div>


        <div class="cart-drawer-footer">

            <a href="/mua-hang" class="btn-checkout">Tiến hành thanh toán</a>

        </div>

    </div>';    

    ?>

    <style type="text/css">

        #xgiohang{

            cursor: pointer;

        }

        #cart-drawer-overlay {

            position: fixed;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: rgba(0, 0, 0, 0.4);

            z-index: 99998;

            opacity: 0;

            visibility: hidden;

            transition: all 0.3s ease;

        }

        #cart-drawer-overlay.active {

            opacity: 1;

            visibility: visible;

        }

        /* Khung Drawer Giỏ hàng góc phải */

        .cart-drawer {

            position: fixed;

            top: 0;

            right: -320px; /* Ẩn sang lề phải */

            width: 300px;

            height: 100%;

            background: #fff;

            z-index: 9999999999;

            box-shadow: -4px 0 15px rgba(0, 0, 0, 0.15);

            display: flex;

            flex-direction: column;

            transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);

        }

        /* Khi mở giỏ hàng */

        .cart-drawer.open {

            right: 0;

        }

        /* Header giỏ hàng */

        .cart-drawer-header {

            display: flex;

            justify-content: space-between;

            align-items: center;

            padding: 15px;

            border-bottom: 1px solid #eee;

            background: #f8f9fa;

        }

        .cart-drawer-header h3 {

            margin: 0;

            font-size: 16px;

            font-weight: bold;

            color: #333;

        }

        .cart-drawer-close {

            background: none;

            border: none;

            font-size: 24px;

            line-height: 1;

            color: #888;

            cursor: pointer;

            padding: 0 5px;

        }

        .cart-drawer-close:hover {

            color: #da1111;

        }

        /* Nội dung giỏ hàng */

        .cart-drawer-body {

            flex: 1;

            padding: 15px;

            overflow-y: auto;

        }

        /* Footer nút thanh toán */

        .cart-drawer-footer {

            padding: 15px;

            border-top: 1px solid #eee;

            background: #fff;

        }

        .btn-checkout {

            display: block;

            text-align: center;

            background: #da1111;

            color: #fff;

            padding: 10px;

            border-radius: 5px;

            text-decoration: none;

            font-weight: bold;

            transition: background 0.2s;

        }

        .btn-checkout:hover {

            background: #b50e0e;

            color: #fff;

        }

    </style>

    <script type="text/javascript">

    function toggleCartDrawer() {

        var drawer = document.getElementById('cart-drawer');

        var overlay = document.getElementById('cart-drawer-overlay');

        

        if (drawer && overlay) {

            drawer.classList.toggle('open');

            overlay.classList.toggle('active');

        }

    }

    // Hàm đóng giỏ hàng (dùng cho nút x và overlay)

    function closeCartDrawer() {

        var drawer = document.getElementById('cart-drawer');

        var overlay = document.getElementById('cart-drawer-overlay');        

        if (drawer && overlay) {

            drawer.classList.remove('open');

            overlay.classList.remove('active');

        }

    }

    document.addEventListener('DOMContentLoaded', function() {

        var xgiohangBtn = document.getElementById('xgiohang');

        if (xgiohangBtn) {

            xgiohangBtn.addEventListener('click', function(e) {

                e.preventDefault();

                toggleCartDrawer();

            });

        }

    });

    </script>

    <?php

}

## theme.php

chứa hàm popup__giohang

Thứ Hai, 5 tháng 10, 2026

Chặn chuột phải - tắt Copy

<script>

// Chặn chuột phải âm thầm

document.addEventListener('contextmenu', e => e.preventDefault());


// Chặn phím tắt Copy (Ctrl+C hoặc Cmd+C)

document.addEventListener('keydown', function(e) {

    if ((e.ctrlKey || e.metaKey) && e.key === 'c') {

        e.preventDefault();

    }

});
</script>

Chủ Nhật, 4 tháng 10, 2026

code send mail SMTP

 include('mail/class.phpmailer.php');

include('mail/class.smtp.php');

require_once "includes/data/mail_config.php";


SMTP Error: Could not connect to SMTP host.

==> Code chạy được và không báo lỗi

require_once 'includes/data/mail_config.php';

require_once 'classes/class.phpmailer.php';

require_once 'classes/class.smtp.php';