HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/nclive/wp-content/plugins/nc_plugin/nc_search_exam.php
<?php
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_slug = basename($actual_link);

$search_content = $_POST['search_data'];
$search_url = trim($search_content);

global $wpdb;
$TT_EXAM = "sp_exam";
$TT_EXAM_LINKS = "sp_exam_links";
$TT_EXAM_CATEGORY = "sp_exam_category";
$TT_EXAM_ENTITY = "sp_exam_entity";
$TT_CITIES = "sp_city";
$TT_STATES = "sp_states";
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

?>
<!-- ALL PAGE HEADER SECTION -->

<section class="allPageheaderSection wow fadeInDown">
    <div class="allPageheaderSectionbg"></div>
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <h2>Search</h2>
                <!-- <h1>Lorem ipsum dolor sit amet consectetur adipisicing elit</h1> -->
                <p><a href="/">Home</a> / Search</p>
            </div>
        </div>
    </div>
</section>

<?php

if ($search_url != '') {

    // echo "select l.exam_id, n.name, l.entity_id, l.display_text, l.date_type, e.url_slug, l.date, l.update_date, e.exam_name, c.img_icon FROM $TT_EXAM_LINKS as l LEFT JOIN $TT_EXAM as e on e.exam_id=l.exam_id LEFT JOIN $TT_EXAM_CATEGORY as c ON c.cat_id = e.cat_id LEFT JOIN $TT_EXAM_ENTITY as n ON n.id = l.entity_id WHERE e.status!='0' and n.status!='0' and e.exam_name LIKE '%$search_url%' group by l.exam_id order by l.update_date desc limit 0, $limit";

    $limit = 18;
    // query to get data as per entity id
    $examDetails = $wpdb->get_results("select l.exam_id, n.name, l.entity_id, l.display_text, l.date_type, e.url_slug, l.date, l.update_date, e.exam_name, c.img_icon FROM $TT_EXAM_LINKS as l LEFT JOIN $TT_EXAM as e on e.exam_id=l.exam_id LEFT JOIN $TT_EXAM_CATEGORY as c ON c.cat_id = e.cat_id LEFT JOIN $TT_EXAM_ENTITY as n ON n.id = l.entity_id WHERE e.status!='0' and n.status!='0' and e.exam_name LIKE '%$search_url%' group by l.exam_id order by l.update_date desc limit 0, $limit");
    $examCount = $wpdb->num_rows;

    // to highlight text via php
    function highlightSearch($content, $search_val)
    {
        $wordarray = explode(" ", $search_val);
        $wordCount = count($wordarray);

        for ($i = 0; $i < $wordCount; $i++) {
            $wordd = $wordarray[$i];
            $color_text = "<mark>$1</mark>";
            $content = preg_replace("/\b([a-z0-9 ]*${wordd}[a-z0-9 ]*)\b/i", $color_text, $content);
        }
        return $content;
    }

?>


    <!-- END ALL PAGE HEADER SECTION -->

    <!-- STATE BOARD EXAM PAGE SECTION -->


    <section class="StateBoardexamPageSection">
        <div class="container">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="SearchStateBoardExamsBox wow fadeInUp">
                        <h4>Search Exam</h4>
                        <form action="">
                            <i class="fas fa-search"></i>
                            <input type="text" id="search_data" placeholder="Exam Name..." value="<?php echo $search_url; ?>" autocomplete="off">
                        </form>
                    </div>
                    <div class="NotificationRightBoxHeader wow fadeInDown">
                        <h4>Show <b><span id="countData"><?php echo $examCount; ?> </span> </b>Exams</h4>
                    </div>
                </div>

                <div id="loader" style="display:none">
                    <p align="center"><i class="fa fa-spinner fa-spin"></i> Loading...</p>
                </div>

                <div id="examList" class="examList">
                    <?php foreach ($examDetails as $exam) {
                        if ($exam->display_text != '') {
                            $display_text = $exam->display_text;
                        } else {
                            $display_text = $exam->name;
                        }

                        if ($exam->date_type == 'FT') {
                            $split_date = preg_split('/,+/', $exam->date);
                            $date1 = $split_date[0];
                            $startDate = date('j M Y', strtotime($date1));
                            $date2 = $split_date[1];
                            $endDate = date('j M Y', strtotime($date2));

                            $datetype = ' From ' . $startDate . ' To ' . $endDate;
                        } else if ($exam->date_type == 'T') {
                            $datetype = $exam->date;
                        } else if ($exam->date_type == 'N') {
                            $datetype = date('jS M Y', strtotime($exam->date));
                        }

                        if (!empty($_POST["search_data"])) {
                            $new_title = highlightSearch($exam->exam_name, trim($_POST["search_data"]));
                            // echo $exam->exam_name.' = '.$_POST["search_data"];
                        }
                    ?>

                        <div class="col-md-4 col-sm-4 col-xs-12">
                            <div class="StateBoardexamBox wow fadeInUp">
                                <?php if ($exam->img_icon != '') { ?>
                                    <img src="/images/<?php echo $exam->img_icon; ?>" alt="">
                                <?php } ?>
                                <div>
                                    <a href="/exams/<?php echo $exam->url_slug; ?>/">
                                        <h4><?php echo $new_title; ?></h4>
                                    </a>
                                    <p style="display: block;">
                                        <span style="margin-bottom: 6px;color: #135fb1;" title="<?php echo $exam->name; ?>"> <i class="fas fa-id-card"></i> <?php echo $display_text; ?></span>
                                        <?php if ($datetype != '') { ?>
                                            <br /><span title="<?php echo $exam->name; ?>" style="color:#ed2551;"><i class="fas fa-calendar-alt"></i> <?php echo $datetype; ?> </span>
                                        <?php } ?>
                                    </p>
                                </div>
                            </div>
                        </div>
                    <?php  } ?>
                </div>
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="loadmore">
                        <input type="button" id="loadBtn" class="SeeMoreBtn wow fadeInUp" value="See More">
                        <input type="hidden" id="data_row" value="0">
                        <input type="hidden" id="data_row1" value="">
                    </div>
                </div>
            </div>

        </div>
    </section>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script>
        // function to highlight text
        function hightlightTxt(search_name) {
            var searchfilter = new RegExp(search_name + "(?=[^>]*<)", "ig");
            var repstr = "<mark>$&</mark>";
            $('.examList').html($('.examList').html().replace(searchfilter, repstr));
        }

        $(document).ready(function() {

            // load more button
            $(document).on('click', '#loadBtn', function() {
                var data_row = Number($('#data_row').val());
                var row_count = $('#countData').text();
                var limit = <?php echo $limit; ?>;
                var search_url = $('#search_data').val();
                if (search_url != '') {
                    var search_name = $('#search_data').val();
                } else {
                    var search_name = '<?php echo $search_url; ?>';
                }

                data_row = data_row + limit;
                $('#data_row').val(data_row);

                var url = '/wp-content/plugins/nc_plugin/api/nc_search_data.php';
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: {
                        'data_row': data_row,
                        "exam_name": search_name,
                        'limit': limit
                    },
                    success: function(data) {
                        var rowCount = data_row + limit;
                        $('.examList').append(data);
                        $('#countData').html(rowCount);
                        var pagenum = $('input[name="page_count"]').val();
                        var totalnum = $('input[name="data_row_count"]').val();
                        // console.log(pagenum);
                        // console.log(totalnum);

                        if (parseInt(totalnum) >= parseInt(pagenum)) {
                            $("#loadBtn").show();
                        } else {
                            $("#loadBtn").hide();
                        }
                    }
                });
            });
            // search data using search field 
            $('#search_data').keyup(function(e) {
                var trim_str = $(this).val();
                var search_name = $.trim(trim_str);

                var searchfilter = new RegExp(search_name + "(?=[^>]*<)", "ig");
                var repstr = "<mark>$&</mark>";
                $('.examList').html($('.examList').html().replace(/(^\s+|\s+$)/g, ""));

                if (search_name != '') {
                    if (e.which == 13) {
                        e.preventDefault();
                        return false;
                    }
                    hightlightTxt(search_name);
                    if (search_name.length > 2) {
                        searchExam(search_name);
                    }
                } else {
                    location.reload(true);
                }
            });

            // search function
            function searchExam(search_name) {
                var limit = '<?php echo $limit; ?>';
                var url = '/wp-content/plugins/nc_plugin/api/nc_search_data.php';
                $.ajax({
                    url: url,
                    type: 'POST',
                    data: {
                        "exam_name": search_name,
                        "limit": limit
                    },
                    beforeSend: function() {
                        $('#loader').show();
                    },
                    success: function(response) {
                        if (response != '') {
                            $('#loader').hide();
                            $('#examList').html(response);
                            var pagenum = $('input[name="page_count"]').val();
                            $('#countData').text(pagenum);
                            hightlightTxt(search_name); // function for highlighting data
                            var totalnum = $('input[name="data_row_count"]').val();

                            if (parseInt(totalnum) >= parseInt(pagenum)) {
                                $("#loadBtn").show();
                            } else {
                                $("#loadBtn").hide();
                            }
                        }
                    }
                });
            }
        });
    </script>

    <!-- END STATE BOARD EXAM PAGE SECTION -->

