Your IP : 216.73.216.40


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

<?php
session_start();

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

if($_SESSION['access'] != 2) {
	// another example...
	// user is logged in but not a manager, let's stop him
	die("Access Denied");
}

?>
<html>
	<script type="text/javascript">
			function reloadFunction() {
				location.reload();
			}
			function w3_open() {
				document.getElementById("mySidebar").style.display = "block";
			}
			function w3_close() {
				document.getElementById("mySidebar").style.display = "none";
			}
	</script>
	<head>
		<style>
			#myImg {
			    border-radius: 5px;
			    cursor: pointer;
			    transition: 0.3s;
			}
			
			#myImg:hover {opacity: 0.7;}

			/* The Modal (background) */
			.modal {
			    display: none; /* Hidden by default */
			    position: fixed; /* Stay in place */
			    z-index: 1; /* Sit on top */
			    padding-top: 100px; /* Location of the box */
			    left: 0;
			    top: 0;
			    width: 100%; /* Full width */
			    height: 100%; /* Full height */
			    overflow: auto; /* Enable scroll if needed */
			    background-color: rgb(0,0,0); /* Fallback color */
			    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
			}

			/* Modal Content (image) */
			.modal-content {
			    margin: auto;
			    display: block;
			    width: 200%;
			    max-width:700px;
			}

			/* Caption of Modal Image */
			#caption {
			    margin: auto;
			    display: block;
			    width: 80%;
			    max-width: 700px;
			    text-align: center;
			    color: #ccc;
			    padding: 10px 0;
			    height: 150px;
			}

			/* Add Animation */
			.modal-content, #caption {  			 
			    -webkit-animation-name: zoom;
			    -webkit-animation-duration: 0.6s;
			    animation-name: zoom;
			    animation-duration: 0.6s;
			}

			@-webkit-keyframes zoom {
			    from {-webkit-transform:scale(0)} 
			    to {-webkit-transform:scale(1)}
			}

			@keyframes zoom {
			    from {transform:scale(0)} 
			    to {transform:scale(1)}
			}

			.rotate90 {
			    -webkit-transform: rotate(90deg);
			    -moz-transform: rotate(90deg);
			    -o-transform: rotate(90deg);
			    -ms-transform: rotate(90deg);
			    transform: rotate(90deg);
			}

			/* The Close Button */
			.close {
			    position: absolute;
			    top: 15px;
			    right: 35px;
			    color: #f1f1f1;
			    font-size: 40px;
			    font-weight: bold;
			    transition: 0.3s;
			}

			.close:hover,
			.close:focus {
			    color: #bbb;
			    text-decoration: none;
			    cursor: pointer;
			}

			/* 100% Image Width on Smaller Screens */
			@media only screen and (max-width: 700px){
			    .modal-content {
				width: 100%;
			    }
			}
		</style>	
				
		<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"> 
		
		  <style>
			table, th, td {
				border: 0px 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#t02 {
				border: 2px solid black;
			}
			table#t01 tr:nth-child(even) {
				background-color: #ded;
			}
			table#t01 tr:nth-child(odd) {
			   background-color:#fff;
			}
			table#t01 th {
				background-color: black;
				color: white;
			}
		  .modal-header, h4, .close {
		      background-color: #5cb85c;
		      color:white !important;
		      text-align: center;
		      font-size: 30px;
		  }
		  h2{
		      background-color: #eee;
		      color:white !important;
		      text-align: right;
			  padding-right : 50px;
		      font-size: 20px;
		  }
		  .modal-footer {
		      background-color: #f9f9f9;
		  }
		  </style>		  	
		<script type="text/javascript">
			$(document).ready(function (e) {
				$("[id^=input_form]").on('submit',(function(e) {
					e.preventDefault();
					$.ajax({
						url: "tester/sam10.php",
						type: "POST",
						data:  new FormData(this),
						contentType: false,
			    	    		cache: false,
						processData:false,
						timeout:15000,
						beforeSend: function()
						{
							$("#targetLayer").html("Fetching");	
						},
						success: function(data)
						{
						$("#targetLayer").html(data);
						},
					  	error: function() 
						{
						$("#targetLayer").html("ERROR");
						}	        
				   	});
				}));
			});
		</script>
	</head>
	<title>Evaluation Board</title>
	<body class = "w3-light-gray">
	
		<!-- 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="student.php?roll=<?php echo $_GET['roll']; ?>" class="w3-bar-item w3-button">Student</a>
		  <a href="#" class="w3-bar-item w3-button">Evaluation</a>
		  <a href="#" class="w3-bar-item w3-button">Verification</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">
			Evaluation Board
		</h1>
		</div>
		<h3  align="center">
			<form id="input_form" action="login.php" method="POST">
			<p><b><?php echo $_GET['roll']; ?></b></p>
			<div align = "center">
				<table id = "t01" width="75%" class="w3-card-4 w3-section">
				<tr><th colspan=14>Question Availability for Evaluation</th><tr>
				<tr><th>1: 1(a)</th><th>2: 1(b)</th><th>3: 2</th><th>4: 3(a)</th><th>5: 3(b)</th><th>6: 4(a)</th><th>7: 4(b)</th><th>8: 5(a)</th><th>9: 5(b)</th><th>10: 6</th><th>11: 7</th><th>12: 8</th><th>13: 9</th><th>14: 10</th></tr>
				<tr>
				<?php
				include_once 'credential.php';
				
				$con = new mysqli($host, $user, $pass, $db);
				check($con);
				$variable = $_GET['roll'];
						for ($x = 1; $x <= 14; $x++) {
							/********************/
							if($stmt = $con->prepare('select count(*) from evaluation_purpose_table where stud_id <> ? and ques_id = ?')){
								$stmt->bind_param('si',$variable,$x);
								if($stmt->execute()){
									$result_rand = get_result($stmt);
									$row_rand = array_shift($result_rand);
									$max_count = $row_rand['count(*)'];
								}
							}
							//echo $max_count;
							/*******************/
							
							///******************** **** Changes 28-04-2018 /
							$answer_done_count = 0;
							if($stmt = $con->prepare('select count(*) from allocation where peer_id <> ? and question_id = ? and marks is not null')){
								$stmt->bind_param('si',$variable,$x);
								if($stmt->execute()){
									$result_rand = get_result($stmt);
									$row_rand = array_shift($result_rand);
									$answer_done_count = $row_rand['count(*)'];
								}
							}
							if($x < 10){
								$max_count = $max_count * 3;
							}
							$percent = (int)((1 - ($answer_done_count/$max_count))*100.0);
							if ($percent < 0){
								$percent = 0;
							}
							$percent = 100;
							echo "<td>" . $percent . "% </td>";
						}
				?>
				</tr>
				</table>
			</div>
			<input name="roll" type = "hidden" value="<?php echo $_GET['roll']; ?>"/>
			<select name = "question">
			<?php
				
				$salt = "fwkirtm452%2wkf#773&D";
				
				$variable = $_GET['roll'];
				$variable = test_input($variable);
				
				
				$chk_question = false;
				
				$seed = 0;
				$max_count = 0;
				if($stmt = $con->prepare('select seed from student where id = ?')){
					$stmt->bind_param('s',$variable);
					if($stmt->execute()){
						$result = get_result($stmt);
						$row = array_shift($result);
						$seed = $row['seed'];
					}
				}
				
				
				if($stmt = $con->prepare('select distinct(ques_id) from evaluation_purpose_table where stud_id = ?')){
					$stmt->bind_param('s',$variable);
					if($stmt->execute()){
						$result = get_result($stmt);
						$i = 0;
						
						while($row = array_shift($result)){
							// Got the question num in $row['ques_id']
							// select stud_id, weight from evaluation_purpose_table where stud_id <> $variable limit seed, 1
							// if tuple(stud_id, question_id, peer_id) in allocation, then increment seed in loop.
							// else random() < 1/weight, then insert (peer_id, question_id, stud_id) in allocation, and update seed, and send peer_id next.
							//echo "$row[0]";
							$question_id = $row['ques_id'];
							
							/********************/
							if($stmt = $con->prepare('select count(*) from evaluation_purpose_table where stud_id <> ? and ques_id = ?')){
								$stmt->bind_param('si',$variable,$question_id);
								if($stmt->execute()){
									$result_rand = get_result($stmt);
									$row_rand = array_shift($result_rand);
									$max_count = $row_rand['count(*)'];
								}
							}
							//echo $max_count;
							/*******************/
							
							///******************** **** Changes 28-04-2018 /
							$answer_done_count = 0;
							if($stmt = $con->prepare('select count(*) from allocation where peer_id <> ? and question_id = ? and marks is not null')){
								$stmt->bind_param('si',$variable,$question_id);
								if($stmt->execute()){
									$result_rand = get_result($stmt);
									$row_rand = array_shift($result_rand);
									$answer_done_count = $row_rand['count(*)'];
								}
							}
							//echo $max_count . "  " . $answer_done_count;
							///******************* **** Changes 28-04-2018/
							
							//*************** **** Changes 28-04-2018 /
							if(($answer_done_count >= $max_count && $question_id >= 10) || ($answer_done_count >= 3*$max_count && $question_id < 10)){
								//continue;
							}
							//*************** **** Changes 28-04-2018 /
							
							
							while(1){
								$seed = mt_rand(1,$max_count-1); //1 + $seed % $max_count;	
								#echo "Seed value" + $seed + "\n";
								if($stmt = $con->prepare('select stud_id, weight from evaluation_purpose_table where stud_id <> ? and ques_id = ? limit ?, 1')){
									$stmt->bind_param('sss',$variable, $question_id, $seed);
									if($stmt->execute()){
										$result2 = get_result($stmt);
										$row2 = array_shift($result2);
										//echo $row2['stud_id'];
										if($stmt = $con->prepare('select count(*), marks, comment from allocation where peer_id = ? and stud_id = ? and question_id = ?')){
											$stmt->bind_param('sss',$row2['stud_id'], $variable, $question_id);
											if($stmt->execute()){
												$result3 = get_result($stmt);
												$row3 = array_shift($result3);
												if ($row3['marks'] != NULL && $row3['comment'] != NULL){
													$seed += 1;
												}else{
													$seed += 1;
													$random_value = mt_rand() / mt_getrandmax();
													if($random_value <= (1.0/(1.0 + $row2['weight']))){
													
													// **** Changes 28-04-2018
													//if(($row2['weight'] < 1 && $question_id >= 10) || ($row2['weight'] < 3 && $question_id < 10)){
													
													// **** Changes 28-04-2018
													
														// insert/update tuple
														// update seed
														
														/**********************/
														if ($row3['count(*)'] == 0){
															$stmt = $con -> prepare('Insert into allocation (stud_id, question_id, peer_id) values (?, ? ,? )');
															$stmt->bind_param('sis',  strtoupper($variable), $question_id, $row2['stud_id']);
															if($stmt->execute()){
																$peer_id_f = $row2['stud_id'];
																//echo $row2['stud_id'];
																$seed += rand(1, 10) ;
																$seed = $seed % $max_count;
																$stmt = $con -> prepare('UPDATE student SET seed = ? WHERE id = ?');
																$stmt->bind_param('is',  $seed, strtoupper($variable));
																$stmt->execute();
															}else{
																echo "Failed to Load";
															}														
														}else{
															$peer_id_f = $row2['stud_id'];
															$seed += rand(1, 10) ;
															$seed = $seed % $max_count;
															$stmt = $con -> prepare('UPDATE student SET seed = ? WHERE id = ?');
															$stmt->bind_param('is',  $seed, strtoupper($variable));
															$stmt->execute();															
														}

														/**********************/
														break;
													}
												}
											}
										}
										
									}
								}
							}
							
							$i += 1;
							$algos = hash_algos();
							if (in_array("sha256", $algos)) {
								$hid_val = hash ("sha256", $peer_id_f . $salt);
							}else{
								echo "something Went wrong";
							}
							$hid_val = $hid_val . "|" . $question_id;							
							echo "<option value=\"". $hid_val . "\">". $question_id ."</option>";
							$chk_question = true;
						}
					}
					$con->close();
				}
			?>
			</select>
			<?php
			if($chk_question == true){
			?>
				<input type="submit" value="Display Question" class="btnSubmit" /><button onclick="reloadFunction()">Go to Next Set</button><br>
				
			<?php
			}else{
				echo "<input type=\"button\" value=\"No Questions\"/>";
			}
			?>
			</form>
		</h3>
		
		<div id="targetLayer" class="w3-margin">
		
		</div>
		<!-- <img id="myImg" src="tester/images/lion.jpg" alt="Trolltunga, Norway" width="300" height="200"> -->
		
		<div id="myModal" class="modal fade" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content" >
				    <div class="modal-body" >
				        <img class="img-responsive" src=""/>
				    </div>
				    <div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			       	</div>
		 		</div>
		 	</div>
		</div>				
		
	</body>
</html>