<?php
include_once("conn_my_web.php");
include_once("logged_in.php");
$m = $_GET['m'];
$jumpto = $_POST['jumpto'];

	if ($dow_D=="Mon") {
  		$day_math = "0 days";
	}
	elseif ($dow_D=="Tue") {
  		$day_math = "1 days";	  
	}
	elseif ($dow_D=="Wed") {
  		$day_math = "2 days";  
	}
	elseif ($dow_D=="Thu") {
  		$day_math = "3 days";		  
	}
	elseif ($dow_D=="Fri") {
  		$day_math = "4 days";  
	}
	elseif ($dow_D=="Sat") {
  		$day_math = "5 days";  
	}
	elseif ($dow_D=="Sun") {
  		$day_math = "6 days";  
	}
	$query_date = $game_date;
	$date = date_create($query_date);
	date_sub($date, date_interval_create_from_date_string($day_math));
	$start_date = date_format($date, 'Y-m-d');
	$expire = time() + 60*60*18;


	$query = "select * from feud_surveys_host where date_added = '".date('Y-m-d')."' and host_ID = ".$usr_ID;
	$result = mysqli_query($my_conn, $query);
	$num = mysqli_num_rows($result);
	if ($num==0) {
		$query = "select fs.set_ID from feud_sets s inner join feud_surveys fs on fs.set_ID = s.set_ID 
		where s.weekstart = '".$start_date."' and s.question_set_id = ".$question_set_id." limit 1";
		$result = mysqli_query($my_conn, $query);
		$row = mysqli_fetch_assoc($result);
		$set_ID = $row['set_ID'];
		//set cookie for set_ID
		setcookie("set_ID", $set_ID, $expire, "/", "triviocity.com");	
		//check to see if there are questions here for region.  if not, insert into feud_surveys from feud_surveys with region_ID
		$rquery = "select sID, survey, sRound, sNo, response1, response2, response3, response4, response5 
					from feud_surveys where set_ID = ".$set_ID." and region_ID = ".$region_ID;	
		$rresult = mysqli_query($my_conn, $rquery);
		$num = mysqli_num_rows($rresult);
		if ($num==0) {
			$rquery = "select sID, survey, sRound, sNo, response1, response2, response3, response4, response5 
						from feud_surveys where set_ID = ".$set_ID." and region_ID = 0";	
		}			
			$rresult = mysqli_query($my_conn, $rquery);								
			while ($rrow=mysqli_fetch_assoc($rresult)) {
				$sRound = $rrow['sRound'];
				$sNo = $rrow['sNo'];
				$question = addslashes($rrow['survey']);
				$response1 = addslashes($rrow['response1']);
				$response2 = addslashes($rrow['response2']);
				$response3 = addslashes($rrow['response3']);
				$response4 = addslashes($rrow['response4']);
				$response5 = addslashes($rrow['response5']);	
				$insert = "insert into feud_surveys_host (sRound, sNo, set_ID, survey, response1, response2, response3, response4, response5, date_added, region_ID, host_ID) values ('".$sRound."', '".$sNo."', '".$set_ID."', '".$question."', '".$response1."', '".$response2."', '".$response3."', '".$response4."', '".$response5."', '".date('Y-m-d')."', ".$region_ID.", ".$usr_ID.")";
				mysqli_query($my_conn, $insert);
			}
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Team Feud | Navigation</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <style>
	body {
      background-color: #f1f1f1;
		font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";		
	}
    /* Remove the navbar's default margin-bottom and rounded borders */ 
    .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;} 
    }
  </style>
  <?php
  if ($jumpto!="") {
	  $s = explode("-",$jumpto);
	  $nr = $s[0];
	  $nq = $s[1];
	  
  ?>
  <script language="javascript">
  function goto() {
	window.open('feud_nav_iframe.php?r=<?php echo $nr; ?>&q=<?php echo $nq; ?>&view=survey', 'feud_nav_game_iframe')
  }
  </script>  
  <?php
  }
  ?>
</head>
  <?php
  if ($jumpto!=="")	{
  ?>
  <body onLoad="goto()">
  <?php
  } else {
  ?>
<body>
  <?php
	}
	?>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="feud_nav.php"><img src="images/TF-Logo_80px_h.png" width="120" height="80"></a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
    
      <ul class="nav navbar-nav">
        <li class="active"><span style="color: #FFF; font-weight: bold;"> Jump To:</span><br>
<form action="feud_nav.php" method="post">
    <select name="jumpto" onchange="this.form.submit()">
      <option selected value=""></option>
      <option value="1-1">1-1</option>
      <option value="1-2">1-2</option>
      <option value="1-3">1-3</option>
      <option value="1-4">1-4</option>
      <option value="B-1">B-1</option>
      <option value="2-1">2-1</option>
      <option value="2-2">2-2</option>
      <option value="2-3">2-3</option>
      <option value="2-4">2-4</option>
      <option value="B-2">B-2</option>      
      <option value="3-1">3-1</option>
      <option value="3-2">3-2</option>
      <option value="3-3">3-3</option>
      <option value="3-4">3-4</option>
      <option value="B-3">B-3</option>  
      <option value="F-1">F-1</option>
      <option value="F-2">F-2</option>
      <option value="F-3">F-3</option>
		 </select>
		</form>
		  </li>
		  <li>
			<a href="feud_preview.php" target="_blank" style="font-weight: bold; color: #FFF;">Preview Game</a>
       
       </li>
	   <li>
		  <a href="feud_nav_iframe.php?view=scores" target="feud_nav_game_iframe" style="font-weight: bold; color: #FFF;">Scores</a>
		  </li>       
       <?php
	   if ($region_ID==19)  {
	   ?>

	   <?php
		   $a = 1;
		   while ($a < 9) {
	   ?>
	   <li>
	   <a href="feud_rules<?php echo $a; ?>.php" style="font-weight: bold; color: #FFF;" target="game">Rules <?php echo $a; ?></a>
		  </li>
	   <?php
		   $a = ($a + 1);
	   	   }
	   }
	   ?>
       
		  <li>
			<a href="https://www.triviocity.com/home.php" target="_blank" style="font-weight: bold; color: #FFF;">Triviocity.com</a>
       
       </li>       
        
      </ul>
      
    </div>
  </div>
</nav>
	<div style="height:20px;"></div>
<table width="1366" cellpadding="0" cellspacing="0" border="0">
  <tr>
	  <td width="10"></td>
	  <td width="456"><iframe src="feud_nav_iframe.php" width="456" height="1000" frameborder="0" name="feud_nav_game_iframe"></iframe></td>
	  <td width="10"></td>
	  <td width="580"><iframe src="feud_scoring.php" width="580" height="1000" frameborder="0" name="feud_team_scoring_iframe"></iframe>
	  <td width="10"></td>
	  <td width="300"></td>
	  <td width="10"></td>
	</tr>
	</table>
</body>
</html>
