<?
include('auth.php');
include('common.php');
$c=0;
if ($_POST['council']!= -1)
{
	$c_clause = " AND council_id = ".$_POST['council'];
	$c=$_POST['council'];
}	

if ($_POST['rtype']==1)
	$prog_clause = " AND prog != 2";

//get learners and count them
//grab all learners in system cycle thru them
$SQL="SELECT id FROM learner WHERE 1=1 ".$c_clause.$prog_clause;
$results = llnb_query($SQL);

//echo $SQL;


//assemble dates
$report_start = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
$report_end =    $_POST['yearend']."-".$_POST['monthend']."-".$_POST['dayend']; 

$lcount=0;
$ut=1;
while($row = llnb_fetch_assoc($results))
{
	//echo "params:".$row['id']." ". $report_start." ". $report_end." ----type of user:". $ut;
	
	if ( isPersonInReportRange($row['id'], $report_start, $report_end, $ut ) )
	{	

		$MYLEARNERS[$lcount]=$row['id'];
		$lcount++;

	}
	//echo "<BR>";

}


//grab all tutors in system cycle thru them
$SQL="SELECT id FROM tutor WHERE 1=1 ".$c_clause;
$results = llnb_query($SQL);
$tcount=0;
$ut=2;
while($row = llnb_fetch_assoc($results))
{
	
	if ( isPersonInReportRange($row['id'], $report_start, $report_end, $ut ) )
	{	
		$tcount++;
	}
}

//grab all volunteers in system cycle thru them
$SQL="SELECT id FROM volunteer WHERE 1=1 ".$c_clause;
$results = llnb_query($SQL);
$vcount=0;
$ut=3;
while($row = llnb_fetch_assoc($results))
{
	
	if ( isPersonInReportRange($row['id'], $report_start, $report_end, $ut ) )
	{	
		$vcount++;
	}
}

//get Tutoring hours
$tutoring_hours = round(getTutoringHours($report_start, $report_end, $c, 1,0), 2);

//get prep hours
$prep_hours = round(getTutoringHours($report_start, $report_end, $c, 2,0), 2);

//get vol hours
$v_hours = round(getVolunteeringHours($report_start, $report_end, $c), 2);



//loop Learners!
for ($i=0; $i<sizeof($MYLEARNERS); $i++)
{
	$SQL="SELECT * FROM learner WHERE id=".$MYLEARNERS[$i];
	$results = llnb_query($SQL);
	$row = llnb_fetch_assoc($results);
	
	//get learners hours
	$l_hours =  round(getTutoringHours($report_start, $report_end, $c, 1, $row['id']),2);
	if (!$l_hours)
		$l_hours = "0";
		
	$weeks = getWeekCount($report_start, $report_end);
	if ($weeks > 0)
		$hrsperweek = round(($l_hours/$weeks),2);
	else
		$hrsperweek=0;
	
	if ($row['gender']==0) $sex="F"; else $sex="M";
	$lastgrade=fetchLastGrade($MYLEARNERS[$i]);
	
	$refby = fetchRefBy($row['ref']);
	if ($row['confform']==0) $confform="No"; else $confform="Yes";
	
	$council = fetchCouncilName($row['council_id']);
	
	if ($row['lang']==1)
		$lang="English";
	else if ($row['lang']==2)
		$lang="French";
	else if ($row['lang']==3)
		$lang=$row['langother'];
	else
		$lang="Not specified";
	
	if ( fetchEI($MYLEARNERS[$i])==0 ) $ei="No"; else $ei="Yes";
	$lastedu=fetchLastYearSchool($MYLEARNERS[$i]);
	$clientof = fetchRefBy($row['clientof']);
	if ($row['learnconsent']==0) $consent="No"; else $consent="Yes";

	if ($row['prog']==0) 
		$prog="None"; 
	else if ($row['prog']==1)
		$prog ="Literacy";
	else if ($row['prog']==2) 
		$prog = "ESL";
	else if ($row['prog']==3) 
		$prog = "ESL, Literacy";
		
	$rows .= "
	<table class=\"table-3\">
					  <tbody>
							<tr>
								<td  class=\"tablecol1\" >
									<p class=\"table-headers\">Learner ID</p>
								</td>
								<td class=\"tablecol2\" >
									<p class=\"table-headers\">Gender</p>
								</td>
								<td class=\"tablecol2\" >
									<p class=\"table-headers\">Birth Date</p>
								</td>
								<td class=\"tablecol2\" >
									<p class=\"table-headers\">Highest Level of Education Completed</p>
								</td>
								<td class=\"tablecol2\" >
									<p class=\"table-headers\">Referral Source</p>
								</td>
								<td class=\"tablecol2\" >
									<p class=\"table-headers\">Laubach Confirmation Signed</p>
								</td>
							</tr>
							<tr>
								<td>
									<p class=\"table-content\">".$row['llnb_id']."</p>
								</td>
								<td>
									<p class=\"table-content\">".$sex."</p>
								</td>
								<td>
									<p class=\"table-content\">".$row['birth']."</p>
								</td>
								<td>
									<p class=\"table-content\">".$lastgrade."</p>
								</td>
								<td>
									<p class=\"table-content\">".$refby."</p>
								</td>
								<td>
									<p class=\"table-content\">".$confform."</p>
								</td>
							</tr>
							<tr>
								<td>
									<p class=\"table-headers\">Literacy Council</p>
								</td>
								<td>
									<p class=\"table-headers\">Mother Tongue</p>
								</td>
								<td>
									<p class=\"table-headers\">EI Recipient</p>
								</td>
								<td>
									<p class=\"table-headers\">Last Year Attended School</p>
								</td>
								<td>
									<p class=\"table-headers\">Client of</p>
								</td>
								<td>
									<p class=\"table-headers\">PETL Release Consent Signed</p>
								</td>
							</tr>
							<tr>
								<td>
									<p class=\"table-content\">".$council."</p>
								</td>
								<td>
									<p class=\"table-content\">".$lang."</p>
								</td>
								<td>
									<p class=\"table-content\">".$ei."</p>
								</td>
								<td>
									<p class=\"table-content\">".$lastedu."</p>
								</td>
								<td>
									<p class=\"table-content\">".$clientof."</p>
								</td>
								<td>
									<p class=\"table-content\">".$consent."</p>
								</td>
							</tr>
							<tr>
								<td>
									<p class=\"table-headers\">Date Tutoring Started</p>
								</td>
								<td>
									<p class=\"table-headers\">Total Tutoring Hours</p>
								</td>
								<td>
									<p class=\"table-headers\">Tutoring Hours per Week</p>
								</td>
								<td>
									<p class=\"table-headers\">Literacy/ESL</p>
								</td>
								<td>
								</td>
								<td>
								</td>
							</tr>
							<tr>
								<td>
									<p class=\"table-content\">".$row['startdate']."</p>
								</td>
								<td>
									<p class=\"table-content\">".$l_hours." hrs</p>
								</td>
								<td>
									<p class=\"table-content\">".$hrsperweek." hrs</p>
								</td>
								<td>
									<p class=\"table-content\">".$prog."</p>
								</td>
								<td>
								</td>
								<td>
								</td>
							</tr>
							".doLearningPlan($report_start, $report_end, $MYLEARNERS[$i])."

							".doStatus($report_start, $report_end, $MYLEARNERS[$i])."


						</tbody>
				</table>
	";

}






