File: /var/www/content-sp/work-sp/nqb_add_multiple_question.php
<?php
include_once('header.php');
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$fileName = str_replace('.php', '', basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']));
if (in_array($fileName, $pageArray)) {
/***define tables */
$SP_MEDIUM = 'csp_sp_medium';
$SP_QUESTION = 'csp_sp_question';
$TT_PREVIOUS_EXAM_TABLE = 'csp_sp_previous_exam';
$SP_MASTER_LEVEL = 'csp_sp_master_level';
$SP_QUESTION_DIFFICULTY = 'csp_sp_question_difficulty';
$SP_MASTER_STRUCTURE = 'csp_sp_master_structure';
$SP_QUES_HISTORY = 'csp_sp_question_history';
$curDate = date('Y-m-d H:i:s');
/**request param */
$subject_id = $_REQUEST['subject_id'];
$topic_id = $_REQUEST['topic_id'];
$sub_topic_id = $_REQUEST['sub_topic_id'];
$master_id = $_REQUEST['master_id'];
$mType = $_REQUEST['mType'];
$groupID = $_REQUEST['group_id'] + 1;
$srcMedium = isset($_SESSION['SRC_MED']) ? $_SESSION['SRC_MED'] : '1';
$allMedium = $conn->query("SELECT medium_id,medium_name from $SP_MEDIUM order by medium_id asc");
$allPreExams = $conn->query("SELECT id, exam_name, status from $TT_PREVIOUS_EXAM_TABLE where status = '1' order by exam_name asc");
$allLevel = $conn->query("SELECT level_name,description from $SP_MASTER_LEVEL where status='1'");
$allDifficulty = $conn->query("SELECT difficulty,description from $SP_QUESTION_DIFFICULTY where status='1'");
$groupCountqry = $conn->query("SELECT count(question_id) as grpcnt from $SP_QUESTION where question_group='$groupID'");
$groupdata = $groupCountqry->fetch_assoc();
$groupdataCnt = $groupdata['grpcnt'];
/***get master and topic name */
if ($subject_id == '0') {
$subquery = "ms.sub_id='$sub_topic_id' and sm.sub_id='$topic_id'";
} else {
$subquery = "ms.sub_id='$sub_topic_id' and sm.sub_id='$topic_id' and sms.sub_id='$subject_id'";
}
$masterDetails = $conn->query("SELECT ms.category_name as subtopic,sm.category_name as topic,sms.category_name as subject FROM $SP_MASTER_STRUCTURE as ms left join $SP_MASTER_STRUCTURE as sm on sm.sub_id=ms.parent_id left join $SP_MASTER_STRUCTURE as sms on sms.sub_id=sm.parent_id where $subquery");
$md = $masterDetails->fetch_assoc();
$subject = $md['subject'];
$topic = $md['topic'];
$sub_topic = $md['subtopic'];
if ($subject_id == '0' || $subject_id == '') {
$subjectid0 = $topic_id;
$topicid0 = $sub_topic_id;
$sub_topic_id0 = '0';
} else {
$subjectid0 = $subject_id;
$topicid0 = $topic_id;
$sub_topic_id0 = $sub_topic_id;
}
$tinyMcefolder = '../tiny_mce_' . $mType;
$uploadFolder = '../uploads/tet_admin_photos_' . $mType . '/';
/**str eplace for form submit */
$submitSpacearray = array($tinyMcefolder, $uploadFolder, 'old_tinymcesp', "'");
$submitReplace = array("../wp-content/plugins/tet-india/files/tinymce_new", "/wp-content/uploads/tet_admin_photos/", "../wp-content/plugins/tet-india/files/tinymce", "");
?>
<meta http-equiv="Content-Language" content="hi">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src='https://content.grapossconnect.com/tiny_mce_sp/jscripts/tiny_mce/tinymce.min.js'></script>
<script type="text/javascript">
tinymce.init({
selector: "#instruction",
height: 500,
theme: 'silver',
plugins: "pagebreak,tiny_mce_wiris, image, lists, table, fullscreen, link, anchor, charmap, code, paste",
toolbar: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect |fontselect | fontsizeselect | cut copy paste | bullist numlist | | outdent indent blockquote | link unlink anchor | table | hr removeformat | superscript subscript pagebreak | tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry | charmap image | fullscreen code | customInsertButton",
branding: false,
setup: function(editor) {
editor.ui.registry.addButton('customInsertButton', {
text: 'Auto Set',
onAction: function(_) {
var content = tinyMCE.editors[0].getContent();
var regex = /<p>(.*?)<\/p>/g;
var matches = [];
var match = regex.exec(content);
while (match != null) {
matches.push(match[1]);
match = regex.exec(content);
}
//alert(matches);
var subStr = matches[0];
tinyMCE.editors[1].setContent("" + subStr + "");
var subStr1 = matches[1];
tinyMCE.editors[2].setContent("" + subStr1 + "");
var subStr2 = matches[2];
tinyMCE.editors[3].setContent("" + subStr2 + "");
var subStr3 = matches[3];
tinyMCE.editors[4].setContent("" + subStr3 + "");
var subStr4 = matches[4];
tinyMCE.editors[5].setContent("" + subStr4 + "");
var subStr5 = matches[5];
if(subStr5 !='' && subStr5 !='undefined' && subStr5 != undefined) {
tinyMCE.editors[6].setContent("" + subStr5 + "");
}
tinyMCE.editors[0].setContent("");
}
});
}
});
tinymce.init({
selector: "textarea",
height: 200,
theme: 'silver',
plugins: "pagebreak, tiny_mce_wiris, image, lists, table, fullscreen, link, anchor, charmap, code, paste",
toolbar: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect |fontselect | fontsizeselect | cut copy paste | bullist numlist | | outdent indent blockquote | link unlink anchor | table | hr removeformat | superscript subscript pagebreak | tiny_mce_wiris_formulaEditor tiny_mce_wiris_formulaEditorChemistry | charmap image | fullscreen code | customInsertButton"
});
</script>
<style>
.panel-body div.tox.tox-tinymce {
height: 396px !important;
}
.panel-body div.tox.tox-tinymce.tox-fullscreen {
height: 100% !important;
}
</style>
<div class="page-inner">
<div class="page-title">
<h3>New Question Bank</h3>
<div class="page-breadcrumb">
<ol class="breadcrumb">
<li><a href="dashboard">Home</a></li>
<li class="active">Add Questions</li>
</ol>
</div>
</div>
<div id="main-wrapper">
<div class="row">
<div class="col-md-12">
<div class="row" id="scrooltotop">
<form method="post">
<!-----Question Instruction---->
<div id="topmsgbox"></div>
<div class="col-md-5">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Add Question :- <?php echo $subject . ' >> ' . $topic . ' >> ' . $sub_topic; ?></h3>
</div>
<div class="panel-body" style="margin-top: 10px;">
<!-----html------->
<div class="form-group">
<label>Question Instructions</label>
<textarea name="instruction" id="instruction"><?php if (isset($instruction)) {
echo $instruction;
} ?></textarea>
</div>
<div class="form-group">
<label>Previous Exam Detail</label>
<div class="row">
<div class="col-sm-4">
<select id="prev_exam_name" name="prev_exam_name" class="form-control">
<option value="">--Select Exam--</option>
<?php while ($preExam = $allPreExams->fetch_assoc()) { ?>
<option value="<?php echo $preExam['exam_name'] ?>"><?php echo $preExam['exam_name']; ?></option>
<?php } ?>
</select>
</div>
<div class="col-sm-4">
<input type="text" value="" name="prev_exam_year" id="prev_exam_year" placeholder="Previous Exam Year" class="form-control" />
</div>
<div class="col-sm-4">
<input type="text" value="" name="prev_exam_shift" id="prev_exam_shift" placeholder="Any Exam Shift" class="form-control" />
</div>
</div>
</div>
<div class="form-group">
<label>No. of Option</label>
<input type="text" class="form-control" name="total_option" id="total_option" value="" placeholder="No. of option in question" />
</div>
<div class="form-group">
<label>Tags <code>(For Multiple Tags Use Comma [Exam,SSC] Seprated Value)</code></label>
<input type="text" class="form-control" name="multi_tags" id="multi_tags" value="" placeholder="Tags for question" />
</div>
<div class="form-group">
<label>Medium</label>
<select id="medium" name="medium" class="form-control">
<?php while ($md = $allMedium->fetch_assoc()) { ?>
<option value="<?php echo $md['medium_id'] ?>" <?php if ($md['medium_id'] == @$srcMedium) {
echo "selected";
} ?>><?php echo $md['medium_name'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Level</label>
<select name="ques_level" id="ques_level" class="form-control">
<option value="">--level--</option>
<?php while ($l = $allLevel->fetch_assoc()) { ?>
<option value="<?php echo $l['level_name']; ?>"><?php echo $l['description']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Difficulty</label>
<select name="ques_difficulty" id="ques_difficulty" class="form-control">
<option value="">--difficulty--</option>
<?php while ($d = $allDifficulty->fetch_assoc()) { ?>
<option value="<?php echo $d['difficulty']; ?>"><?php echo $d['description']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group" style="float:left; width:100%;">
<label for="input-Default" class="col-sm-12 control-label">Question Translate</label>
<div class="row">
<div class="col-sm-12">
<input type="checkbox" name="translate_ques" id="translate_ques" value="0" class="form-control" checked />
<br>
<label id="exampleInputName-error" class="error" for="exampleInputName">(If this question is not available in other medium then unchecked the checkbox.)</label>
<label id="exampleInputName-error" class="error" for="exampleInputName">(अगर यह प्रश्न अन्य मीडियम मे उपलब्ध नहीं है तो चेकबॉक्स को अनचेक करें |)</label>
</div>
</div>
</div>
<div class="form-group">
<label>Question Repository</label>
<div class="row">
<div class="col-sm-4">
<label class="control-label"><input type="radio" name="ques_of" value="sarkari-pariksha" class="form-control" checked/>Sarkari Pariksha</label>
</div>
<?php if ($editor_role != '5') { ?>
<div class="col-sm-4">
<label class="control-label"><input type="radio" name="ques_of" value="csc-olympiad" class="form-control" />CSC Olympiad</label>
</div>
<div class="col-sm-4">
<label class="control-label"><input type="radio" name="ques_of" value="sarkari-pariksha,csc-olympiad" class="form-control" />Both Repository</label>
</div>
<?php } ?>
</div>
</div>
<!-----html------->
</div>
</div>
</div>
<!-----Question Instruction---->
<!-----Question---->
<div class="col-md-7">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Question, Options & Answer | Group ID : <?php echo $groupID; ?> | Existing Count : <?php echo $groupdataCnt; ?></h3>
</div>
<div class="panel-body" style="margin-top: 10px;">
<div class="form-group">
<label>Question Statement</label>
<textarea name="question" id="question"><?php echo @$question; ?></textarea>
</div>
<hr>
<table class="table table-striped">
<thead>
<tr>
<th width="1%">No</th>
<th width="10%">Correct</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td><input type="radio" value="1" name="radio_ans" class="radio_ans" id="radio_answer" /></td>
<td><textarea name="ans_1" id="ans_1"><?php echo @$ans1; ?></textarea></td>
</tr>
<tr>
<th scope="row">2</th>
<td><input type="radio" value="2" name="radio_ans" class="radio_ans" id="radio_answer" /></td>
<td><textarea name="ans_2" id="ans_2"><?php echo @$ans2; ?></textarea></td>
</tr>
<tr>
<th scope="row">3</th>
<td><input type="radio" value="3" name="radio_ans" class="radio_ans" id="radio_answer" /></td>
<td><textarea name="ans_3" id="ans_3"><?php echo @$ans3; ?></textarea></td>
</tr>
<tr>
<th scope="row">4</th>
<td><input type="radio" value="4" name="radio_ans" class="radio_ans" id="radio_answer" /></td>
<td><textarea name="ans_4" id="ans_4"><?php echo @$ans4; ?></textarea></td>
</tr>
<tr>
<th scope="row">5</th>
<td><input type="radio" value="5" name="radio_ans" class="radio_ans" id="radio_answer" /></td>
<td><textarea name="ans_5" id="ans_5"><?php echo @$ans5; ?></textarea></td>
</tr>
</tbody>
</table>
<div class="form-group">
<label>Question Solution</label>
<textarea name="solution" id="solution"><?php echo @$question_solution; ?></textarea>
</div>
</div>
</div>
</div>
<!-----Question---->
<div class="col-md-12">
<div class="panel">
<div class="panel-body">
<div class="col-md-6"><span id="msgbox"></span></div>
<div class="col-md-6" style="text-align: end; ">
<input type="hidden" id="masterid" value="<?php echo $master_id; ?>">
<input type="hidden" id="subjectid" value="<?php echo $subject_id; ?>">
<input type="hidden" id="topicid" value="<?php echo $topic_id; ?>">
<input type="hidden" id="subtopicid" value="<?php echo $sub_topic_id; ?>">
<input type="hidden" id="mType" value="<?php echo $mType; ?>">
<input type="hidden" id="gRoup" value="<?php echo $groupID; ?>">
<button type="button" id="savequestion" class="btn btn-success" style="width: 25%;">Save Question</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="page-footer">
<p class="no-s">Graposs Connect ©</p>
</div>
</div>
</div>
<script>
jQuery(function() {
jQuery(document).on('click','#translate_ques', function(){
if(jQuery("#translate_ques").prop("checked")) {
jQuery("#translate_ques").val(0);
} else {
jQuery("#translate_ques").val(1);
}
})
jQuery(document).on('click', '#savequestion', function() {
if (jQuery("input[name='radio_ans']:checked").length == 0) {
jQuery("#msgbox").html("<div style='color: red; font-size:12px;display: inline-block;text-align:center'>Please select correct answer radio button</div>");
} else if (jQuery("input[name='ques_of']:checked").length == 0) {
jQuery("#msgbox").html("<div style='color: red; font-size:12px;display: inline-block;text-align:center'>Select Question Repository</div>");
} else if (jQuery('#ques_level').val() == "") {
jQuery("#msgbox").html("<div style='color: red; font-size:12px;display: inline-block;text-align:center'>Select Question Level</div>");
} else if (jQuery('#ques_difficulty').val() == "") {
jQuery("#msgbox").html("<div style='color: red; font-size:12px;display: inline-block;text-align:center'>Select Question Difficulty</div>");
} else {
var quesData = {
instruction: tinymce.get("instruction").getContent(),
prev_exam_name: $("#prev_exam_name").val(),
prev_exam_year: $("#prev_exam_year").val(),
prev_exam_shift: $("#prev_exam_shift").val(),
multitags: $("#multi_tags").val(),
total_option: $("#total_option").val(),
medium: $("#medium").val(),
queslevel: $("#ques_level").val(),
quesdifficulty: $("#ques_difficulty").val(),
questionoff: ($('input:radio[name="ques_of"]:checked').val()),
question: tinymce.get("question").getContent(),
radioanswer: ($('input:radio[name="radio_ans"]:checked').val()),
answer1: tinymce.get("ans_1").getContent(),
answer2: tinymce.get("ans_2").getContent(),
answer3: tinymce.get("ans_3").getContent(),
answer4: tinymce.get("ans_4").getContent(),
answer5: tinymce.get("ans_5").getContent(),
solution: tinymce.get("solution").getContent(),
master: $("#masterid").val(),
subject: $("#subjectid").val(),
topic: $("#topicid").val(),
subtopic: $("#subtopicid").val(),
mType: $("#mType").val(),
gRoup: $("#gRoup").val(),
qType: $("#translate_ques").val(),
};
jQuery.ajax({
type: "POST",
url: "ajax_call/save_multiple_question_data.php",
data: quesData,
dataType: "json",
encode: true,
success: function(response) {
var status = response.status;
var message = response.message;
if (status == '1') {
jQuery("#msgbox").html("<div style='color: green; font-size:12px;display: inline-block;margin-left: 4px;'>" + message + "</div>");
jQuery("#topmsgbox").html("<div style='color: green; font-size:12px;display: inline-block;margin-left: 4px;'>" + message + "</div>");
tinymce.get('question').setContent('');
tinymce.get('ans_1').setContent('');
tinymce.get('ans_2').setContent('');
tinymce.get('ans_3').setContent('');
tinymce.get('ans_4').setContent('');
tinymce.get('ans_5').setContent('');
tinymce.get('solution').setContent('');
jQuery(".radio_answer").prop('checked', jQuery(this).prop('checked'));
jQuery(".radio").find('span .radio_ans').removeClass('checked');
$('html, body').animate({
scrollTop: $("#scrooltotop").offset().top
}, 2000);
} else {
jQuery("#msgbox").html("<div style='color: red; font-size:12px;display: inline-block;text-align:center'>" + message + "</div>");
}
}
})
}
});
});
</script>
<?php
} else {
echo "<script>alert('You dont have access to add question');</script>";
echo "<script type='text/javascript'>location.href='/work-sp';</script>";
}
include_once('footer.php');
?>