<?
include('auth.php');
include('common.php');
$x=650;
$y=300;

//fetch definition from specific user reason for leaving table
$t= $_GET['t'];		
$dbt=$_SETTINGTABLES_RFL[$t];


if (count($_POST) > 0)
{

	//clear table to start in all cases
	$SQL="DELETE FROM ".$dbt."";
	$results = llnb_query($SQL);
	
	$REASONS=$_POST['thereasons'];
	
	for ($i=0; $i < count($REASONS); $i++)
	{
		$SQL="INSERT INTO ".$dbt." 
			(rfl_id)
			VALUES
			(".$REASONS[$i].")
		";
		$results = llnb_query($SQL);
	}
	$do_close=1;

}
else
{

	$SQL="SELECT rfl_id FROM ".$dbt." ORDER by rfl_id";
	$results = llnb_query($SQL);
	while($row = llnb_fetch_assoc($results))
		$RFLSELECTED[$row['rfl_id']]="checked";

	$SQL="SELECT * FROM reasonforleaving ";
	$results = llnb_query($SQL);

	$i=0;
	while($row = llnb_fetch_assoc($results))
	{

		if ($i % 2)
			$odd= "class=\"odd\"";
		else
			$odd ="";


		$TRs .="
		<tr ".$odd."\">
		   <td>".$row['name']." </td>
		   <td><input type=\"checkbox\" name=\"thereasons[]\" ".$RFLSELECTED[$row['id']]." value=\"".$row['id']."\"> </td>
		 </tr>
		";

		$i++;
	}

}
?>
<!doctype html>
 <html class="no-js" lang="en"> <!--<![endif]-->
<head>
  <meta charset="utf-8">

  <!-- Use the .htaccess and remove these lines to avoid edge case issues.
       More info: h5bp.com/i/378 -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>LLNB System</title>
  <meta name="description" content="">

  <!-- Mobile viewport optimized: h5bp.com/viewport -->
  <meta name="viewport" content="width=device-width, maximum-scale=1.0">

  <!-- Place favicon.ico and apple-touch-icon.png in the root directory: mathiasbynens.be/notes/touch-icons -->
  <LINK REL="SHORTCUT ICON" HREF="favicon.ico">

  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="css/llnb-style.css">

  <!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->

 <script src="js/libs/modernizr-2.5.3.min.js"></script>
<link href="scripts/SqueezeBox.css" rel="stylesheet" type="text/css" />
<script src="scripts/mootools.js" type="text/javascript" ></script>
<script src="scripts/SqueezeBox.js" type="text/javascript"></script>
 
<script language="javascript">
 
window.addEvent('domready', function()
{
	SqueezeBox.assign($$('a.btnlfr_m'), {
		parse: 'rel'
	});
});

window.addEvent('domready', function()
{
	SqueezeBox.assign($$('a.btnsml_m'), {
		parse: 'rel'
	});
});  
</script>

</head>
<body>
<? 
if ($do_close) 
	echo "<script>self.location.href='setting_overview.php';</script>"; 

?>
<div id="wrap">
  <!-- Prompt IE 6 users to install Chrome Frame. Remove this if you support IE 6.
       chromium.org/developers/how-tos/chrome-frame-getting-started -->
  <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
  <header><a href="index.php" class="btn lfr" style="position:relative; top: 15px; right: 0;">Logout</a>
	<h1>Laubach Literacy - <?=uType();?></h1> 
	<nav id="menu" class="clearfix navmenu">
	<a href="home.php" class="btn lfl">Home</a>
	<a href="setting_overview.php" class="btn lfl">Settings</a></nav>
  </header>
  <div role="main" id="main" class="clearfix">
  	<div id="location">
  	<a href="setting_list.php?t=6" class="btn lfr" style="position:relative; top: 0; right: 10px;">Add/Edit/Delete: Reasons For Leaving</a>
      <H2>Setting</H2>
    </div> <!-- end of location -->
    <div>
    	  <h2><?=$_SETTINGTABLES_RFL_USR_DISPLAY[$t];?></h2>
<form action="setting_rfl.php?t=<?=$t;?>" method="post">
    <table  border="0" cellspacing="0" cellpadding="0" class="infotable">
      <tr>
        <th scope="col">Reason</th>
        <th scope="col">Assign</th>
      </tr>
<?=$TRs;?>
    </table>
    </div>

  <p>
  <input type="submit" class="btn lfr" value="Save &amp; Close">     

  </div> 

    <div style="clear:both;"></div>
  <footer>
	<?php include('footer.php'); ?>
  </footer>
  </div>


</form>
</body>
</html>