<? include("../settings.php"); ?>
<? include("session.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Abstract Submission Portal</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Include all CSS/JS -->
        <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/jquery.dataTables.css" rel="stylesheet">
    <link href="https://cdn.datatables.net/responsive/1.0.1/css/dataTables.responsive.css" rel="stylesheet">
    <style>
    #tooltip
    {
        text-align: center;
        color: #fff;
        background: #111;
        position: absolute;
        z-index: 100;
        padding: 15px;
    }
 
    #tooltip:after /* triangle decoration */
    {
        width: 0;
        height: 0;
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-top: 10px solid #111;
        content: '';
        position: absolute;
        left: 50%;
        bottom: -10px;
        margin-left: -10px;
    }
 
        #tooltip.top:after
        {
            border-top-color: transparent;
            border-bottom: 10px solid #111;
            top: -20px;
            bottom: auto;
        }
 
        #tooltip.left:after
        {
            left: 10px;
            margin: 0;
        }
 
        #tooltip.right:after
        {
            right: 10px;
            left: auto;
            margin: 0;
        }
    </style>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-2.1.1.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/responsive/1.0.1/js/dataTables.responsive.js"></script>

    <!-- End of all CSS/JS -->

	<script>
		
		function selectTopic(){
			$('#reviewer').submit() ;
		}
    </script>
   </head>
<body>


<? include("nav_menu.php"); ?>
      <div class="well">
<div class="content" bgcolor="#FFFFD0">
<div class="col-12 feature">
<div class="panelCheck">
    <div class="panel-heading">
        <h3 class "panel-title"><strong>Reviewer Summary</strong></h3>
    </div>

    <form name="reviewer" method='POST' action="" enctype="multipart/form-data" class="form-horizontal" role="form" id="reviewer">
   
	<?
		$output = "<select name='topic_id' onchange='selectTopic();' class='form-control'><option value='0'>Please select</option>";
		if ($_SESSION['user_admin']=='1'){
			$results = $db->select("tbl_topic");
			foreach($results as $result){
				$output = $output."<option value='".$result['topic_id']."'>".$result['topic_name']."</option>"; 
			}
		}else{
			$bind = array(
				":search1"=>$_SESSION['user_id']
			);
			$results = $db->select("tbl_topic as a, tbl_topic_user as b","b.topic_id = a.topic_id AND b.user_id = :search1",$bind);
			foreach ($results as $result){
				$output = $output."<option value='".$result['topic_id']."'>".$result['topic_name']."</option>"; 
			}
		}
		$output = $output."<select name='topic_id'>";
	?>
    Topic : <?=$output;?><br/>
	<?
		if (isset($_REQUEST['topic_id']) || $_REQUEST['topic_id']!=0){
			$papers = $db->run("SELECT COUNT(*) as total FROM tbl_abstract WHERE abstract_deleted = 0 AND topic_id = '".$_REQUEST['topic_id']."'");
			$papertotal = $papers[0]['total'];
		}else{
			$papertotal = 0;
		}
	?>
	Total number of papers : <?=$papertotal;?></br>
	<?
		if (isset($_REQUEST['topic_id']) || $_REQUEST['topic_id']!=0){
			$reviews = $db->run("SELECT COUNT(*) as total FROM tbl_topic_user as a, tbl_abstract_user as b WHERE a.topic_id = '".$_REQUEST['topic_id']."' AND a.user_id = b.user_id AND b.user_principle = 0");
			$reviewertotal = $reviews[0]['total'];
		}else{
			$reviewertotal = 0;
		}
		$reviewersassigneds = $db->run("SELECT count(*) as total FROM tbl_abstract as a, tbl_abstract_review as b where b.abstract_id = a.abstract_id AND a.topic_id = '".$_REQUEST['topic_id']."'");
		$reviewersassigned=$reviewersassigneds[0]['total'];
	?>
	Total number of reviewers assigned : <?=$reviewersassigned;?>/<?=$papertotal*4;?></br>
	<?
		$jobsdone = $db->run("select abstract_user_id,count(*) as grandtotal from tbl_topic_user as a, tbl_review as b, tbl_abstract as c where a.topic_id='".$_REQUEST['topic_id']."' AND a.topic_id=c.topic_id AND b.abstract_id = c.abstract_id AND a.user_id=b.abstract_user_id group by abstract_user_id having grandtotal>5");
		$completedreviews=count($jobsdone);
	?>
    Total number of reviewers who have completed all 6 reviews: <?=$completedreviews;?></br>  
    <?
		if (isset($_REQUEST['topic_id']) || $_REQUEST['topic_id']!=0){
			echo "<table id='myTable' class='table table-striped table-hover' cellspacing='0' width='100%'><thead><tr><th>#</th><th>Reviewer</th><th>Number of Assigned Papers</th><th>Number of Reviewed Papers</th><th>Number of Unreviewed Papers</th></tr></thead>";
			echo "<tbody>";
			$bind = array(
				":search1" => $_REQUEST['topic_id']
			);
			$topics = $db->select("tbl_topic","topic_id = :search1",$bind);
			$topic = $topics[0]['topic_name'];
			echo "<b>TOPIC : $topic</b><br/><br/>";
			
			$results = $db->select("tbl_topic_user as a, tbl_abstract_user as b","a.topic_id=:search1 AND a.user_id=b.user_id AND b.user_admin = 0 AND b.user_principle = 0",$bind);
			$i=1;
			foreach ($results as $result){
				$assignedtotals = $db->run("SELECT COUNT(*) as total FROM tbl_abstract as a, tbl_abstract_review as b WHERE b.user_id = '".$result['user_id']."' AND b.abstract_id = a.abstract_id AND a.abstract_deleted=0");
				$assignedtotal = $assignedtotals[0]['total'];
				$reviewedtotals = $db->run("SELECT COUNT(*) as total FROM tbl_abstract as a, tbl_review as b WHERE b.abstract_user_id = '".$result['user_id']."' AND b.abstract_id = a.abstract_id AND a.abstract_deleted=0");
				$reviewedtotal = $reviewedtotals[0]['total'];
				$unreviewed = $assignedtotal - $reviewedtotal;
				if ($unreviewed==0)
					$class = "success";
				else
					$class = "Info";
				echo "<tr class='$class'><td>$i</td><td>".$result['user_name']."</td><td>".$assignedtotal."</td><td>".$reviewedtotal."</td><td>".$unreviewed."</td></tr>";
				$i++;
			}
			echo "</tbody></table>";
		}
	?>
    </form>

</div>
</div>
</div>
</div>
</body>
</html>