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/content-sp/work-sp/nqb_master_questions_prev_flag2.php
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
include_once 'config.php';
include_once 'functions.php';
session_start();

if (!empty($_SESSION['editor'])) {
    //current user
    $editorData = json_decode($_SESSION['editor']);
    $adminId = $editorData->eId;
    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $root_link = $protocol . $_SERVER['HTTP_HOST'] . '/';
    include_once 'pagination.php';
    $SP_MASTER_STRUCTURE = 'csp_sp_master_structure';
    $SP_EDITORS = 'csp_editors';
    $SP_QUESTION = 'csp_sp_question';
    $SP_MASTER_CATEGORY = 'csp_sp_master_category';
    $SP_MEDIUM = 'csp_sp_medium';
    $SP_QUESTION_MEDIUM_WISE = 'csp_sp_question_medium_wise';
    $SP_QUES_HISTORY = 'csp_sp_question_history';
    $TEAM_ACCESS = 'csp_team_user_access';
    $TT_PREVIOUS_EXAM_TABLE = 'csp_sp_previous_exam';

    $checkPermissions = $conn->query("SELECT count(id) as have_id FROM $TEAM_ACCESS as ac where ac.work_id='11'");
    $checkIf = $checkPermissions->fetch_assoc();

    if ($checkIf['have_id'] != '0') {

        $pagination_link = 'nqb_master_questions_prev_flag2';

        $allMaster = $conn->query("SELECT mc.master_id, mc.master_name,mc.source from $SP_MASTER_CATEGORY as mc order by mc.master_name asc");

        # previous year exams
        $allExmQuery = "SELECT pe.id, pe.exam_name from $TT_PREVIOUS_EXAM_TABLE as pe  order by pe.exam_name asc";
        $allExmData = $conn->query($allExmQuery);

        $curdate = date('Y-m-d');
        $curdateTime = date('Y-m-d H:i:s');

        /***search data */
        if (isset($_REQUEST['findData'])) {
            $stype = $_REQUEST['stype'];
            $q_prev_ex = $_REQUEST['q_prev_ex'];

            $subQuery = "sq.previous_exam_name='$q_prev_ex' and sq.status='$stype'";

            // $_SESSION['mType'] = 'sp';

            $_SESSION['flagqueryPrev_TEST'] = $subQuery;
?>
            <script>
                window.location.href = "nqb_master_questions_prev_flag2"
            </script>
        <?php
        }

        /**set question flag */
        if (isset($_REQUEST['setFlag'])) {
            $qflag = $_REQUEST['qflag'];
            $qt_ques_id = $_REQUEST['qt_ques_id'];
            foreach ($qt_ques_id as $q) {
                if ($q != '' && $q != '0') {
                    $message = '';
                    $updateFlag = "UPDATE $SP_QUESTION set question_flag='$qflag',last_update_on='$curdateTime' where question_id='$q'";
                    if ($conn->query($updateFlag)) {
                        $message = '<div class="alert alert-success alert-dismissible fade show" role="alert">Flag Set</div>';
                    } else {
                        $message = '<div class="alert alert-danger alert-dismissible fade show" role="alert">Flag Not Set ' . $q . '</div>';
                    }
                }
            }
        }

        if (!empty($_SESSION['flagqueryPrev_TEST'])) {

            // $mType = !empty($_SESSION['mType']) ? $_SESSION['mType'] : 'sp';
            // include 'str_replace_type.php';

            $quesQuery = $_SESSION['flagqueryPrev_TEST'];
            $limit = 100;
            $pageNo = isset($_GET['pageN']) ? $_GET['pageN'] : 1;
            $indexN = ($pageNo - 1) * $limit;
            $countQuery = $conn->query("SELECT count(question_id) as total FROM $SP_QUESTION as sq where $quesQuery and sq.question_flag='2'");
            $cQuery = $countQuery->fetch_assoc();
            $count = $cQuery['total'];
            $noOfPages = ceil($count / $limit);
            $queryQues = "SELECT sq.question_id,sq.old_question_id, sq.medium_id, sq.no_of_option, sq.question_instruction, sq.question_statement, sq.option_1, sq.option_2, sq.option_3, sq.option_4, sq.option_5, sq.correct_answer, sq.question_solution, sq.previous_exam_year, sq.previous_exam_name, sq.exam_shift, sq.question_expiry, sq.question_type, sq.add_date, sq.status, u.contact_name as addBy,sq.last_proofread_by,pf.contact_name as prf_by,sq.last_proofread_date, md.medium_name,sq.question_flag FROM $SP_QUESTION as sq left join $SP_EDITORS as u on u.editor_id=sq.add_by left join $SP_EDITORS as pf on pf.editor_id=sq.last_proofread_by left join $SP_MEDIUM as md on md.medium_id=sq.medium_id where $quesQuery and sq.question_flag='2' limit $indexN, $limit";
            $quesData = $conn->query($queryQues);
        }
        ?>
        <!DOCTYPE html>
        <html lang="en">

        <head>
            <meta charset="UTF-8">
            <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
            <meta name="viewport" content="width=device-width, user-scalable=no">
            <title>Previous Year Questions Flag</title>
            <link rel="icon" href="assets/images/favicon.png" type="image/x-icon">
            <!-- Latest compiled and minified CSS -->
            <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
            <link rel="stylesheet" href="assets/css/bootstrap4.css">
            <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
            <link rel="stylesheet" href="assets/css/new-ques-ui.css">
            <link href="assets/plugins/fontawesome/css/font-awesome.css" rel="stylesheet" type="text/css" />
        </head>

        <body>
            <!-- QUESTION UI SECTION  -->
            <section class="question-ui-section">
                <div class="container-fluid">
                    <div class="jumbotron">
                        <h4 class="display-4">Previous Year Questions Flag </h4>
                        <a href="nqb_master_questions_flag" target="_blank">Set Questions Flagging >>></a>
                        <hr class="my-4">

                        <?php if (isset($message)) {
                            echo $message;
                        } ?>
                        <div class="row">
                            <form class="form-horizontal" method="post" onSubmit="return validateForm();">
                                <div class="form-group row">
                                    <label for="q_prev_ex" class="col-sm-4 col-form-label">Previous Exam</label>
                                    <div class="col-sm-8">
                                        <select name="q_prev_ex" id="q_prev_ex" class="form-control">
                                            <option value="0">---</option>
                                            <?php foreach ($allExmData as $m) {
                                            ?>
                                                <option value="<?php echo $m['exam_name']; ?>"><?php echo $m['exam_name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="stype" class="col-sm-4 col-form-label">Select Type</label>
                                    <div class="col-sm-8">
                                        <select name="stype" id="stype" class="form-control">
                                            <option value="2">Not Proof Read</option>
                                            <option value="4">Proof Read</option>
                                        </select>
                                    </div>
                                </div>


                                <button type="submit" name="findData" class="btn btn-primary mb-2">Submit</button>
                            </form>
                        </div>
                        <hr>
                        <?php if (!empty($_SESSION['flagqueryPrev_TEST'])) { ?>

                            <div class="row question-ui-section-box">
                                <div class="question-ui-header">
                                    <h4>Total Question - <span><?php echo $count; ?></span></h4>
                                </div>
                            </div>
                            <!-- Pagination -->
                            <div class="row">
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <?php echo pagination($limit, $pageNo, $pagination_link . "?pageN=", $count); ?>
                                </div>
                            </div>

                            <form method="post">
                                <div class="row question-ui-section-box mb-2">
                                    <div class="col-md-6 col-sm-6 col-xs-12">
                                        <label for="checkAll" class="mr-sm-2">Select All <input type="checkbox" id="checkAll" value="0"> </label>
                                        <br>
                                        <label for="qflag" class="mr-sm-2">Question Flag :<select name="qflag" id="qflag" class="form-control mb-2 mr-sm-2">
                                                <option value="">--Select Flag--</option>
                                                <option value="2">Move without proofread</option>
                                                <option value="1">Move</option>
                                            </select></label>

                                        <button type="submit" name="setFlag" class="btn btn-primary mb-2">Set</button>
                                    </div>
                                    <div class="col-md-6 col-sm-6 col-xs-12"></div>
                                </div>
                                <hr>
                                <input class="form-control" type='text' id='search' placeholder='Search: Not Move, Move without proof read'>
                                <hr>
                                <!-- Start question loop -->
                                <?php
                                $i = 1;
                                $mType = '';
                                $spaceArray = '';
                                $replaceSpaceArray = '';
                                foreach ($quesData as $ql) {
                                    $qId = $ql['question_id'];
                                    $qOldId = $ql['old_question_id'];

                                    $getEntity = $conn->query("select m.master_name, s.category_name as subject, t.category_name as topic, st.category_name as subtopic,m.source from $SP_QUESTION as q LEFT JOIN $SP_MASTER_CATEGORY as m ON m.master_id=q.master_id LEFT JOIN $SP_MASTER_STRUCTURE as s ON s.sub_id=q.subject_id LEFT JOIN $SP_MASTER_STRUCTURE as t ON t.sub_id=q.topic_id LEFT JOIN $SP_MASTER_STRUCTURE as st ON st.sub_id=q.sub_topic_id where q.question_id='$qId'");
                                    $entData = $getEntity->fetch_assoc();
                                    $dispEnt = $entData['master_name'] . "->" . $entData['subject'] . "->" . $entData['topic'] . "->" . $entData['subtopic'];

                                    $mType = strtolower($entData['source']);
                                    include('str_replace_type.php');

                                    // echo "Mty ".$mType;

                                    $instructions = str_replace('../', $root_link, $ql['question_instruction']);
                                    $instructions = str_replace($spaceArray, $replaceSpaceArray, $instructions);
                                    $question = str_replace('../', $root_link, $ql['question_statement']);
                                    $question = str_replace($spaceArray, $replaceSpaceArray, $question);

                                    $question_solution = str_replace('../', $root_link, $ql['question_solution']);
                                    $question_solution = str_replace($spaceArray, $replaceSpaceArray, $question_solution);

                                    $option1 = str_replace('../', $root_link, $ql['option_1']);
                                    $option1 = str_replace($spaceArray, $replaceSpaceArray, $option1);
                                    $option2 = str_replace('../', $root_link, $ql['option_2']);
                                    $option2 = str_replace($spaceArray, $replaceSpaceArray, $option2);
                                    $currect_ans = $ql['correct_answer'];
                                    $preExmDet = $ql['previous_exam_name'] . "/" . $ql['previous_exam_year'] . "/" . $ql['exam_shift'];
                                    // get question proof reading status
                                    $ques_prf_status = $ql['status'];
                                    $addBy = $ql['addBy'];
                                    $addDate = $ql['add_date'];
                                    $medium = $ql['medium_id'];
                                    $question_flag = $ql['question_flag'];
                                    /**current ques flag */
                                    if ($question_flag == '0') {
                                        $currentFlag = '<span style="font-size:10px;" class="badge badge-danger">Not Move</span>';
                                    } else if ($question_flag == '1') {
                                        $currentFlag = '<span style="font-size:10px;" class="badge badge-success">Move</span>';
                                    } else if ($question_flag == '2') {
                                        $currentFlag = '<span style="font-size:10px;" class="badge badge-warning">Move without proof read</span>';
                                    }

                                    /*** proof read data*/
                                    if ($ql['last_proofread_by'] != '') {
                                        $readBy = $ql['prf_by'];
                                        $readDate = $ql['last_proofread_date'];
                                        $readText = '<span class="proof">Proof Read <i class="fa fa-check-circle"></i></span>';
                                        $readStatus = $readBy . ' / ' . $readDate;
                                    } else {
                                        if ($ques_prf_status == '3' || $ques_prf_status == '4') {
                                            $readText = '<span class="proof">Proof Read <i class="fa fa-check-circle"></i></span>';
                                        } else {
                                            $readStatus = '';
                                            $readText = '<span class="not-proof">Not Proof Read <i class="fa fa-times-circle"></i></span> ';
                                        }
                                    }
                                    if ($ql['option_3']) {
                                        $option3 = str_replace('../', $root_link, $ql['option_3']);
                                        $option3 = str_replace($spaceArray, $replaceSpaceArray, $option3);
                                    } else {
                                        $option3 = "";
                                    }
                                    if ($ql['option_4']) {
                                        $option4 = str_replace('../', $root_link, $ql['option_4']);
                                        $option4 = str_replace($spaceArray, $replaceSpaceArray, $option4);
                                    } else {
                                        $option4 = "";
                                    }
                                    if ($ql['option_5']) {
                                        $option5 = str_replace('../', $root_link, $ql['option_5']);
                                        $option5 = str_replace($spaceArray, $replaceSpaceArray, $option5);
                                    } else {
                                        $option5 = "";
                                    }
                                    // replacing cloze test blanks with question id
                                    $varRep = array('{$curnt}' => $i, '{$curnt+1}' => $i + 1, '{$curnt+2}' => $i + 2, '{$curnt+3}' => $i + 3, '{$curnt+4}' => $i + 4, '{$curnt+5}' => $i + 5, '{$curnt+6}' => $i + 6, '{$curnt+7}' => $i + 7, '{$curnt+8}' => $i + 8, '{$curnt+9}' => $i + 9, '{$curnt+10}' => $i + 10, '{$curnt-1}' => $i - 1, '{$curnt-2}' => $i - 2, '{$curnt-3}' => $i - 3, '{$curnt-4}' => $i - 4, '{$curnt-5}' => $i - 5, '{$curnt-6}' => $i - 6, '{$curnt-7}' => $i - 7, '{$curnt-8}' => $i - 8, '{$curnt-9}' => $i - 9, '{$curnt-10}' => $i - 10);
                                    // replace unneccessary spaces from ques and statement
                                    $getEntity = $conn->query("select m.master_name, s.category_name as subject, t.category_name as topic, st.category_name as subtopic from $SP_QUESTION as q LEFT JOIN $SP_MASTER_CATEGORY as m ON m.master_id=q.master_id LEFT JOIN $SP_MASTER_STRUCTURE as s ON s.sub_id=q.subject_id LEFT JOIN $SP_MASTER_STRUCTURE as t ON t.sub_id=q.topic_id LEFT JOIN $SP_MASTER_STRUCTURE as st ON st.sub_id=q.sub_topic_id where q.question_id='$qId'");
                                    $entData = $getEntity->fetch_assoc();
                                    $dispEnt = $entData['master_name'] . "->" . $entData['subject'] . "->" . $entData['topic'] . "->" . $entData['subtopic'];
                                ?>
                                    <div class="row question-ui-section-box mb-2 search_title">
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div class="question-ui-box">
                                                <h4><span><?php echo $i + $indexN; ?>.</span> ( Question Master Id: <?php echo $qId; ?> )
                                                    <span class="edit-btn"></span><input class="checkAll1" style="height:22px; width:22px; border:1px solid #FF0000;" type="checkbox" name="qt_ques_id[]" value="<?php echo $qId; ?>" />
                                                </h4>
                                                <h5 class="ques-topic-name"><?php echo $dispEnt; ?> </h5>
                                                <div class="question-ui-status">
                                                    <h6 class="gen_ins">Current Flag: <?php echo $currentFlag; ?>
                                                    </h6>
                                                </div>
                                                <?php if ($instructions) { ?>
                                                    <div class="question-ui-instruc">
                                                        <h4>Instructions</h4>
                                                        <p><?php echo $instructions; ?></p>
                                                    </div>
                                                <?php } ?>
                                                <div class="question-ques-option">
                                                    <?php echo strtr((str_replace('../', $root_link, $question)), $varRep); ?>
                                                </div>
                                                <div class="question-ui-options">
                                                    <ul>
                                                        <li><input <?php if ($currect_ans == 1) echo "checked"; ?> id="rd_ans1<?php echo $i; ?>" type="radio" value="1" name="rd_ans<?php echo $i; ?>"><?php echo $option1; ?></li>
                                                        <li><input <?php if ($currect_ans == 2) echo "checked"; ?> id="rd_ans2<?php echo $i; ?>" type="radio" value="2" name="rd_ans<?php echo $i; ?>"><?php echo $option2; ?></li>
                                                        <?php if ($option3 != "") { ?>
                                                            <li><input <?php if ($currect_ans == 3) echo "checked"; ?> id="rd_ans3<?php echo $i; ?>" type="radio" value="3" name="rd_ans<?php echo $i; ?>"><?php echo $option3; ?></li>
                                                        <?php } ?>
                                                        <?php if ($option4 != "") { ?>
                                                            <li><input <?php if ($currect_ans == 4) echo "checked"; ?> id="rd_ans4<?php echo $i; ?>" type="radio" value="4" name="rd_ans<?php echo $i; ?>"><?php echo $option4; ?></li>
                                                        <?php } ?>
                                                        <?php if ($option5 != "") { ?>
                                                            <li><input <?php if ($currect_ans == 5) echo "checked"; ?> id="rd_ans5<?php echo $i; ?>" type="radio" value="5" name="rd_ans<?php echo $i; ?>"><?php echo $option5; ?></li>
                                                        <?php } ?>
                                                    </ul>
                                                </div>
                                                <div class="question-ui-solution">
                                                    <span>Solution</span>
                                                    <?php echo $question_solution; ?>
                                                </div>
                                                <div class="question-ui-status">
                                                    <h6>Question Status: <?php echo $readText; ?>
                                                    </h6>
                                                    <h6>Add : <span class="mail-id"><?php echo $addBy . " / " . $addDate; ?></span></h6>
                                                    <h6>Proof Read : <span class="mail-id"><?php echo $readStatus; ?> </span></h6>
                                                    <?php if ($ql['previous_exam_name'] != '') { ?>
                                                        <h6 title="Previous Exam Details"><?php echo $preExmDet; ?></h6>
                                                    <?php } ?>
                                                </div>
                                                <div class="question-ui-translate">
                                                    <p>Available for translate : <?php echo $ql['question_type'] == '0' ? 'Yes' : 'No'; ?></p>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div class="question-ui-box">***
                                            </div>

                                        </div>
                                    </div>
                                <?php
                                    $i++;
                                }
                                ?>
                            </form>
                            <!-- Pagination -->
                            <div class="row">
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <?php echo pagination($limit, $pageNo, $pagination_link . "?pageN=", $count); ?>
                                </div>
                            </div>
                            <!-- end question loop repeat -->
                        <?php } ?>
                    </div>
                </div>
            </section>
            <!-- END QUESTION UI SECTION  -->

        </body>
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="assets/plugins/jquery-ui/jquery-ui.min.js"></script>
        <script src="assets/js/bootstrap4.min.js"></script>
        <script>
            function validateForm() {
                if (jQuery("#q_prev_ex").val() == '0') {
                    alert("Select exam");
                    return false;
                }
            }
            var jq = jQuery.noConflict();
            jq(document).ready(function() {
                jq("#ondate").datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                jq("#fdate").datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                jq("#tdate").datepicker({
                    changeMonth: true,
                    changeYear: true
                });
            });
            jQuery("#checkAll").change(function() {

                var check = this.value;
                if (check == 0) {
                    jQuery(".checkAll1").prop('checked', jQuery(this).prop('checked'));
                    jQuery(".checker").find('span').addClass('checked');
                    jQuery("#checkAll").val(1);

                } else if (check == 1) {
                    jQuery(".checkAll1").prop('checked', jQuery(this).prop('checked'));
                    jQuery(".checker").find('span').removeClass('checked');
                    jQuery("#checkAll").val(0);
                }
                //jQuery(".checkAll1").prop('!checked', jQuery(this).prop('!checked'));
                //jQuery(".checker").find('span').removeClass('checked');
            });
            jQuery('#search').keyup(function() {

                // Search text
                var text = jQuery(this).val().toLowerCase();

                // Hide all content class element
                jQuery('.search_title').hide();

                // Search 
                jQuery('.search_title .gen_ins').each(function() {
                    if (jQuery(this).text().toLowerCase().indexOf("" + text + "") != -1) {
                        jQuery(this).closest('.search_title').show();
                    }
                });
            });
        </script>

        </html>
<?php
    } else {
        echo "You dont have permissions";
    }
} else {
    echo "Please Logged In";
}