Preview: question_bulk_add.php
Size: 9.96 KB
/home/jambtst2015/public_html/giraffeng.com/admin/question_bulk_add.php
<?php include("includes/head.php"); ?>
<?php include("includes/header.php"); ?>
<?php
if($_REQUEST['delete']=="del" && $_REQUEST['delete_id']!='')
{
//mysql_query("delete from exam_question_answers_reasons where id='".$_REQUEST['delete_id']."'");
//mysql_query("delete from sat_users_history where user_id='".$_REQUEST['delete_id']."'");
//$delmsg="Details deleted successfully";
header('location:question.php?success=2');
exit();
}
?>
<script>
function showsubject(str) {
//alert(str);
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getsubject1.php?q="+str,true);
xmlhttp.send();
}
}
function showpaper(str1) {
//alert(str1);
if (str1 == "") {
document.getElementById("txtHint1").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint1").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getpaper.php?q="+str1,true);
xmlhttp.send();
}
}
</script>
<script type="text/javascript" language="javascript">
function open_src()
{
if(document.getElementById("div_src").style.display=='none')
{
//document.getElementById("div_src").style.display='block';
$("#div_src").show("slow");
}
else
{
//document.getElementById("div_src").style.display='none';
$("#div_src").hide("slow");
}
}
$(document).ready(function(){
setTimeout(function(){
$(".mydiv").fadeOut("slow", function () {
$(".mydiv").remove("slow");
});
}, 4000);
});
</script>
<?php
if (isset($_POST['submit']) && $_FILES['filename']['name']!="") {
//$deleterecords = "TRUNCATE TABLE exam_question_answers_reasons"; //empty the table of its current records
//mysql_query($deleterecords);
$exam_board_id=$_POST['exam_board_id'];
$subject_id=$_POST['subject_id'];
$paper_id=$_POST['paper_id'];
$sql_data_year = mysql_fetch_array(mysql_query("SELECT * FROM `exam_paper` WHERE `id`='".$paper_id."'"));
$pdate=$sql_data_year['assign_year'];
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
// echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
// echo "<h2>Displaying contents:</h2>";
//readfile($_FILES['filename']['tmp_name']);
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
GLOBAL $i;
$i=0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$i++;
if($i!=1)
{
//$sql_data = mysql_fetch_array(mysql_query('SELECT * FROM exam_topic WHERE name = "'.$data[12].'"'));
//$sql_data1 = mysql_fetch_array(mysql_query('SELECT * FROM exam_sub_topic WHERE name = "'.$data[13].'"'));
$paper_id=$_POST['paper_id'];
$data[0]=addslashes($data[0]);
$data[1]=addslashes($data[1]);
$data[2]=addslashes($data[2]);
$data[3]=addslashes($data[3]);
$data[4]=addslashes($data[4]);
$data[5]=addslashes($data[5]);
$data[6]=addslashes($data[6]);
$data[7]=addslashes($data[7]);
$data[8]=addslashes($data[8]);
$data[10]=addslashes($data[10]);
$data[11]=addslashes($data[11]);
$import="INSERT into exam_question_answers_reasons(exam_board_id,subject_id,topic_id,sub_topic_id,paper_id,question,ans1,reasons1,ans2,reasons2,ans3,reasons3,ans4,reasons4,ans5,reasons5,correct_ans,post_date) values('$exam_board_id','$subject_id','$data[12]','$data[13]','$paper_id','$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$pdate')";
mysql_query($import) or die(mysql_error());
}
}
fclose($handle);
print "Import done";
//view upload form
header('location:question.php?msg=Data Imported');
exit();
}else {
?>
<div class="upload_section">
<?php
print "<h1>Upload new csv by browsing to file and clicking on Upload</h1>\n";
if($_GET['msg']!="")
{
echo $_GET['msg'];
}
print "<form enctype='multipart/form-data' action='question_bulk_add.php' method='post'>";
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="center-tbl new-tbl">
<tr>
<td align="right" valign="top">*Board</td>
<td><select name="exam_board_id" class="validate[required] selectfield require_select" onchange="showsubject(this.value)">
<option value="">--Select Board --</option>
<?php $board = mysql_query("select * from exam_board_master");
while($board_list=mysql_fetch_array($board))
{
?>
<option value="<?php echo $board_list['id']?>" <?php if($_POST['userclass']=='1') { ?>selected="selected"<?php } ?>><?php echo $board_list['name']?></option>
<?php } ?>
</select>
</td>
</tr>
<tr id="txtHint">
<td align="right" valign="top">*Subject</td>
<td><select name="subject_id" class="validate[required] selectfield require_select" onchange="showpaper(this.value)">
<option value="subject_id">--Select subject --</option>
<?php $subject = mysql_query("select * from exam_subject_master");
while($subject_list = mysql_fetch_array($subject))
{
?>
<option value="<?php echo $subject_list['id']?>" <?php if($_POST['userclass']=='1') { ?>selected="selected"<?php } ?>><?php echo $subject_list['name']?></option>
<?php } ?>
</select>
</td>
</tr>
<tr id="txtHint1">
<td align="right" valign="top">*Paper</td>
<td><select name="paper_id" class="validate[required] selectfield require_select" >
<option value="">--Select Paper --</option>
<?php $paper = mysql_query("select * from exam_paper");
while($paper_list = mysql_fetch_array($paper))
{
?>
<option value="<?php echo $paper_list['id']?>" <?php if($_POST['userclass']=='1') { ?>selected="selected"<?php } ?>><?php echo $paper_list['paper_name']?></option>
<?php } ?>
</select>
</td>
</tr>
</table>
<style>
.csv_btn
{
color:#2B6023;
margin-left:20px;
}
</style>
<?php
print "<h2>File name to import:</h2>\n";
print "<input size='50' type='file' name='filename'>\n";
print "<input type='submit' name='submit' value='Upload'>";
print '<a href="question-new - Copy.csv" target="_blank" class="csv_btn">Demo Csv</a>';
print "</form>";
}
?>
</div>
<div class="container_bottom_section">
<?php if($delmsg!=''){ ?>
<p class="mydiv" style="color:#F00; float:left; font-family:Verdana, Geneva, sans-serif; font-size:13px; text-align:left;"><?php echo $delmsg; ?></p>
<?php } ?>
<?php if($_REQUEST['success']=='2'){ ?>
<p class="mydiv" style="color:#090; float:left; font-family:Verdana, Geneva, sans-serif; font-size:13px; text-align:left;">Question Deleted Successfully</p>
<?php } ?>
<?php if($_REQUEST['success']=='3'){ ?>
<p class="mydiv" style="color:#090; float:left; font-family:Verdana, Geneva, sans-serif; font-size:13px; text-align:left;">Question Updated Successfully</p>
<?php } ?>
<!--<a href="javascript:open_src();" class="require" style="margin-right:5px; margin-bottom:5px;"><i class="fa fa-search"></i> Search</a>-->
<?php if($level==1){ ?>
<?php /*?><a href="users_export_xls.php" class="require" style="margin-right:5px; margin-bottom:5px;">Export</a><?php */?>
<a href="userform.php" class="require org" style="margin-right:5px; margin-bottom:5px;"><i class="fa fa-plus"></i> Add User</a>
<?php } ?>
<div class="clear"></div>
<?php if(empty($_REQUEST['submit2'])){$_REQUEST['submit2']='';} ?>
<div class="search-box" style="padding:5px; <?php if($_REQUEST['submit2']=='') { ?>display:none;<?php } ?> border:1px solid #C4C4C4; margin-bottom:10px;" id="div_src">
<div class="require_add">
<h3 style="font-family:Arial, Helvetica, sans-serif; font-size:18px; float:left; color:#2597C9; padding-bottom:5px;"><i class="fa fa-search"></i> Search By</h3>
<div class="clear"></div>
</div>
<form name="myfrm" action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_search">
<tr>
<td colspan="8" height="10"></td>
</tr>
<tr>
<td width="10%" height="25" valign="top" class="require_table_search">Pin Type:</td>
<td colspan="4" align="left" valign="top">
<input type="text" name="pin_type" class="textfield require_field" value="<?php echo $_REQUEST['pin_type']; ?>" />
</td>
<td width="3%"> </td>
</tr>
<tr>
<td colspan="12">
<span style="float:right;margin: 0px 22px 0px 0px;">
<input name="submit2" type="submit" value="Search" class="require sm" style="margin-top:0px !important;" />
<a href="question.php" style="text-decoration:none;" class="require org"> Show All
</a>
</span>
</td>
</tr>
</table>
</form>
</div>
<div class="clear"></div>
</div>
<?php include("includes/footer.php"); ?>
Directory Contents
Dirs: 17 × Files: 180