Your IP : 216.73.216.40


Current Path : /var/www/html/rkala/data/
Upload File :
Current File : /var/www/html/rkala/data/process.php

<?php
// Setting for the re-evaluation phase..
$second_phase = 0;

session_start();
include 'credential.php';

if(!isset($_SESSION['encrpy']) || !isset($_SESSION['user']) || $_SESSION['encrpy'] != md5($_SESSION['user']."unbreakabelcipehre")) {
	// user is not logged in, do something like redirect to login.php
	header("Location: logon.php");
	die();
}

if($_SESSION['access'] != 1) {
	// another example...
	// user is logged in but not a manager, let's stop him
	die("Access Denied");
}
?>
<?php
function mean($array){
	if(count($array) == 0){
		return 0;
	}
	return array_sum($array)/count($array);
}
// Function to calculate square of value - mean
function sd_square($x, $mean) { return pow($x - $mean,2); }

// Function to calculate standard deviation (uses sd_square)    
function sd($array) {
    // square root of sum of squares devided by N-1
	if(count($array) <= 1){
		return 0;
	}
    return sqrt(array_sum(array_map("sd_square", $array, array_fill(0,count($array), (array_sum($array) / count($array)) ) ) ) / (count($array)-1) );
}
?>
<?php
	$ta = $_SESSION['user'];
	$ta = explode(',', $ta);
	parse_str($ta[0]);

	// start : for each questions
		// search in correction_ta with each ta_id and ques_id for stud_id
			// get 'n' marks with peer_id (stud_id) and ques_id
				// compute and classify it
	
	$main_array = array();
	
	$con = @mysqli_connect($host, $user, $pass, $db);
	if (@mysqli_connect_errno()){
		echo "<script> alert('Server is Offline. Please try again later.'); window.location.href = 'logon.php';</script>";
		die();
	}
	//$uid = '*';
	$query = "Select q_id from question";
	$result = @mysqli_query($con, $query);
	$count = 0;
	while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
		$quest_id = $row['q_id'];
		
		$query = "Select stud_id, ta_id from correction_ta where ta_id = '$uid' and question_id = $quest_id";
		if($uid == 'rkala')
			$query = "Select stud_id, ta_id from correction_ta where question_id = $quest_id";
		
		$result_2 = @mysqli_query($con, $query) or die(mysqli_error());
		while($row_2 = mysqli_fetch_array($result_2, MYSQLI_ASSOC)){
			$stud_id = $row_2['stud_id'];
			$taa_id = $row_2['ta_id'];
			
			$array_marks = array();
			$query = "Select marks from allocation where peer_id = '$stud_id' and question_id = $quest_id and blur is not null and blur <> 1";
			$result_3 = @mysqli_query($con, $query) or die(mysqli_error());
			while($row_3 = mysqli_fetch_array($result_3, MYSQLI_ASSOC)){
				$marks = $row_3['marks'];
				
				array_push($array_marks, $marks);
			}
			
			$query = "Select marks from correction_ta where ta_id = '$uid' and stud_id = '$stud_id' and question_id = $quest_id";
			
			if($uid == 'rkala')
				$query = "Select marks from correction_ta where stud_id = '$stud_id' and question_id = $quest_id";
			
			$result_3 = @mysqli_query($con, $query) or die(mysqli_error());
			$ta_mark = 0;
			while($row_3 = mysqli_fetch_array($result_3)){
				$ta_mark = $row_3['marks'];
			}			
			
			/**************/
			// get self evaluated score
			$self_marks = 0;
			$self_marking = -1;
			$query = "select self_marks from evaluation_purpose_table where ques_id = $quest_id and stud_id = '$stud_id'";
			$result_3 = @mysqli_query($con, $query) or die(mysqli_error());
			while($row_3 = mysqli_fetch_array($result_3, MYSQLI_ASSOC)){
				$self_marks = $row_3['self_marks'];
				$self_marking = $row_3['self_marks'];
			}
			if($self_marking == -1){
				array_push($array_marks, $ta_mark);
			}else{
				array_push($array_marks, $self_marks);
			}
			
			// find threshold
			$threshold = 0;
			$query = "select threshold from question where q_id = $quest_id";
			$result_3 = @mysqli_query($con, $query) or die(mysqli_error());
			while($row_3 = mysqli_fetch_array($result_3, MYSQLI_ASSOC)){
				$threshold = $row_3['threshold'];
			}
			
			// sort the array
			sort($array_marks);
			
			// find median and get min and max value using thres // find number of evaluation lying inside ranges
			$weight = 0;
			$median = 0;
			$arrlength = count($array_marks);
			if ($arrlength%2 == 0){
				$median = ($array_marks[$arrlength/2] + $array_marks[($arrlength/2) - 1])/2.0;
			}else{
				$median = $array_marks[($arrlength/2)];
			}
			for($x = 0; $x < $arrlength; $x++) {
				$weight += 1;
				if (($array_marks[$x] > ($median+$threshold)) && ($array_marks[$x] < ($median-$threshold))){
					$weight += 0;
				}
			}
			$display = 1;
			//echo $stud_id . "<br>" . $ta_mark. "<br>" . $median . "<br>" . $threshold. "<br>" . $quest_id . "<br><br>";
			if (($ta_mark >= ($median-$threshold)) && ($ta_mark <= ($median+$threshold))){
					$display = 0;
			}
			
			
			/**************/
			
			// Weighted factor for generating error
			//$factor = 0.25*sd($array_marks) + 0.75*abs(mean($array_marks) - $ta_mark);
			$factor = $weight;
			
			if($second_phase == 1){
				if($display == 1){
					$temp_array = array($factor, $quest_id, $stud_id, $taa_id, $self_marking);
					array_push($main_array, $temp_array);
				}
			}else{			
				if($uid == 'rkala' or $display == 1){
					$temp_array = array($factor, $quest_id, $stud_id, $taa_id, $self_marking);
					array_push($main_array, $temp_array);
				}
			}
			/*
			// Weighted factor for generating error
			$factor = 0.25*sd($array_marks) + 0.75*abs(mean($array_marks) - $ta_mark);

			$temp_array = array($factor, $quest_id, $stud_id, $taa_id);
			array_push($main_array, $temp_array);
			*/
		}
	}
	mysqli_free_result($result);
	mysqli_close($con);
	
	foreach ($main_array as $key => $row) {
		// replace 0 with the field's index/key
		$dates[$key]  = $row[0];
	}
	if(count($main_array) > 0){
		array_multisort($dates, SORT_DESC, $main_array);
	}
	
	// To visualize the sorting action
	/*
	for ($row = 0; $row < count($main_array); $row++) {
	  echo "<p><b>Row number $row</b></p>";
	  echo "<ul>";
	  for ($col = 0; $col < count($main_array[0]); $col++) {
		echo "<li>".$main_array[$row][$col]."</li>";
	  }
	  echo "</ul>";
	}
	*/
