<?php
$score_ID = $_GET['score_ID'];
if ($score_ID=="") {
	$score_ID = 1;
}
$view = $_GET['view'];
$r=$_GET['r'];
$q=$_GET['q'];
$p=$_GET['p'];
if ($p=="n5") {
	$p = "-5";
}
$value=$_GET['value'];
$yn=$_GET['yn'];
$m=$_GET['m'];
if ($view=="") {
	$view = "survey";
}
$feud_scoring = $_COOKIE['feud_scoring'];
//include_once("logged_in.php");
$gamehost = $_SERVER['HTTP_HOST'];	
if ($gamehost == "localhost") {
	include 'conn_my_local.php';
}
else {
	include 'conn_my_web.php';
}
include_once("logged_in.php");
if ($m=="undo") {
	$update = "update feud_scores set ".$r."_".$q." = 0, total_points = (total_points - ".$p.") where score_ID = ".$score_ID;
	//echo $update.'<br>';
	mysqli_query($my_conn, $update);
	$loc = "Location: feud_team_scoring.php?score_ID=".$score_ID."&r=".$r."&q=".$q;
	//echo $loc."<br>";
	header($loc);
}
elseif ($m=="submit") {
	$update = "update feud_scores set ".$r."_".$q." = ".$p.", total_points = (total_points + ".$p.") where score_ID = ".$score_ID;
	mysqli_query($my_conn, $update);
}
$query = "select teamname, total_points, aka from feud_scores where score_ID = ".$score_ID;
//echo $query."<br>";
$result = mysqli_query($my_conn, $query);
$row = mysqli_fetch_assoc($result);
$teamname = $row['teamname'];
$total_points = $row['total_points'];
$aka = $row['aka'];

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Team Feud</title>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <style>
    /* Remove the navbar's default margin-bottom and rounded borders */ 
	body {
		margin: 0;
		background-color: #f1f1f1;	
		font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
	}

  .scoring_text {
	font-size: 14px;
	clear: both;
	width: 520px;
	height: 25px;
	}

.team_name {
	float: left;
	width: 180px;
	color: #000;
	font-size: 21px;
}

.scoring_options {
	width: 340px;
	float: right;	
}
	  
	  .navbar {
      margin-bottom: 0;
      border-radius: 0;
	  background:#0a2853;
      height: 100px;
	}
    
    /* Set height of the grid so .sidenav can be 100% (adjust as needed) */
    .row.content {height: 450px}
    
    /* Set gray background color and 100% height */
    .sidenav {
      padding-top: 20px;
      background-color: #f1f1f1;
      height: 100%;
    }
    
    /* Set black background color, white text and some padding */
    footer {
      background-color: #555;
      color: white;
      padding: 15px;
    }
    
    /* On small screens, set height to 'auto' for sidenav and grid */
    @media screen and (max-width: 767px) {
      .sidenav {
        height: auto;
        padding: 15px;
      }
      .row.content {height:auto;} 
    }
	  
	  .buttona {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #4de33c;
		  color: #FFF;
		  margin-right: 5px;
	  }
	  .buttonb {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color:#40ce2f;
		  color: #FFF;
		  margin-right: 5px;		  
	  }	  
	  .buttonc {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color:#31be20;
		  color: #FFF;
		  margin-right: 5px;		  
	  }	  
	  .buttond {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #23af13;
		  color: #FFF;
		  margin-right: 5px;		  
	  }
	  
	  .buttone {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #159E05;
		  color: #FFF;
		  margin-right: 5px;		  
	  }
	  .buttonf {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #0f8801;
		  color: #FFF;
		  margin-right: 5px;		  
	  }	  
	  .buttonz {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #000;
		  color: #FFF;
		  margin-right: 5px;		  
	  }	  
	  .buttonn {
		  height: 40px;
		  width: 20px;
		  padding: 5px;
		  text-align: center;
		  background-color: #C0292B;
		  color: #FFF;
		  margin-right: 5px;		  
	  }	
		.border {
			border-left: 1px solid #000;
			border-right: 1px solid #000;
			border-top: 1px solid #000;
			border-bottom: 1px solid #000;			
		}	  
  </style>
  <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
  <script>
    function score(str) {
	if (str==""){
    	document.getElementById("total_points").value="";
    	return;
	}
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {// code for IE6, IE5
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
    	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        	var data = JSON.parse(xmlhttp.responseText);
        	for(var i=0;i<data.length;i++) {
          		document.getElementById("total_points").value = data[i].total_points;
        	}
    	}
	}
	xmlhttp.open("GET","feud_score_update.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&p="+str,true);
	xmlhttp.send();
}
	</script>
</head>