?>

<!doctype html>
 <html class="no-js" lang="en">
<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">
  <link rel="stylesheet" href="css/llnb-style-ptinting.css">

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

  <script src="js/libs/modernizr-2.5.3.min.js"></script>
</head>
<body style="background-color: #fff; background-image: none;">
	
		<div id="untitled-1">
			<div class="story">
            <h1>Laubach Literacy -    <?
    if ($_POST['rtype'] == 1)
    		echo "New Brunswick Government Report";
    	else
    	   	echo "Internal  Report";
    ?>
            
            - <?=dispDateNoTime($report_start);?> to <?=dispDateNoTime($report_end);?> </h1>
			  <table id="table-1">
					<tbody>
						<tr>
							<td>
								<p class="table-headers">Learners</p>
							</td>
							<td>
								<p class="table-headers">Tutors</p>
							</td>
							<?
							if ($_POST['rtype']==2)
							echo "							
							<td>
								<p class=\"table-headers\">Volunteers</p>
							</td>";
							?>
						</tr>
						<tr>
						
							<td>
								<p class="table-content"><?=$lcount;?></p>
							</td>
							<td>
								<p class="table-content"><?=$tcount;?></p>
							</td>
							<?
							if ($_POST['rtype']==2)
							echo "							
							<td>
								<p class=\"table-content\">".$vcount."</p>
							</td>";
							?>
							
							
						</tr>
						<tr>
							<td>
								<p class="table-headers">Tutoring Hours</p>
							</td>
							<td>
								<p class="table-headers">Prep Hours</p>
							</td>
							<?
							if ($_POST['rtype']==2)
							echo "							
							<td>
								<p class=\"table-headers\">General Volunteer Hours</p>
							</td>";
							
							?>
						</tr>
						<tr>
							<td>
								<p class="table-content"><?=$tutoring_hours;?> hrs</p>
							</td>
							<td>
								<p class="table-content"><?=$prep_hours;?> hrs</p>
							</td>
							<?
							if ($_POST['rtype']==2)
							echo "
							<td>
								<p class=\"table-content\">".$v_hours." hrs</p>
							</td>";
							
							?>
						</tr>
					</tbody>
				</table>
				<h3>Laubach Literacy - 
				<?
    if ($_POST['rtype'] == 1)
    		echo "New Brunswick Government Report";
    	else
    	   	echo "Internal Report";
    ?> - <?=dispDateNoTime($report_start);?> to <?=dispDateNoTime($report_end);?></h3>


			<?=$rows;?>



				
				
	
			</div>
		</div>
  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\/script>')</script>

  <!-- scripts concatenated and minified via build script -->
  <script src="js/plugins.js"></script>
  <script src="js/script.js"></script>
  <!-- end scripts -->

</body>
</html>