?>

<html>
		<script src="js/jquery-2.1.3.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> 
		
		<script>
			function w3_open() {
				document.getElementById("mySidebar").style.display = "block";
			}
			function w3_close() {
				document.getElementById("mySidebar").style.display = "none";
			}
		</script>
	<style>
		h4{
		      background-color: #fff;
		      color:white !important;
		      text-align: right;
			  padding-right : 50px;
		      font-size: 20px;
		  }
		 h2{
		      background-color: #eee;
		      color:white !important;
		      text-align: right;
			  padding-right : 50px;
		      font-size: 20px;
		  }
		table, th, td {
			border: 2px solid black;
			border-collapse: collapse;
			-moz-border-radius: 4px;
			-webkit-border-radius: 4px;
			border-collapse:separate;
			border-radius: 4px;			
		}
		th, td {
			padding: 5px;
			text-align: center;
		}
		table#t01 tr:nth-child(even) {
			background-color: #ded;
		}
		table#t01 tr:nth-child(odd) {
		   background-color:#fff;
		}
		table#t01 th {
			background-color: black;
			text-align: center;	
			color: white;
		}
	</style>
	<title>Report</title>
	<body>
	
		<!-- Sidebar -->
		<div class="w3-sidebar w3-large w3-bar-block w3-border-right w3-animate-left" style="display:none" id="mySidebar">
		  <button onclick="w3_close()" class="w3-bar-item w3-large">Close &times;</button>
		  <a href="ta.php" class="w3-bar-item w3-button">User</a>
		  <a href="student_insert.php" class="w3-bar-item w3-button">Scanning</a>
		  <a href="#" target="_blank" class="w3-bar-item w3-button">Re-Evaluation</a>
		  <a href="logon.php?out" class="w3-bar-item w3-button">Logout</a>
		</div>
		
		<div class="w3-teal">
			<button class="w3-button w3-teal w3-xlarge" onclick="w3_open()">&#9776;</button>
			<h1 align="center">
				Students
			</h1>
		</div>

		<h3>
			<table align="center"  id="t01" style="width:50%">
				<tr> <th>Roll</th><th>TA</th> <th>Question</th><th>Evaluation_count</th><th>Self-marks</th></tr>
			<?php
				$i = 0;
				while($i < count($main_array)){   //Creates a loop to loop through results
					//echo $i. " : " . $row[0];
					echo "<tr> <td><a onclick=\"window.open('re_eval.php?roll=".$main_array[$i][2]."&quest=".$main_array[$i][1]."', 'newwindow', 'width=500, height=550'); return false;\" href = '#'>". $main_array[$i][2]. "</a></td><td>" . $main_array[$i][3] . "</td><td>" . $main_array[$i][1] . "</td><td>" . $main_array[$i][0] . "</td><td>" . $main_array[$i][4] . "</td></tr>";
					$i += 1;
			?>
				
			<?php
				}
			?>
			</table>
		</h3>
	</body>
</html>