<?php } else {
    /*----------state -exam_id data query for latest updates-------*/
    $sqlexamData = $wpdb->get_results("SELECT l.exam_id FROM $TT_EXAM_LINKS as l INNER JOIN $TT_EXAM AS e on e.exam_id=l.exam_id where e.status='1'  AND e.top_display_order !=0 group by l.exam_id ORDER BY e.top_display_order DESC limit 0,15");

    $examId = '';
    for ($i = 0; $i < count($sqlexamData); $i++) {
        $examId .= $sqlexamData[$i]->exam_id . ',';
    }
    $examIDs = rtrim($examId, ',');

    $getLatestUpdate = $wpdb->get_results("SELECT e.exam_id, e.exam_name, e.url_slug, c.img_icon, t.name FROM $TT_EXAM AS e LEFT JOIN $TT_EXAM_LINKS AS l ON l.exam_id=e.exam_id LEFT JOIN $TT_EXAM_CATEGORY AS c on c.cat_id=e.cat_id LEFT JOIN $TT_EXAM_ENTITY AS t ON t.id=l.entity_id WHERE e.exam_id IN (" . $examIDs . ") group by e.exam_id ORDER BY e.top_display_order DESC limit 0,6");
?>


    <!-- END ALL PAGE HEADER SECTION -->

    <!-- STATE BOARD EXAM PAGE SECTION -->

    <section class="StateBoardexamPageSection">
        <div class="container">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="SearchStateBoardExamsBox wow fadeInUp">
                        <h4>Search Exam</h4>
                        <form action="/search/" method="post" id="search-data">
                            <i class="fas fa-search"></i>
                            <input type="text" name="search_data" id="search_data" placeholder="Search Exams etc...">
                        </form>
                    </div>
                </div>

                <div class="SearchStateBoardExamsBox wow fadeInUp">
                    <h3>View Latest Exams</h3>
                </div>
                <?php foreach ($getLatestUpdate as $update) {  ?>

                    <div class="col-md-4 col-sm-4 col-xs-12">
                        <div class="StateBoardexamBox wow fadeInUp">
                            <?php if ($update->img_icon != '') { ?>
                                <img src="/images/<?php echo $update->img_icon; ?>" alt="">
                            <?php } ?>
                            <div>
                                <a href="/exams/<?php echo $update->url_slug; ?>/">
                                    <h4> <?php echo $update->exam_name; ?></h4>
                                </a>
                                <span><?php echo $update->name; ?></span>
                            </div>
                        </div>
                    </div>
                <?php  } ?>

            </div>

        </div>
    </section>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script>
        window.onload = () => {
            const mySearchInput = document.getElementById('search_data');
            mySearchInput.onpaste = e => e.preventDefault();
        }

        $(document).ready(function() {
            // search data using search field 
            $('#search_data').keyup(function(e) {
                // if (e.keyCode == 10 || e.keyCode == 13)
                //     e.preventDefault();

                var trim_str = $(this).val();
                var search_name = $.trim(trim_str);

                if (search_name != '') {
                    if (search_name.length >= 3) {
                        let form = document.getElementById("search-data");
                        form.submit();
                    }
                }
            });

        });
    </script>

<?php } ?>