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_question_entity_change_view.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'] . '/';

    $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';

    $type = $_REQUEST['type'];
    $type_id = $_REQUEST['type_id'];
    $mType = $_REQUEST['mType'];
    if ($type != '' && $type_id != '') {
        if ($type == "S") {
            $qryT = " and sq.subject_id='$type_id'";
        } else if ($type == "T") {
            $qryT = " and sq.topic_id='$type_id'";
        } else if ($type == "ST") {
            $qryT = " and sq.sub_topic_id='$type_id'";
        } else {
            $qryT = " and sq.subject_id='nosubject'";
        }

        include 'str_replace_type.php';

        $paguri = explode("&pageN",$_SERVER['REQUEST_URI']);
        $pagination_link = $paguri[0];

        $getName = $conn->query("SELECT c.category_name, m.master_name from $SP_MASTER_STRUCTURE as c LEFT JOIN $SP_MASTER_CATEGORY as m ON m.master_id=c.master_id where c.sub_id='$type_id'");
        $mData = $getName->fetch_assoc();
        $dispName = $mData['master_name'] . "->" . $mData['category_name'];

        $ques_edit_url = '/work-sp/nqb_question_edit';
        $ques_edit_url_live = '/work-sp/nqb_question_edit_live';
        $ques_edit_url_trans = '/work-sp/nqb_question_edit_secondary';
        $ques_add_url_trans = '/work-sp/nqb_question_add_translated';

        if (isset($_REQUEST['changeEnt'])) {
            $ent_master = $_REQUEST['ent_master'];
            $ent_subject = $_REQUEST['ent_subject'];
            $ent_topic = $_REQUEST['ent_topic'];
            $ent_sub_topic = $_REQUEST['ent_sub_topic'];
            $ent_ques_id = $_REQUEST['ent_ques_id'];
            if($mType == 'sp') {
                $question_server = array("sarkari-pariksha");
                $quesOfjson = json_encode($question_server, JSON_UNESCAPED_UNICODE);
            } else if($mType == 'oly') {
                $question_server = array("csc-olympiad");
                $quesOfjson = json_encode($question_server, JSON_UNESCAPED_UNICODE);
            } else {
                $quesOfjson = '';
            }

            if ($ent_master != '' && $ent_subject != '' && $ent_topic != '') {
                foreach ($ent_ques_id as $e_q) {
                    $f_ques_id = $e_q;
                    $checkQuestionOf = $conn->query("SELECT question_of FROM $SP_QUESTION where question_id='$f_ques_id'");
                    $quesCheck = $checkQuestionOf->fetch_assoc();
                    if ($quesCheck['question_of'] == '') {
                        $quesOfServer = ",question_of='$quesOfjson'";
                    } else {
                        $quesOfServer = '';
                    }
                    $updateQuery = "UPDATE $SP_QUESTION set master_id='$ent_master', subject_id='$ent_subject', topic_id='$ent_topic', sub_topic_id='$ent_sub_topic',last_update_by='$adminId' $quesOfServer where question_id = '$f_ques_id'";
                    if ($conn->query($updateQuery)) {
                        echo "{Updated :" . $f_ques_id . '}';
                        echo '-';
                    } else {
                        echo "{Not Updated :" . $f_ques_id . '}';
                        echo '-';
                    }
                }
            } else {
                echo 'required field will not be empty';
            }
        }

        $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 sq.question_id!='' $qryT order by sq.question_id");
        $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 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 sq.question_id!='' $qryT order by sq.question_id 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>Question view - Topic/Subtopic change</title>
            <link rel="icon" href="assets/images/favicon.png" type="image/x-icon">
            <!-- Latest compiled and minified 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>
            <?php include_once 'pagination.php'; ?>

            <!-- QUESTION UI SECTION  -->
            <section class="question-ui-section">
                <div class="container-fluid">
                    <div class="row question-ui-section-box">
                        <div class="question-ui-header">
                            <h4>Total Question - <span><?php echo $count; ?></span> [ <?php echo $dispName; ?> ]</h4>
                        </div>
                    </div>
                    <!--entity change form ------>
                    <form onsubmit="return validateChange();" method="post">
                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select Master Type*</label>
                            <div class="col-sm-4">
                                <select name="ent_master_type" class="form-control" id="ent_master_type">
                                    <option value="">--Choose Master Type--</option>
                                    <option value="sp">Sarkari Pariksha</option>
                                    <option value="oly">Olympiad</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select Master*</label>
                            <div class="col-sm-4">
                                <select name="ent_master" id="ent_master" class="form-control">
                                    <option value="">--Choose Master--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select Subject*</label>
                            <div class="col-sm-4">
                                <select name="ent_subject" class="form-control" id="ent_subject">
                                    <option value="">--Select Subject--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select Topic*</label>
                            <div class="col-sm-4">
                                <select name="ent_topic" id="ent_topic" class="form-control">
                                    <option value="">--Choose Topic--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select Sub Topic</label>
                            <div class="col-sm-4">
                                <select name="ent_sub_topic" id="ent_sub_topic" class="form-control">
                                    <option value="">--Choose Sub Topic--</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="q_master" class="col-sm-2 col-form-label">Select All</label>
                            <div class="col-sm-4">
                                <input type="checkbox" id="checkAll" value="0">
                            </div>
                        </div>
                        <button type="submit" name="changeEnt" class="btn btn-primary mb-2">Change</button>
                        <hr>
                        <input class="form-control" type='text' id='search' placeholder='Search: Question Id or statement...'>
                        <hr>
                        <!-- Start question loop -->
                        <?php
                        $i = 1;
                        foreach ($quesData as $ql) {
                            $qId = $ql['question_id'];
                            $qOldId = $ql['old_question_id'];
                            $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'];

                            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 {
                                $readStatus = '';
                                if ($ques_prf_status == '4' || $ques_prf_status == '3') {
                                    $readText = '<span class="proof">Proof Read <i class="fa fa-check-circle"></i></span>';
                                } else {
                                    $readText = $readText = '<span id="span_' . $i . '" 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 gen_ins">
                                    <div class="question-ui-box">
                                        <h4><span><?php echo $i + $indexN; ?>.</span> ( Question Master Id: <?php echo $qId; ?> )
                                            <input class="checkAll1" style="height:22px; width:22px; border:1px solid #FF0000;" type="checkbox" name="ent_ques_id[]" value="<?php echo $qId; ?>" />
                                        </h4>
                                        <h5 class="ques-topic-name"><?php echo $dispEnt; ?></h5>
                                        <?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 -->
                </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/js/bootstrap4.min.js"></script>

        </html>
        <script type="text/javascript">
            function validateChange() {

                if (jQuery('#ent_master_type').val() == "") {
                    alert("Master Type");
                    jQuery('#ent_master_type').focus();
                    jQuery(":focus").css("background-color", "#f1d9d9");
                    return false;
                }
                if (jQuery('#ent_master').val() == "") {
                    alert("Select master");
                    jQuery('#ent_master').focus();
                    jQuery(":focus").css("background-color", "#f1d9d9");
                    return false;
                }
                if (jQuery('#ent_subject').val() == "") {
                    alert("Select Subject");
                    jQuery('#ent_subject').focus();
                    jQuery(":focus").css("background-color", "#f1d9d9");
                    return false;
                }
                if (jQuery('#ent_topic').val() == "") {
                    alert("Select Topic");
                    jQuery('#ent_topic').focus();
                    jQuery(":focus").css("background-color", "#f1d9d9");
                    return false;
                }
                if (jQuery("input[name='ent_ques_id[]']:checked").length == 0) {
                    alert("checkbox not selected");
                    return false;
                }
            }
            jQuery.noConflict();
            jQuery(document).ready(function() {
                jQuery('#ent_master_type').on('change', function() {
                    var mid = jQuery("#ent_master_type").val();
                    var loadUrl = "ajax_call/nqb_master_topics.php?eid=" + mid + "&type=masterof";
                    jQuery.ajax({
                        url: loadUrl,
                        type: 'POST',
                        data: 'html',
                        success: function(data) {
                            jQuery("#ent_master").html(data);
                        }
                    });
                });
                jQuery('#ent_master').on('change', function() {
                    var mid = jQuery("#ent_master").val();
                    var loadUrl = "ajax_call/nqb_master_topics.php?eid=" + mid + "&type=master";
                    jQuery.ajax({
                        url: loadUrl,
                        type: 'POST',
                        data: 'html',
                        success: function(data) {
                            jQuery("#ent_subject").html(data);
                        }
                    });
                });

                jQuery('#ent_subject').on('change', function() {
                    var subId = jQuery("#ent_subject").val();
                    var mid = jQuery("#ent_master").val();
                    var loadUrl = "ajax_call/nqb_master_topics.php?eid=" + subId + "&type=topic&m=" + mid;
                    jQuery.ajax({
                        url: loadUrl,
                        type: 'POST',
                        data: 'html',
                        success: function(data) {
                            jQuery("#ent_topic").html(data);
                        }
                    });
                });

                jQuery('#ent_topic').on('change', function() {
                    var subId = jQuery("#ent_topic").val();
                    var mid = jQuery("#ent_master").val();
                    var loadUrl = "ajax_call/nqb_master_topics.php?eid=" + subId + "&type=subtopic&m=" + mid;
                    jQuery.ajax({
                        url: loadUrl,
                        type: 'POST',
                        data: 'html',
                        success: function(data) {
                            jQuery("#ent_sub_topic").html(data);
                        }
                    });
                });
            });
            jQuery("#checkAll").change(function() {

                var check = this.value;
                if (check == 0) {
                    jQuery(".search_title:visible .checkAll1").prop('checked', true);
                    jQuery("#checkAll").val(1);

                } else if (check == 1) {
                    jQuery(".checkAll1").prop('checked', false);
                    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>
<?php
    } else {
        echo "parameters required";
    }
} else {
    echo "Please Logged In";
}