You are on page 1of 8

check.

php
<?php
include("connect.php");
$QID=$_POST['QID'];
$ans=$_POST['answer'];
$items=$_POST['items'];
$score=0;
if(is_array($QID)){
foreach($QID as $key => $QIDS){
$res=mysql_query("Select answer from tbl_question where QID='$QIDS'");
$row=mysql_fetch_assoc($res);
$correctAns=$row['answer'];
$studAns=$ans[$key];
if($correctAns==$studAns){
$score=$score+1;
}
else{
$score=$score;
}
}
}
$grade=($score/$items)*50+50;
?>
<html>
<body>
<h1> Assessment Result </h1>
Score: <?php echo $score; ?> <p>
Grade: <?php echo $grade; ?>
</body>
</html>

take_ass.php
<?php
include("connect.php");
$aid=$_POST['assTake'];
$sid=$_POST['sid'];
//deactivate student assessment
mysql_query("UPDATE tbl_active_assessment SET AssStatus='Inactive' WHERE
SID='$sid' AND AID='$aid'");
$resA=mysql_query("Select * from tbl_assessment where AID=$aid");
$rowA=mysql_fetch_assoc($resA);
echo "Topic: ".$rowA['topic'];
echo "<br>";
echo "Number of Items: ".$rowA['items'];
echo "<br>";
echo "Instruction: ".$rowA['instruction'];
echo "<p />";
?>
<form method="POST" action="check.php">
<?php $resB=mysql_query("Select * from tbl_assess_detail where AID=$aid");
$num=1;
while($rowB=mysql_fetch_assoc($resB)){
$QID=$rowB['QID'];
?>
<input type="hidden" value="<?php echo $QID; ?>" name="QID[]">
<input type="hidden" value="<?php echo $rowA['items']; ?>"
name="items">
<?php
$resC=mysql_query("Select qStatement from tbl_question where
QID=$QID limit 1");
$rowC=mysql_fetch_assoc($resC);
echo $num.".) ";
echo $rowC['qStatement'];

echo "<br>";
$resD=mysql_query("Select * from tbl_question_choices where
QID=$QID ORDER BY letter_choices ASC");
while($rowD=mysql_fetch_assoc($resD)){ ?>
<input type="radio" value="<?php echo $rowD['letter_choices']; ?
>" name="answer[]<?php echo $QID; ?>">
<?php echo $rowD['letter_choices'];
echo ".";
echo $rowD['choices_statement'];
echo "<br>";
}
$num++;
echo "<p>";
}
?>
<input type="submit" value="Submit">
</form>

active_ass.php

<?php
include("connect.php");
$AID=$_POST['alist'];
mysql_query("Delete from tbl_active_assessment where AID='$AID'"); //delete previous
activation assessment para wlay duplication
$r=mysql_query("Select * from tbl_user where user_type=2");

//get all student

while($row=mysql_fetch_assoc($r)){
$uid=$row['UID'];
mysql_query("Insert into tbl_active_assessment values($AID,$uid,'active')"); //set
exam activation for all student
}
?>
<html>
<head>
<title> Activate Assesment </title>
<head>
<body>
Successfully Activated!
</body>
</html>

student.php

<?php
include("connect.php");
if(isset($_GET['UID'])){
$sid=$_GET['UID'];
$res=mysql_query("Select * from tbl_active_assessment, tbl_assessment where
tbl_active_assessment.AID=tbl_assessment.AID AND SID=$sid AND
AssStatus='active'");
if (mysql_num_rows($res)==0){
echo 'No Active Assessment!';
}else{
?>

<form method="POST" action="take_ass.php">


<p>
<h1> Activated Assessment </h1>
</p>
<input type="hidden" value="<?php echo $sid; ?>" name="sid">
<?php while($row=mysql_fetch_assoc($res)) { ?>
<input type="radio" value="<?php echo $row['AID'];?>"
name="assTake" /> <?php echo $row['topic']; ?> <br><br>
<?php } ?>
<input type="submit" value="Take Assessment">
<?php }
}
?>
</html>

teacher.php

<?php
include("connect.php");
$res=mysql_query("Select * from tbl_assessment");
?>
<html>
<head>
<title> Teacher Page </title>
</head>
<body>
<h1> Assessment List </h1>
<form method="POST" action="active_ass.php" >
<?php while($row=mysql_fetch_assoc($res)) { ?>
<input type="radio" value="<?php echo $row['AID']; ?>" name="alist"> <?php echo
$row['topic']; ?> <br>
<?php } ?> <br>
<input type="submit" value="activate">
</form>
<body>
</html>

login.php

<?php
include("connect.php");
$uname=$_POST['username'];
$passwd=$_POST['password'];
$result=mysql_query("SELECT * from tbl_user WHERE username='$uname' limit 1");
//check if username exist
if (mysql_num_rows($result)==0){
header("Location:index.php?error=UNF");
}
else{
$row=mysql_fetch_assoc($result);
$pswd=$row['password'];
//check the passwd if ngmatch sa gi.enter ug sa tbl_user pass
if($pswd!=$passwd){
header("Location:index.php?error=IP");
}
else if($row['user_type']==1){
header("Location:teacher.php");
}
else if($row['user_type']==2){
header("Location:student.php?UID=".$row['UID']);
}
}
?>

index.php

<?php
if (isset($_GET['error'])){
$er=$_GET['error'];
if($er=="UNF"){
$message='User Not Found!';
}
if($er=="IP"){
$message='Invalid Password!';
}
}
else $message='';
?>

<html>
<head>
<title> E-Learning </title>
</head>
<body>
<h1> Welcome </h1>
<form method="POST" action="login.php">
<?php echo $message; ?> <br><br>
username: <input type="text" name="username" id="username"> <br><br>
password: <input type="password" name="password" id="password"> <br><br>
<input type="submit" value="Login">
</form>
</body>
</html>

You might also like