-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.php
207 lines (201 loc) · 6.88 KB
/
quiz.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
include("header.php");
if($_SESSION[sessionid] == $_POST[sessionid])
{
if(isset($_POST[submit]))
{
$title= mysqli_real_escape_string($con, $_POST[title]);
$description= mysqli_real_escape_string($con, $_POST[description]);
if(isset($_GET[editid]))
{
$sql="UPDATE quiz set course_id=$_POST[course],semester=$_POST[semester],subject_id=$_POST[subject],title=$title,description=$description WHERE quiz_id=$_GET[editid]";
$qsql = mysqli_query($con,$sql);
if(!$qsql)
{
echo mysqli_error($con);
}
if(mysqli_affected_rows($con) == 1)
{
echo "<SCRIPT>alert(Quiz record UPDATED successfully..);</SCRIPT>";
echo "<script>window.location=viewquiz.php;</script>";
}
}
else
{
$sql="INSERT INTO quiz(user_id,course_id,semester,subject_id,title,description) values ($_SESSION[user_id],$_POST[course],$_POST[semester],$_POST[subject],$_POST[title],$description)";
$qsql = mysqli_query($con,$sql);
if(!$qsql)
{
echo mysqli_error($con);
}
if(mysqli_affected_rows($con) == 1)
{
echo "<SCRIPT>alert(Quiz record inserted successfully..);</SCRIPT>";
echo "<script>window.location=viewquiz.php;</script>";
}
}
}
}
$_SESSION[sessionid] = rand();
if(isset($_GET[editid]))
{
$sqledit = "SELECT * FROM quiz WHERE quiz_id=$_GET[editid]";
$qsqledit = mysqli_query($con,$sqledit);
$rsedit = mysqli_fetch_array($qsqledit);
}
?>
<section id="contentSection">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<div class="left_content">
<div class="contact_area">
<h2>Quiz</h2>
<p>Add the quiz.</p>
<form action="" class="contact_form" method="post" name="frmquiz" onsubmit="return validateform()">
<input type="hidden" name="sessionid" value="<?php echo $_SESSION[sessionid]; ?>" >
Course:<font color=red size=4><strong>*</strong></font>
<select name="course" class="form-control" onchange="loadsubject(course.value,semester.value)">
<option value="">Select Course</option>
<?php
$sqlcourse = "SELECT * FROM course WHERE status=Active";
$qsqlcourse = mysqli_query($con,$sqlcourse);
while($rscourse = mysqli_fetch_array($qsqlcourse))
{
if($rscourse[course_id] == $rsedit[course_id])
{
echo "<option value=$rscourse[course_id] selected>$rscourse[course]</option>";
}
else
{
echo "<option value=$rscourse[course_id]>$rscourse[course]</option>";
}
}
?>
</select>
<span id="idcourse"></span>
<br />
Semester:<font color=red size=4><strong>*</strong></font>
<select name="semester" class="form-control" onchange="loadsubject(course.value,semester.value)">
<option value="">Select semester</option>
<?php
$arr = array("First Semester","Second Semester","Third Semester","Fourth Semester","Fifth Semester","Sixth Semester");
foreach($arr as $val)
{
if($val == $rsedit[semester])
{
echo "<option value=$val selected>$val</option>";
}
else
{
echo "<option value=$val>$val</option>";
}
}
?>
</select>
<span id="idsemester"></span>
<br />
<span id="spansubjectid">
Subject:<font color=red size=4><strong>*</strong></font>
<select name="subject" class="form-control">
<option value="">Select Subject</option>
<?php
$sqlsubject = "SELECT * FROM subject WHERE subject_id=$rsedit[subject_id]";
$qsqlsubject = mysqli_query($con,$sqlsubject);
$rssubject = mysqli_fetch_array($qsqlsubject);
echo "<option value=$rssubject[subject_id] selected>$rssubject[subject]</option>";
?>
</select>
<span id="idsubject"></span>
</span>
<br />
Title:<font color=red size=4><strong>*</strong></font>
<input type="text" name="title" class="form-control" placeholder="Title *" value="<?php echo $rsedit[title]; ?>">
<span id="idtitle"></span>
<br />
Description:
<script src="richtexteditor/tinymce.min.js"></script>
<script>tinymce.init({ selector:textarea });</script>
<textarea name="description" class="form-control" cols="30" rows="10" placeholder="Description *"><?php echo $rsedit[description]; ?></textarea>
<br />
<input name="submit" type="submit" value="submit">
</form>
</div>
</div>
</div>
<?php include("rightsidebar.php"); ?>
</div>
</section>
<?php
include("footer.php")
?>
<script>
function loadsubject(courseid,semester) {
if (courseid == "")
{
document.getElementById("spansubjectid").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.open("GET","ajaxloadsubject.php?courseid="+courseid+"&semester="+semester,true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("spansubjectid").innerHTML = this.responseText;
}
};
}
}
</script>
<script type="application/javascript">
function validateform()
{
var alphaExp = /^[a-zA-Z]+$/; //Variable to validate only alphabets
var alphaspaceExp = /^[a-zA-Z\s]+$/; //Variable to validate only alphabets and space
var alphanumbericExp = /^[a-zA-Z0-9]+$/; //Variable to validate only alphabets and space
var numericExpression = /^[0-9]+$/; //Variable to validate only numbers
var validatecondtion = 0;
document.getElementById("idcourse").innerHTML ="";
document.getElementById("idsemester").innerHTML ="";
document.getElementById("idsubject").innerHTML ="";
document.getElementById("idtitle").innerHTML ="";
if(document.frmquiz.course.value=="")
{
document.getElementById("idcourse").innerHTML ="<font color=red>Kindly select Course..</font>";
validatecondtion=1;
}
if(document.frmquiz.semester.value=="")
{
document.getElementById("idsemester").innerHTML ="<font color=red>Kindly select Semester..</font>";
validatecondtion=1;
}
if(document.frmquiz.subject.value=="")
{
document.getElementById("idsubject").innerHTML ="<font color=red>Kindly select Subject..</font>";
validatecondtion=1;
}
if(document.frmquiz.title.value=="")
{
document.getElementById("idtitle").innerHTML ="<font color=red>Title must not be empty..</font>";
validatecondtion=1;
}
if(validatecondtion==1)
{
return false;
}
else
{
return true;
}
}
</script>