require('DBconnect.php');
		require('library_functions.php');

		$SponsID=$_SESSION['loginID']; //get SponsID from previos session

	?>
	<header>
		<h1>Sponsorship Department</h1>
	</header>
	
	<section id="overview">
		<!-- I have put this stuff in the nav tag cause i wanted it to appear on the left without disturbing the page layout-->
		<!-- You have to write a php code which displays the deals done in that sector-->
		
			<?php 
			$earning_arr= get_earning_report($SponsID);
			$meeting_arr= get_meeting_report($SponsID);
			echo "<table class=\"sponsrepnav\" style=\"width:100%\" >";
			echo"<caption><h2>Sponsorship Representative Details:</h2></caption>";

			echo "<tr align=left>
				<th>Name:</th>
			<td>";
			echo get_person_name($SponsID);
			echo "</td></tr><tr align=left>
				<th>Sector:</th>
			<td>";
			echo get_person_sector($SponsID);
			echo "</td></tr><tr align=left>
				<th>Companies signed:</th>
			<td>";
function get_sector_details($SponsSector)
{
    require 'DBconnect.php';
    //this is needed in every function that uses mySQL
    $num_spons_reps = 0;
    $num_sector_heads = 0;
    $num_companies_in_sector = 0;
    $total_companies_signed = 0;
    $total_earned = 0;
    $max_earned = 0;
    $max_earner_ID = -1;
    $Sector_SR_query = "SELECT * FROM SponsRep WHERE Sector = '{$SponsSector}'";
    $result = mysql_query($Sector_SR_query);
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            $num_spons_reps++;
            $SponsRepID = $row['SponsID'];
            $SponsRepEarningReport = get_earning_report($SponsRepID);
            $total_companies_signed = $total_companies_signed + $SponsRepEarningReport[1];
            $total_earned = $total_earned + $SponsRepEarningReport[2];
            if ($max_earned < $SponsRepEarningReport[2]) {
                $max_earned = $SponsRepEarningReport[2];
                $max_earner_ID = $SponsRepID;
            }
        }
    }
    $Sector_SH_query = "SELECT * FROM SectorHead WHERE Sector='{$SponsSector}'";
    $result = mysql_query($Sector_SH_query);
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            $num_sector_heads++;
        }
    }
    $Sector_CMP_query = "SELECT * FROM Company WHERE Sector='{$SponsSector}'";
    $result = mysql_query($Sector_CMP_query);
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            $num_companies_in_sector++;
        }
    }
    return array("num_spons_reps" => $num_spons_reps, "num_sector_heads" => $num_sector_heads, "num_companies_in_sector" => $num_companies_in_sector, "total_companies_signed" => $total_companies_signed, "total_earned" => $total_earned, "max_earner_ID" => $max_earner_ID, "max_earned" => $max_earned);
}