<body>
  
    <table width="510" cellpadding="0" cellspacing="0" border="0">
      <tr>
    <td width="260" max-width="160" style="width: 160px; max-width: 160px; font-size: 14px; color: #FFF;" class="border">
		&nbsp;&nbsp;<a href="feud_scoring_edit.php?m=edit&score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>" style="text-decoration: underline; color: #000; font-weight: bold;" target="feud_team_scoring_iframe"><?php echo substr($aka, 0, 15); ?></a>
		</td>		  
        
    <?php
    //check to see if there is a score for this question 1st
	$query = "select ".$r."_".$q." as 'current' from feud_scores where score_ID = ".$score_ID;
	//echo $query."<br>";
	$result = mysqli_query($my_conn, $query);
	$row = mysqli_fetch_assoc($result);
	$current = $row['current'];
	if ($current > 0) {
		echo '<td align="left" valign="center" class="border" height="36" style="font-size: 12px; height: 36px;">'.$current.' points Recorded.';
		echo '<a href="feud_team_scoring.php?score_ID='.$score_ID.'&r='.$r.'&q='.$q.'&m=undo&p='.$current.'">Undo</a></td>';
	}
	elseif ($m=="submit") {
		echo '<td align="left" valign="center" class="border"height="36" style="font-size: 12px; height: 36px;">'.$p.' points Recorded.';
		echo '<a href="feud_team_scoring.php?score_ID='.$score_ID.'&r='.$r.'&q='.$q.'&m=undo&p='.$p.'">Undo</a></td>';
	}
	elseif ($r==1 && $m!="submit") {
		if ($feud_scoring==1) {
	?>
	<td width="36" align="center" height="36" class="border">
		<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0">
			<img src="images/score_nums/feud_0.png">
		</a> 
	</td>
	<td width="36" align="center" height="36" class="border">		  
   	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=1"><img src="images/score_nums/feud_1.png"></a>
	</td>
	<td width="36" align="center" height="36" class="border">		  
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=2"><img src="images/score_nums/feud_2.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">		  		
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=3"><img src="images/score_nums/feud_3.png"></a> 
	</td>
	<?php		
		}
		else {
	?>
    <td width="36" align="center" height="36" class="border">		  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
   	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=1"><img src="images/score_nums/feud_1.png"></a>
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=2"><img src="images/score_nums/feud_2.png"></a>    
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=3"><img src="images/score_nums/feud_3.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=4"><img src="images/score_nums/feud_4.png"></a>
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=5"><img src="images/score_nums/feud_5.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a>
	</td>
	
    <?php
		}
	}
	elseif ($r==2 && $m!="submit") {
		if ($feud_scoring==1) {
	?>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 	
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=2"><img src="images/score_nums/feud_2.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=4"><img src="images/score_nums/feud_4.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a>	
		  </td>
	<?php		
		}
		else {
	?>
	<td width="36" align="center" height="36" class="border">			  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=2"><img src="images/score_nums/feud_2.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=4"><img src="images/score_nums/feud_4.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a>
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=8"><img src="images/score_nums/feud_8.png"></a>     
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=12"><img src="images/score_nums/feud_12.png"></a>
	</td>
    <?php
		}
    }
	elseif ($r==3 && $m!="submit") {
		if ($feud_scoring==1) {
	?>
	<td width="36" align="center" height="36" class="border">			  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 	
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=3"><img src="images/score_nums/feud_3.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=9"><img src="images/score_nums/feud_9.png"></a>	
	</td>		
	<?php		
		}
		else {
	?>
	<td width="36" align="center" height="36" class="border">			  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 	
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=3"><img src="images/score_nums/feud_3.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=9"><img src="images/score_nums/feud_9.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=12"><img src="images/score_nums/feud_12.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=15"><img src="images/score_nums/feud_15.png"></a>
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=18"><img src="images/score_nums/feud_18.png"></a>    
	</td>
    <?php
		}
	}
	elseif ($r=="B" && $m!="submit") {
	?>
	<td width="36" align="center" height="36" class="border">			  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 	
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=2"><img src="images/score_nums/feud_2.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=4"><img src="images/score_nums/feud_4.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=6"><img src="images/score_nums/feud_6.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=8"><img src="images/score_nums/feud_8.png"></a>
	</td>
    <?php
	}
	elseif ($r=="F" && $m!="submit") {
	?>
	<td width="36" align="center" height="36" class="border">			  
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=0"><img src="images/score_nums/feud_0.png"></a> 		
	</td>
	<td width="36" align="center" height="36" class="border">			
	<a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=10"><img src="images/score_nums/feud_+10.png"></a> 
	</td>
	<td width="36" align="center" height="36" class="border">			
    <a href="feud_team_scoring.php?score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&m=submit&p=n5"><img src="images/score_nums/feud_-5.png"></a> 
	</td>
    <?php
	}		
	?>     
		  </td>
		  <td width="50" class="border" align="center">
		  <?php echo $total_points; ?>
		  </td>
		  <td width="20" class="border" align="center">
            <a href="feud_scoring.php?m=dropteam&score_ID=<?php echo $score_ID; ?>&r=<?php echo $r; ?>&q=<?php echo $q; ?>&view=<?php echo $view; ?>" target="feud_team_scoring_iframe">
            <img src="images/disable.png" height="15" width="15">
            </a>			  
		  </td>
	    </tr>
	  </table>  
</body>
</html>