<?
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="";

//active state
if (!isset($_GET['active']))
	$act=1;
else
	$act=$_GET['active'];
	
//search term
$s = secure_user_input($_GET['s']);
if ($s)
{
	$SQL_x .= " AND (firstname LIKE '%".$s."%' OR lastname LIKE '%".$s."%')";
}


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


//coords/tutor can ONLY see their council's tutors
if ($_SESSION['ulevel'] == $_COORD || $_SESSION['ulevel'] == $_TUTOR )
{	
	$c = $_SESSION['council_id'];
}

if ($c && $c != -1)
{
	$SQL_x .= " AND council_id=".$c;
}

$SQL="SELECT count(id) as rcount FROM tutor WHERE active=".$act.$SQL_x;
$results = llnb_query($SQL);
$rowcount = llnb_fetch_assoc($results);
	
$SQL="SELECT * FROM tutor WHERE active=".$act.$SQL_x.$SQL_limit;
$results = llnb_query($SQL);
while($row = llnb_fetch_assoc($results))
{
	$TRs .= "  
		<tr>
		  <td><a href=\"tutor_overview.php?tid=".$row['id']."\" class=\"btnsml btn\">".$row['firstname']." ".$row['lastname']."</a></td>
		  <td>".dispPhone($row['homephone'])."</td>
		  <td><a class=\"btnsml_m\" rel=\"{handler:'iframe',size:{x:550,y:400}}\" href=\"tutor_time_m.php?tid=".$row['id']."&c=".$c."\">Add Session</a></td>
		 </tr>";

}

/*
      <tr>
        <td><a href="tutor_overview.php" class="btnsml btn">First Last</a> (10)</td>
        <td>506.506.5061</td>
        <td><a href="tutor_time_m.php" class="btnsml btn">Add Session</a></td>
      </tr>
*/
?>



<!doctype html>

<!--[if gt IE 8]><!--> <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">
  <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 type="text/javascript">
  	function OnChange(dropdown)
  	{
  		var myindex  = dropdown.selectedIndex
  		var SelValue = dropdown.options[myindex].value
  		self.location.href = 'tutor_list.php?s=<?=$s;?>&active=<?=$act;?>&council='+SelValue;
  	}
	</script>
	
	<script type="text/javascript">

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

	</script>
	
	
</head>
<body>
<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">
  	<a href="tutor_personalinfo.php?mode=new" class="btn lfr" style="position:relative; top: 0; right: 10px;">Add Tutor</a>
      <H2>Tutors</H2>
    
    </div> <!-- end of location -->
    <div>
    <?
    	if ($_SESSION['ulevel'] == $_EXECDIR )
    	echo "
      <select name=\"council\" class=\"selectcouncils\" title=\"Select Council\" onchange='OnChange(this);'>
   	". buildCouncilDropdownALLoption($c)."
    	</select>";
    ?>
    
	<form name="searchform" id="searchform" action="tutor_list.php" method="GET">
	<input name="s" type="text" class="search" id="search"   title="Search" value="<?= $_GET['s'];?>">
	<input type="submit" class="searchbtn searchmove" id="searchbtn"   value="Search">
	<input type="button" class="searchbtn" id="clearbtn" onClick="self.document.searchform.s.value=''; self.document.searchform.submit();"    value="Clear Search">
	<input type="hidden" name="active" value="<?=$act;?>">
	<input type="hidden" name="council" value="<?=$_GET['council'];?>">
	 </form>
    
    
    <div style="clear:both;"></div>
    <table  border="0" cellspacing="0" cellpadding="0" class="infotable">
      <tr>
        <th scope="col">Name</th>
        <th scope="col">Phone</th>
        <th scope="col">Session</th>
      </tr>
       <?
        echo $TRs;
       ?>

    </table>

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

   ?>     
  </div><!-- end of main -->
  <div class="sidecolumn">

  	<?
  	if ($_SESSION['ulevel'] != $_TUTOR )
	{
	  if ($act == 1)
	  	echo "<a href=\"tutor_list.php?active=0&s=".$s."&council=".$_GET['council']."\" class=\"btn btncnt\">Inactive Tutors</a>";
	 else 
	 	echo "<a href=\"tutor_list.php?active=1&s=".$s."&council=".$_GET['council']."\" class=\"btn btncnt\">Active Tutors</a>";
	}  
	 ?> 

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


</body>
</html>