File: /var/www/content-sp/work-sp/group_question_in_master.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';
$fileName = str_replace('.php', '', basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']));
//check master permissions
//if(in_array($fileName,$pageArray)) {
$masterType = 'sp';
$SP_MASTER_CATEGORY = 'csp_sp_master_category';
$SP_MASTER_STRUCTURE = 'csp_sp_master_structure';
$SP_MEDIUM = 'csp_sp_medium';
$SP_QUESTION = 'csp_sp_question';
$SP_QUESTION_MEDIUM_WISE = 'csp_sp_question_medium_wise';
$SP_EDITORS = 'csp_editors';
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$root_link = $protocol . $_SERVER['HTTP_HOST'] . '/';
$tpcId = $_REQUEST['tpcId'];
$m = $_REQUEST['m'];
$mType = $_REQUEST['mType'];
include 'str_replace_type.php';
$getTpcName = $conn->query("SELECT category_name from $SP_MASTER_STRUCTURE where sub_id='$tpcId'");
$getTpcres = $getTpcName->fetch_assoc();
$topicName = $getTpcres['category_name'];
$paguri = explode("&pageN", $_SERVER['REQUEST_URI']);
$pagination_link = $paguri[0];
$maxGroupquery = $conn->query("select MAX(question_group) as mgrp from $SP_QUESTION limit 1");
$grpQuery = $maxGroupquery->fetch_assoc();
$maxGroup = $grpQuery['mgrp'];
$limit = 50;
$pageNo = isset($_GET['pageN']) ? $_GET['pageN'] : 1;
$indexN = ($pageNo - 1) * $limit;
$countQuery = $conn->query("SELECT count(q.question_id) as total FROM $SP_QUESTION as q where (q.topic_id='$tpcId' or q.sub_topic_id='$tpcId') and q.question_group=0 order by q.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 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 where (sq.topic_id='$tpcId' or sq.sub_topic_id='$tpcId') and sq.question_group=0 order by sq.question_id limit $indexN, $limit";
$quesData = $conn->query($queryQues);
if (isset($_POST["submit"])) {
if ($_POST['ques_id']) {
$qn_group = $_POST['qn_group'];
$quessidd = implode(', ', $_POST['ques_id']);
$checkExist = $conn->query("Select count(question_id) as ifexist from $SP_QUESTION where question_group='$qn_group'");
$existResult = $checkExist->fetch_assoc();
$existRows = $existResult['ifexist'];
if ($existRows == '0') {
$updateQuery = "UPDATE $SP_QUESTION set question_group='$qn_group' where question_id IN($quessidd)";
} else {
$qn_group1=$qn_group;
$updateQuery = "UPDATE $SP_QUESTION set question_group='$qn_group1' where question_id IN($quessidd)";
}
$conn->query($updateQuery);
$sec = "0";
header("Refresh: $sec;");
}
}
?>
<!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>User Question view - Editors Admin</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'; ?>
<section class="question-ui-section">
<form class="form-horizontal" method="post">
<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 $topicName; ?> ]</h4>
</div>
</div>
<div class="row question-ui-section-box mb-2">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="row">
<?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['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 + $indexN, '{$curnt+1}' => $i + $indexN + 1, '{$curnt+2}' => $i + $indexN + 2, '{$curnt+3}' => $i + $indexN + 3, '{$curnt+4}' => $i + $indexN + 4, '{$curnt+5}' => $i + $indexN + 5, '{$curnt+6}' => $i + $indexN + 6, '{$curnt+7}' => $i + $indexN + 7, '{$curnt+8}' => $i + $indexN + 8, '{$curnt+9}' => $i + $indexN + 9, '{$curnt+10}' => $i + $indexN + 10, '{$curnt-1}' => $i + $indexN - 1, '{$curnt-2}' => $i + $indexN - 2, '{$curnt-3}' => $i + $indexN - 3, '{$curnt-4}' => $i + $indexN - 4, '{$curnt-5}' => $i + $indexN - 5, '{$curnt-6}' => $i + $indexN - 6, '{$curnt-7}' => $i + $indexN - 7, '{$curnt-8}' => $i + $indexN - 8, '{$curnt-9}' => $i + $indexN - 9, '{$curnt-10}' => $i + $indexN - 10);
// replace unneccessary spaces from ques and statement
?>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="question-ui-box">
<h4>
<input class="exam_question questiono" style="height:22px; width:22px; border:1px solid #FF0000;" type="checkbox" name="ques_id[]" value="<?php echo $qId; ?>">
<span><?php echo $i + $indexN; ?>.</span> ( Question Master Id: <?php echo $qId; ?> )
</h4>
<?php if ($instructions) { ?>
<div class="question-ui-instruc" style="padding: 10px 10px 0px;">
<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>
</div>
<?php
$i++;
}
?>
</div>
<!-- Pagination -->
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php echo pagination($limit, $pageNo, $pagination_link . "&pageN=", $count); ?>
</div>
</div>
<!-- end question loop repeat -->
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="question-ui-box" style="position: sticky;top:0;">
<h4>Group Question</h4>
<div class="row" style="padding: 10px;">
<label for="input-rounded" class="col-sm-4 control-label" style="width: 28%">Enter Group :</label>
<div class="col-sm-4">
<input type="text" name="qn_group" id="qn_group" value="<?php echo $maxGroup + 1; ?>" class="form-control">
</div>
<div class="col-sm-4">
<button type="submit" name="submit" class="btn btn-warning btn-addon"><i class="fa fa-plus"></i>Add to Group</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</section>
</div><!-- Main Wrapper -->
</div><!-- Page Inner -->
</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>