<?
include('auth.php');
include('common.php');

//needed for proper pagination
if (!isset($_GET['p']))
	$p = 1;
else
	$p = $_GET['p'];
$SQL_limit = buildLimitClause($p);


$SQL_x="";

//council
$c = $_GET['cid'];

if ($c && $c != -1)
{
	$SQL_x .= " AND council_id=".$c;
}
else
	$c=-1;
	
$SQL="SELECT count(id) as rcount FROM coordinator WHERE alive=1 ".$SQL_x;
$results = llnb_query($SQL);
$rowcount = llnb_fetch_assoc($results);

$SQL="SELECT * FROM coordinator WHERE alive=1 ".$SQL_x.$SQL_limit;
$results = llnb_query($SQL);

while($row = llnb_fetch_assoc($results))
{

	if ($row['active'] ==0)
		$act="(Inactive)";
	else
		$act="";
	

	$TRs.= "
	     <tr>
	      <td>
	      	<a href=\"coordinator_overview.php?cid=".$row['council_id']."&coordid=".$row['id']."\" class=\"btnsml btn\">
	        ".$row['firstname']." ".$row['lastname']." </a>&nbsp;".$act."
	      </td>
	        <td>".dispPhone($row['homephone'])."</td>
	        <td>".dispPhone($row['workphone'])."</td>
	        <td><a  onClick=\"return confirm('Are you sure you want to delete?');\"  href=\"do_delete_coordinator.php?cid=".$c."&frompg=coord_list&coordid=".$row['id']."\" class=\"btnsml btn\">Delete</a></td>
	     </tr>";
}
?>


<!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>

	<script type="text/javascript">
	function OnChange(dropdown)
	{
		var myindex  = dropdown.selectedIndex
		var SelValue = dropdown.options[myindex].value
		self.location.href = 'coordinator_list.php?cid='+SelValue;
	}
	</script>

</head>
<body onLoad="document.forms.council.councilname.focus()">
<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> 
	<h3><?=fetchCouncilName($_SESSION['council_id']);?></h3>	

    <nav id="menu" class="clearfix navmenu">
    <a href="home.php" class="btn lfl">Home</a></nav>
 
  </header>
  <div role="main" id="main" class="clearfix">
  	<div id="location">
  	<? 
   		if ($c != -1 && $_SESSION['ulevel'] == $_EXECDIR)
			echo	"<a href=\"coordinator_personalinfo.php?mode=new&cid=".$c."\" class=\"btn lfr\" style=\"position:relative; top: 0; right: 10px;\">Add Coordinator</a>";
	?>  
    <select name="council" class="selectcouncils" title="Select Council"  onchange='OnChange(this);'>
		<?
     		echo  buildCouncilDropdownALLoption($c); 
		?>
    </select>
  
    </div>
    
    <div>
    <H2>Coordinator List</H2>

<form name="coordinatorlist">
    <table  border="0" cellspacing="0" cellpadding="0" class="infotable">
      <tr>
        <th scope="col">Coordinator</th>
        <th scope="col">Home Phone</th>
        <th scope="col">Work Phone</th>
        <th scope="col">Delete</th>
      </tr>

	<?= $TRs;?>

    </table>




  </div>
  
   <?
   
	//pagination functionality
   $urlstring="&council=".$c;
   echo constructPagination($rowcount['rcount'], $p, "coordinator_list.php", $urlstring);

   ?>    
</div>

</form>
<!-- end of main -->
<aside>
</aside>
    <div style="clear:both;"></div>
<footer>
  <?php include('footer.php'); ?>
</footer>
</div>


</body>
</html>