<!DOCTYPE html>
<html>

	<head>

		<?php

			include 'includes/core_scripts.php'; 

			// ini_set('display_errors', 1);
   //    		ini_set('display_startup_errors', 1);
   //    		error_reporting(E_ALL);

		?>

		<title>Transportation Model | CSULA Energy Dashboard</title>

	</head>

	<body>

		<!-- Layout-->
		<div class="layout">

			<?php 

				include "includes/header.php";
				include "includes/chartjs_scripts.php";

			?>

			<!-- Wrapper-->
			<div class="wrapper">

				<section class='module module-gray'>
					
					<div class='container'>

						<div class="row">

							<div class="col-md-12">

								<div class="module-title">

									<br /><br />

									<h1 class="text-success text-center">Transportation</h1>

								</div>

							</div>

							<div class='col-12'>

								<?php

									function getDistance($zip) {

										$distance = 0;

										$result = pg_query("SELECT * FROM api_references WHERE api_name='Google Maps'");

										$api = pg_fetch_assoc($result)['access_token'];

										$endpoint = "https://maps.googleapis.com/maps/api/distancematrix/json";

										$params = array('key' => $api, 'origins' => $zip, 'destinations' => 'California State University, Los Angeles', 'units' => 'imperial');

										$url = $endpoint . '?' . http_build_query($params);

										$ch = curl_init();
										curl_setopt($ch, CURLOPT_URL, $url);
										curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
										$output = curl_exec($ch);

										curl_close($ch);

										$output = json_decode($output);

										if($output->rows[0]->elements[0]->status != 'NOT_FOUND') {

											$distance = $output->rows[0]->elements[0]->distance->text;

											$distance = number_format(floatval(explode(" ", $distance)[0]), 2, '.', '');

										}

										return $distance;

									}

									$total_enrollment = 26671;
									$on_campus_population = 650;
									$daily_permits_percentage = 18.31;
									$parking_permit_percentage = 37.44;
									$public_transportation_percentage = 14.08;
									$own_transportation_percentage = $daily_permits_percentage + $parking_permit_percentage;

									$public_transportation_population = floor($public_transportation_percentage * $total_enrollment / 100);
									$own_transportation_population = $total_enrollment - ($public_transportation_population + $on_campus_population);

									$result = pg_query("SELECT * FROM transportation_survey WHERE year=2019 ORDER BY id");

									$i = 0;
									$own_transportation_energy = 0.0;
									$public_transportation_energy = 0.0;

									$public_transportation_count = 0;
									$own_transportation_count = 0;

									$total_energy = array();
									$total_distance = array();
									$energy_trend = array();

									$total_energy["drove_alone"] = 0;
									$total_energy["carpool"] = 0;
									$total_energy["rideshare"] = 0;
									$total_energy["metrolink"] = 0;
									$total_energy["bus"] = 0;
									$total_distance["drove_alone"] = 0;
									$total_distance["carpool"] = 0;
									$total_distance["rideshare"] = 0;
									$total_distance["metrolink"] = 0;
									$total_distance["bus"] = 0;
									$energy_trend["sun"] = 0;
									$energy_trend["mon"] = 0;
									$energy_trend["tue"] = 0;
									$energy_trend["wed"] = 0;
									$energy_trend["thu"] = 0;
									$energy_trend["fri"] = 0;
									$energy_trend["sat"] = 0;

									$bus = array();
									$rail = array();
									$carpool = array();
									$rideshare = array();
									$drove_alone = array();

									$bus_count = array();
									$rail_count = array();
									$carpool_count = array();
									$rideshare_count = array();
									$drove_alone_count = array();
									$no_commute_count = array();

									$bus["sun"] = 0;
									$bus["mon"] = 0;
									$bus["tue"] = 0;
									$bus["wed"] = 0;
									$bus["thu"] = 0;
									$bus["fri"] = 0;
									$bus["sat"] = 0;

									$rail["sun"] = 0;
									$rail["mon"] = 0;
									$rail["tue"] = 0;
									$rail["wed"] = 0;
									$rail["thu"] = 0;
									$rail["fri"] = 0;
									$rail["sat"] = 0;

									$carpool["sun"] = 0;
									$carpool["mon"] = 0;
									$carpool["tue"] = 0;
									$carpool["wed"] = 0;
									$carpool["thu"] = 0;
									$carpool["fri"] = 0;
									$carpool["sat"] = 0;

									$rideshare["sun"] = 0;
									$rideshare["mon"] = 0;
									$rideshare["tue"] = 0;
									$rideshare["wed"] = 0;
									$rideshare["thu"] = 0;
									$rideshare["fri"] = 0;
									$rideshare["sat"] = 0;

									$drove_alone["sun"] = 0;
									$drove_alone["mon"] = 0;
									$drove_alone["tue"] = 0;
									$drove_alone["wed"] = 0;
									$drove_alone["thu"] = 0;
									$drove_alone["fri"] = 0;
									$drove_alone["sat"] = 0;

									$bus_count["sun"] = 0;
									$bus_count["mon"] = 0;
									$bus_count["tue"] = 0;
									$bus_count["wed"] = 0;
									$bus_count["thu"] = 0;
									$bus_count["fri"] = 0;
									$bus_count["sat"] = 0;

									$rail_count["sun"] = 0;
									$rail_count["mon"] = 0;
									$rail_count["tue"] = 0;
									$rail_count["wed"] = 0;
									$rail_count["thu"] = 0;
									$rail_count["fri"] = 0;
									$rail_count["sat"] = 0;

									$carpool_count["sun"] = 0;
									$carpool_count["mon"] = 0;
									$carpool_count["tue"] = 0;
									$carpool_count["wed"] = 0;
									$carpool_count["thu"] = 0;
									$carpool_count["fri"] = 0;
									$carpool_count["sat"] = 0;

									$rideshare_count["sun"] = 0;
									$rideshare_count["mon"] = 0;
									$rideshare_count["tue"] = 0;
									$rideshare_count["wed"] = 0;
									$rideshare_count["thu"] = 0;
									$rideshare_count["fri"] = 0;
									$rideshare_count["sat"] = 0;

									$drove_alone_count["sun"] = 0;
									$drove_alone_count["mon"] = 0;
									$drove_alone_count["tue"] = 0;
									$drove_alone_count["wed"] = 0;
									$drove_alone_count["thu"] = 0;
									$drove_alone_count["fri"] = 0;
									$drove_alone_count["sat"] = 0;

									$no_commute_count["sun"] = 0;
									$no_commute_count["mon"] = 0;
									$no_commute_count["tue"] = 0;
									$no_commute_count["wed"] = 0;
									$no_commute_count["thu"] = 0;
									$no_commute_count["fri"] = 0;
									$no_commute_count["sat"] = 0;

									while($row = pg_fetch_assoc($result)) {

										if($row['roundtrip_miles'] == NULL) {

											$distance = number_format(getDistance($row['zipcode']) * 2, 2, '.', '');

											pg_query("UPDATE transportation_survey SET roundtrip_miles=".$distance." WHERE zipcode='".$row['zipcode']."'");

										}
										else
											$distance = $row['roundtrip_miles'];

										$modes = array();

										$modes["sun"] = $row['sun_mode'];
										$modes["mon"] = $row['mon_mode'];
										$modes["tue"] = $row['tue_mode'];
										$modes["wed"] = $row['wed_mode'];
										$modes["thu"] = $row['thu_mode'];
										$modes["fri"] = $row['fri_mode'];
										$modes["sat"] = $row['sat_mode'];

										if(in_array(4, $modes) || in_array(6, $modes))
											$public_transportation_count++;
										else if (in_array(5, $modes) || in_array(3, $modes) || in_array(2, $modes))
											$own_transportation_count++;

										foreach ($modes as $key => $value) {

											$trip_energy = 0;
											
											switch ($value) {

												case '2':

													$vehicle_milage = $row['vehicle_milage'];
													$vehicle_type = $row['vehicle_type'];
													$vehicle_type_carbon = pg_fetch_assoc(pg_query("SELECT * FROM vehicle_type WHERE id=".$vehicle_type))['carbon_equivalent'];

													$trip_energy = $distance * $vehicle_type_carbon;

													$total_distance["drove_alone"] = $total_distance["drove_alone"] + $distance;
													$total_energy["drove_alone"] = $total_energy["drove_alone"] + $trip_energy;
													$drove_alone[$key] = $drove_alone[$key] + $trip_energy;
													$drove_alone_count[$key] = $drove_alone_count[$key] + 1;

													$own_transportation_energy += $trip_energy;

													break;

												case '3':

													$vehicle_milage = 24.7;
													$vehicle_type_carbon = pg_fetch_assoc(pg_query("SELECT * FROM vehicle_type WHERE id=1"))['carbon_equivalent'];
													$persons = $row['carpool_persons'];

													$trip_energy = $distance * $vehicle_type_carbon;
													$trip_energy = $trip_energy / $persons;

													$total_distance["carpool"] = $total_distance["carpool"] + $distance;
													$total_energy["carpool"] = $total_energy["carpool"] + $trip_energy;
													$carpool[$key] = $carpool[$key] + $trip_energy;
													$carpool_count[$key] = $carpool_count[$key] + 1;

													$own_transportation_energy += $trip_energy;

													break;

												case '4':

													$vehicle_type_carbon = pg_fetch_assoc(pg_query("SELECT * FROM vehicle_type WHERE id=12"))['carbon_equivalent'];
													
													$trip_energy = $distance * $vehicle_type_carbon;

													$total_distance["metrolink"] = $total_distance["metrolink"] + $distance;
													$total_energy["metrolink"] = $total_energy["metrolink"] + $trip_energy;
													$rail[$key] = $rail[$key] + $trip_energy;
													$rail_count[$key] = $rail_count[$key] + 1;

													$public_transportation_energy += $trip_energy;

													break;

												case '5':

													$vehicle_milage = 24.7;
													$vehicle_type_carbon = pg_fetch_assoc(pg_query("SELECT * FROM vehicle_type WHERE id=1"))['carbon_equivalent'];

													$trip_energy = $distance * $vehicle_type_carbon;

													$total_distance["rideshare"] = $total_distance["rideshare"] + $distance;
													$total_energy["rideshare"] = $total_energy["rideshare"] + $trip_energy;
													$rideshare[$key] = $rideshare[$key] + $trip_energy;
													$rideshare_count[$key] = $rideshare_count[$key] + 1;

													$own_transportation_energy += $trip_energy;

													break;

												case '6':

													$vehicle_type_carbon = pg_fetch_assoc(pg_query("SELECT * FROM vehicle_type WHERE id=11"))['carbon_equivalent'];
													
													$trip_energy = $distance * $vehicle_type_carbon;

													$total_distance["bus"] = $total_distance["bus"] + $distance;
													$total_energy["bus"] = $total_energy["bus"] + $trip_energy;
													$bus[$key] = $bus[$key] + $trip_energy;
													$bus_count[$key] = $bus_count[$key] + 1;

													$public_transportation_energy += $trip_energy;

													break;

												default:

													$no_commute_count[$key] = $no_commute_count[$key] + 1;

											}

											$energy_trend[$key] = $energy_trend[$key] + $trip_energy;

										}

									}

									foreach ($energy_trend as $key => $value) {

										$energy_trend[$key] = number_format($energy_trend[$key], 2, '.', '');
										
									}

									foreach ($total_energy as $key => $value) {

										$total_energy[$key] = number_format($total_energy[$key], 2, '.', '');
										
									}

									foreach ($total_distance as $key => $value) {

										$total_distance[$key] = number_format($total_distance[$key], 2, '.', '');
										
									}

									$total_student_Emissions = ((($own_transportation_population / $own_transportation_count) * $own_transportation_energy) + (($public_transportation_population / $public_transportation_count) * $public_transportation_energy)) * (288 / 7);

								?>

							</div>

							<div class="col-12">

								<?php

									$total_employee_Emissions = 0.0;
									$total_employee_miles = 0.0;

									$result = pg_query("SELECT * FROM staff_survey WHERE year=2018");

									$i = 0;

									while($row = pg_fetch_assoc($result)) {

										$i++;

										if($row['trip_distance'] == NULL) {

											$distance = 2 * getDistance($row['zipcode']);

											pg_query("UPDATE staff_survey SET trip_distance=$distance WHERE id=".$row['id']);

											if($distance > 0) {

												$mon_mode = $row['monday'];
												$tue_mode = $row['tuesday'];
												$wed_mode = $row['wednesday'];
												$thu_mode = $row['thursday'];
												$fri_mode = $row['friday'];

												$mon_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$mon_mode'"))['carbon_equivalent'];
												$tue_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$tue_mode'"))['carbon_equivalent'];
												$wed_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$wed_mode'"))['carbon_equivalent'];
												$thu_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$thu_mode'"))['carbon_equivalent'];
												$fri_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$fri_mode'"))['carbon_equivalent'];

												$employee_Emissions = $distance * ($mon_Emissions + $tue_Emissions + $wed_Emissions + $thu_Emissions + $fri_Emissions);

												$total_employee_Emissions = $total_employee_Emissions + $employee_Emissions;
												$total_employee_miles = $total_employee_miles + $distance;

											}

										}
										else {

											if($row['trip_distance'] > 0) {

												$mon_mode = $row['monday'];
												$tue_mode = $row['tuesday'];
												$wed_mode = $row['wednesday'];
												$thu_mode = $row['thursday'];
												$fri_mode = $row['friday'];

												$mon_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$mon_mode'"))['carbon_equivalent'];
												$tue_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$tue_mode'"))['carbon_equivalent'];
												$wed_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$wed_mode'"))['carbon_equivalent'];
												$thu_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$thu_mode'"))['carbon_equivalent'];
												$fri_Emissions = pg_fetch_assoc(pg_query("SELECT * FROM transportation_mode WHERE code='$fri_mode'"))['carbon_equivalent'];

												$employee_Emissions = $row['trip_distance'] * ($mon_Emissions + $tue_Emissions + $wed_Emissions + $thu_Emissions + $fri_Emissions);

												$total_employee_Emissions = $total_employee_Emissions + $employee_Emissions;
												$total_employee_miles = $total_employee_miles + $row['trip_distance'];

											}

										}

									}

									$total_employee_Emissions = $total_employee_Emissions * (288 / 7);
									$total_employee_miles = $total_employee_miles * (288 / 7);

									$drove_alone_per_person = round((array_sum($drove_alone) * 100 ) / array_sum($drove_alone_count), 2);
									$carpool_per_person = round((array_sum($carpool) * 100 ) / array_sum($carpool_count), 2);
									$rideshare_per_person = round((array_sum($rideshare) * 100 ) / array_sum($rideshare_count), 2);

								?> 

								

							</div>

						</div>

					</div>

				</section>

				<section class="module">
					
					<div class="container">

						<div class="row">

							<div class="col-12 text-center">

								<h3 class="text-success"><u>ANALYSIS FROM THE YEAR 2019 SURVEY</u></h3>

							</div>

						</div>

					</div>

					<br /><br />

					<div class="container-fluid">

						<div class="row">

							<div class="col-12">

								<div class="row">

									<div class="col-md-7 col-12">

										<!--canvas id="chart4"></canvas-->

										<!--table class="table table-striped" style="color: black;">
											
											<tr class="text-success">
												
												<th>Mode / Day</th>
												<th>Sun</th>
												<th>Mon</th>
												<th>Tue</th>
												<th>Wed</th>
												<th>thu</th>
												<th>Fri</th>
												<th>Sat</th>
												<th>Weekly Average</th>

											</tr>

											<tr>
												
												<th class="text-success">Metrolink/Rail</th>

												<?php

													//$sun_rail = round(($rail["sun"] * 100) / ($rail["sun"] + $bus["sun"] + $drove_alone["sun"] + $rideshare["sun"] + $carpool["sun"]), 2);
													//$mon_rail = round(($rail["mon"] * 100) / ($rail["mon"] + $bus["mon"] + $drove_alone["mon"] + $rideshare["mon"] + $carpool["mon"]), 2);
													//$tue_rail = round(($rail["tue"] * 100) / ($rail["tue"] + $bus["tue"] + $drove_alone["tue"] + $rideshare["tue"] + $carpool["tue"]), 2);
													//$wed_rail = round(($rail["wed"] * 100) / ($rail["wed"] + $bus["wed"] + $drove_alone["wed"] + $rideshare["wed"] + $carpool["wed"]), 2);
													//$thu_rail = round(($rail["thu"] * 100) / ($rail["thu"] + $bus["thu"] + $drove_alone["thu"] + $rideshare["thu"] + $carpool["thu"]), 2);
													//$fri_rail = round(($rail["fri"] * 100) / ($rail["fri"] + $bus["fri"] + $drove_alone["fri"] + $rideshare["fri"] + $carpool["fri"]), 2);
													//$sat_rail = round(($rail["sat"] * 100) / ($rail["sat"] + $bus["sat"] + $drove_alone["sat"] + $rideshare["sat"] + $carpool["sat"]), 2);

												?>

												<td><?php //echo $sun_rail; ?></td>
												<td><?php //echo $mon_rail; ?></td>
												<td><?php //echo $tue_rail; ?></td>
												<td><?php //echo $wed_rail; ?></td>
												<td><?php //echo $thu_rail; ?></td>
												<td><?php //echo $fri_rail; ?></td>
												<td><?php //echo $sat_rail; ?></td>
												<td><?php //echo round(($sun_rail + $mon_rail + $tue_rail + $wed_rail + $thu_rail + $fri_rail + $sat_rail) / 7, 2); ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Bus</th>

												<?php

													// $sun_bus = round(($bus["sun"] * 100) / ($rail["sun"] + $bus["sun"] + $drove_alone["sun"] + $rideshare["sun"] + $carpool["sun"]), 2);
													// $mon_bus = round(($bus["mon"] * 100) / ($rail["mon"] + $bus["mon"] + $drove_alone["mon"] + $rideshare["mon"] + $carpool["mon"]), 2);
													// $tue_bus = round(($bus["tue"] * 100) / ($rail["tue"] + $bus["tue"] + $drove_alone["tue"] + $rideshare["tue"] + $carpool["tue"]), 2);
													// $wed_bus = round(($bus["wed"] * 100) / ($rail["wed"] + $bus["wed"] + $drove_alone["wed"] + $rideshare["wed"] + $carpool["wed"]), 2);
													// $thu_bus = round(($bus["thu"] * 100) / ($rail["thu"] + $bus["thu"] + $drove_alone["thu"] + $rideshare["thu"] + $carpool["thu"]), 2);
													// $fri_bus = round(($bus["fri"] * 100) / ($rail["fri"] + $bus["fri"] + $drove_alone["fri"] + $rideshare["fri"] + $carpool["fri"]), 2);
													// $sat_bus = round(($bus["sat"] * 100) / ($rail["sat"] + $bus["sat"] + $drove_alone["sat"] + $rideshare["sat"] + $carpool["sat"]), 2);

												?>

												<td><?php //echo $sun_bus; ?></td>
												<td><?php //echo $mon_bus; ?></td>
												<td><?php //echo $tue_bus; ?></td>
												<td><?php //echo $wed_bus; ?></td>
												<td><?php //echo $thu_bus; ?></td>
												<td><?php //echo $fri_bus; ?></td>
												<td><?php //echo $sat_bus; ?></td>
												<td><?php //echo round(($sun_bus + $mon_bus + $tue_bus + $wed_bus + $thu_bus + $fri_bus + $sat_bus) / 7, 2); ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Drove Alone / Dropped Off</th>

												<?php

													// $sun_drove_alone = round(($drove_alone["sun"] * 100) / ($rail["sun"] + $bus["sun"] + $drove_alone["sun"] + $rideshare["sun"] + $carpool["sun"]), 2);
													// $mon_drove_alone = round(($drove_alone["mon"] * 100) / ($rail["mon"] + $bus["mon"] + $drove_alone["mon"] + $rideshare["mon"] + $carpool["mon"]), 2);
													// $tue_drove_alone = round(($drove_alone["tue"] * 100) / ($rail["tue"] + $bus["tue"] + $drove_alone["tue"] + $rideshare["tue"] + $carpool["tue"]), 2);
													// $wed_drove_alone = round(($drove_alone["wed"] * 100) / ($rail["wed"] + $bus["wed"] + $drove_alone["wed"] + $rideshare["wed"] + $carpool["wed"]), 2);
													// $thu_drove_alone = round(($drove_alone["thu"] * 100) / ($rail["thu"] + $bus["thu"] + $drove_alone["thu"] + $rideshare["thu"] + $carpool["thu"]), 2);
													// $fri_drove_alone = round(($drove_alone["fri"] * 100) / ($rail["fri"] + $bus["fri"] + $drove_alone["fri"] + $rideshare["fri"] + $carpool["fri"]), 2);
													// $sat_drove_alone = round(($drove_alone["sat"] * 100) / ($rail["sat"] + $bus["sat"] + $drove_alone["sat"] + $rideshare["sat"] + $carpool["sat"]), 2);

												?>

												<td><?php //echo $sun_drove_alone; ?></td>
												<td><?php //echo $mon_drove_alone; ?></td>
												<td><?php //echo $tue_drove_alone; ?></td>
												<td><?php //echo $wed_drove_alone; ?></td>
												<td><?php //echo $thu_drove_alone; ?></td>
												<td><?php //echo $fri_drove_alone; ?></td>
												<td><?php //echo $sat_drove_alone; ?></td>
												<td><?php //echo round(($sun_drove_alone + $mon_drove_alone + $tue_drove_alone + $wed_drove_alone + $thu_drove_alone + $fri_drove_alone + $sat_drove_alone) / 7, 2); ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Rideshare (Uber / Lyft)</th>

												<?php

													// $sun_rideshare = round(($rideshare["sun"] * 100) / ($rail["sun"] + $bus["sun"] + $drove_alone["sun"] + $rideshare["sun"] + $carpool["sun"]), 2);
													// $mon_rideshare = round(($rideshare["mon"] * 100) / ($rail["mon"] + $bus["mon"] + $drove_alone["mon"] + $rideshare["mon"] + $carpool["mon"]), 2);
													// $tue_rideshare = round(($rideshare["tue"] * 100) / ($rail["tue"] + $bus["tue"] + $drove_alone["tue"] + $rideshare["tue"] + $carpool["tue"]), 2);
													// $wed_rideshare = round(($rideshare["wed"] * 100) / ($rail["wed"] + $bus["wed"] + $drove_alone["wed"] + $rideshare["wed"] + $carpool["wed"]), 2);
													// $thu_rideshare = round(($rideshare["thu"] * 100) / ($rail["thu"] + $bus["thu"] + $drove_alone["thu"] + $rideshare["thu"] + $carpool["thu"]), 2);
													// $fri_rideshare = round(($rideshare["fri"] * 100) / ($rail["fri"] + $bus["fri"] + $drove_alone["fri"] + $rideshare["fri"] + $carpool["fri"]), 2);
													// $sat_rideshare = round(($rideshare["sat"] * 100) / ($rail["sat"] + $bus["sat"] + $drove_alone["sat"] + $rideshare["sat"] + $carpool["sat"]), 2);

												?>

												<td><?php //echo $sun_rideshare; ?></td>
												<td><?php //echo $mon_rideshare; ?></td>
												<td><?php //echo $tue_rideshare; ?></td>
												<td><?php //echo $wed_rideshare; ?></td>
												<td><?php //echo $thu_rideshare; ?></td>
												<td><?php //echo $fri_rideshare; ?></td>
												<td><?php //echo $sat_rideshare; ?></td>
												<td><?php //echo round(($sun_rideshare + $mon_rideshare + $tue_rideshare + $wed_rideshare + $thu_rideshare + $fri_rideshare + $sat_rideshare) / 7, 2); ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Carpool</th>

												<?php

													// $sun_carpool = round(($carpool["sun"] * 100) / ($rail["sun"] + $bus["sun"] + $drove_alone["sun"] + $rideshare["sun"] + $carpool["sun"]), 2);
													// $mon_carpool = round(($carpool["mon"] * 100) / ($rail["mon"] + $bus["mon"] + $drove_alone["mon"] + $rideshare["mon"] + $carpool["mon"]), 2);
													// $tue_carpool = round(($carpool["tue"] * 100) / ($rail["tue"] + $bus["tue"] + $drove_alone["tue"] + $rideshare["tue"] + $carpool["tue"]), 2);
													// $wed_carpool = round(($carpool["wed"] * 100) / ($rail["wed"] + $bus["wed"] + $drove_alone["wed"] + $rideshare["wed"] + $carpool["wed"]), 2);
													// $thu_carpool = round(($carpool["thu"] * 100) / ($rail["thu"] + $bus["thu"] + $drove_alone["thu"] + $rideshare["thu"] + $carpool["thu"]), 2);
													// $fri_carpool = round(($carpool["fri"] * 100) / ($rail["fri"] + $bus["fri"] + $drove_alone["fri"] + $rideshare["fri"] + $carpool["fri"]), 2);
													// $sat_carpool = round(($carpool["sat"] * 100) / ($rail["sat"] + $bus["sat"] + $drove_alone["sat"] + $rideshare["sat"] + $carpool["sat"]), 2);

												?>

												<td><?php //echo $sun_carpool; ?></td>
												<td><?php //echo $mon_carpool; ?></td>
												<td><?php //echo $tue_carpool; ?></td>
												<td><?php //echo $wed_carpool; ?></td>
												<td><?php //echo $thu_carpool; ?></td>
												<td><?php //echo $fri_carpool; ?></td>
												<td><?php //echo $sat_carpool; ?></td>
												<td><?php //echo round(($sun_carpool + $mon_carpool + $tue_carpool + $wed_carpool + $thu_carpool + $fri_carpool + $sat_carpool) / 7, 2); ?></td>

											</tr>

										</table-->

										<h4 class="text-center">Weekly Commute Percentage</h4>
										<table class="table table-striped" style="color: black;">
											
											<tr class="text-success">
												
												<th>Mode / Day</th>
												<th>Sun</th>
												<th>Mon</th>
												<th>Tue</th>
												<th>Wed</th>
												<th>Thu</th>
												<th>Fri</th>
												<th>Sat</th>
												<th>Weekly Average</th>

											</tr>

											<tr>
												
												<th class="text-success">Metrolink/Rail</th>

												<?php

													$sun_rail_count = round(($rail_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_rail_count = round(($rail_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_rail_count = round(($rail_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_rail_count = round(($rail_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_rail_count = round(($rail_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_rail_count = round(($rail_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_rail_count = round(($rail_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_rail_count; ?></td>
												<td><?php echo $mon_rail_count; ?></td>
												<td><?php echo $tue_rail_count; ?></td>
												<td><?php echo $wed_rail_count; ?></td>
												<td><?php echo $thu_rail_count; ?></td>
												<td><?php echo $fri_rail_count; ?></td>
												<td><?php echo $sat_rail_count; ?></td>
												<td><?php $rail_student_percentage = round(($sun_rail_count + $mon_rail_count + $tue_rail_count + $wed_rail_count + $thu_rail_count + $fri_rail_count + $sat_rail_count) / 7, 2); echo $rail_student_percentage; ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Bus</th>

												<?php

													$sun_bus_count = round(($bus_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_bus_count = round(($bus_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_bus_count = round(($bus_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_bus_count = round(($bus_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_bus_count = round(($bus_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_bus_count = round(($bus_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_bus_count = round(($bus_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_bus_count; ?></td>
												<td><?php echo $mon_bus_count; ?></td>
												<td><?php echo $tue_bus_count; ?></td>
												<td><?php echo $wed_bus_count; ?></td>
												<td><?php echo $thu_bus_count; ?></td>
												<td><?php echo $fri_bus_count; ?></td>
												<td><?php echo $sat_bus_count; ?></td>
												<td><?php $bus_student_percentage = round(($sun_bus_count + $mon_bus_count + $tue_bus_count + $wed_bus_count + $thu_bus_count + $fri_bus_count + $sat_bus_count) / 7, 2); echo $bus_student_percentage; ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Drove Alone / Dropped Off</th>

												<?php

													$sun_drove_alone_count = round(($drove_alone_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_drove_alone_count = round(($drove_alone_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_drove_alone_count = round(($drove_alone_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_drove_alone_count = round(($drove_alone_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_drove_alone_count = round(($drove_alone_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_drove_alone_count = round(($drove_alone_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_drove_alone_count = round(($drove_alone_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_drove_alone_count; ?></td>
												<td><?php echo $mon_drove_alone_count; ?></td>
												<td><?php echo $tue_drove_alone_count; ?></td>
												<td><?php echo $wed_drove_alone_count; ?></td>
												<td><?php echo $thu_drove_alone_count; ?></td>
												<td><?php echo $fri_drove_alone_count; ?></td>
												<td><?php echo $sat_drove_alone_count; ?></td>
												<td><?php $drove_alone_student_percentage = round(($sun_drove_alone_count + $mon_drove_alone_count + $tue_drove_alone_count + $wed_drove_alone_count + $thu_drove_alone_count + $fri_drove_alone_count + $sat_drove_alone_count) / 7, 2); echo $drove_alone_student_percentage; ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Rideshare (Uber / Lyft)</th>

												<?php

													$sun_rideshare_count = round(($rideshare_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_rideshare_count = round(($rideshare_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_rideshare_count = round(($rideshare_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_rideshare_count = round(($rideshare_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_rideshare_count = round(($rideshare_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_rideshare_count = round(($rideshare_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_rideshare_count = round(($rideshare_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_rideshare_count; ?></td>
												<td><?php echo $mon_rideshare_count; ?></td>
												<td><?php echo $tue_rideshare_count; ?></td>
												<td><?php echo $wed_rideshare_count; ?></td>
												<td><?php echo $thu_rideshare_count; ?></td>
												<td><?php echo $fri_rideshare_count; ?></td>
												<td><?php echo $sat_rideshare_count; ?></td>
												<td><?php $rideshare_student_percentage = round(($sun_rideshare_count + $mon_rideshare_count + $tue_rideshare_count + $wed_rideshare_count + $thu_rideshare_count + $fri_rideshare_count + $sat_rideshare_count) / 7, 2); echo $rideshare_student_percentage; ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Carpool</th>

												<?php

													$sun_carpool_count = round(($carpool_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_carpool_count = round(($carpool_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_carpool_count = round(($carpool_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_carpool_count = round(($carpool_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_carpool_count = round(($carpool_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_carpool_count = round(($carpool_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_carpool_count = round(($carpool_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_carpool_count; ?></td>
												<td><?php echo $mon_carpool_count; ?></td>
												<td><?php echo $tue_carpool_count; ?></td>
												<td><?php echo $wed_carpool_count; ?></td>
												<td><?php echo $thu_carpool_count; ?></td>
												<td><?php echo $fri_carpool_count; ?></td>
												<td><?php echo $sat_carpool_count; ?></td>
												<td><?php $carpool_student_percentage = round(($sun_carpool_count + $mon_carpool_count + $tue_carpool_count + $wed_carpool_count + $thu_carpool_count + $fri_carpool_count + $sat_carpool_count) / 7, 2); echo $carpool_student_percentage; ?></td>

											</tr>

											<tr>
												
												<th class="text-success">Did not Commute</th>

												<?php

													$sun_no_commute_count = round(($no_commute_count["sun"] * 100) / ($rail_count["sun"] + $bus_count["sun"] + $drove_alone_count["sun"] + $rideshare_count["sun"] + $carpool_count["sun"] + $no_commute_count["sun"]), 2);
													$mon_no_commute_count = round(($no_commute_count["mon"] * 100) / ($rail_count["mon"] + $bus_count["mon"] + $drove_alone_count["mon"] + $rideshare_count["mon"] + $carpool_count["mon"] + $no_commute_count["mon"]), 2);
													$tue_no_commute_count = round(($no_commute_count["tue"] * 100) / ($rail_count["tue"] + $bus_count["tue"] + $drove_alone_count["tue"] + $rideshare_count["tue"] + $carpool_count["tue"] + $no_commute_count["tue"]), 2);
													$wed_no_commute_count = round(($no_commute_count["wed"] * 100) / ($rail_count["wed"] + $bus_count["wed"] + $drove_alone_count["wed"] + $rideshare_count["wed"] + $carpool_count["wed"] + $no_commute_count["wed"]), 2);
													$thu_no_commute_count = round(($no_commute_count["thu"] * 100) / ($rail_count["thu"] + $bus_count["thu"] + $drove_alone_count["thu"] + $rideshare_count["thu"] + $carpool_count["thu"] + $no_commute_count["thu"]), 2);
													$fri_no_commute_count = round(($no_commute_count["fri"] * 100) / ($rail_count["fri"] + $bus_count["fri"] + $drove_alone_count["fri"] + $rideshare_count["fri"] + $carpool_count["fri"] + $no_commute_count["fri"]), 2);
													$sat_no_commute_count = round(($no_commute_count["sat"] * 100) / ($rail_count["sat"] + $bus_count["sat"] + $drove_alone_count["sat"] + $rideshare_count["sat"] + $carpool_count["sat"] + $no_commute_count["sat"]), 2);

												?>

												<td><?php echo $sun_no_commute_count; ?></td>
												<td><?php echo $mon_no_commute_count; ?></td>
												<td><?php echo $tue_no_commute_count; ?></td>
												<td><?php echo $wed_no_commute_count; ?></td>
												<td><?php echo $thu_no_commute_count; ?></td>
												<td><?php echo $fri_no_commute_count; ?></td>
												<td><?php echo $sat_no_commute_count; ?></td>
												<td><?php echo round(($sun_no_commute_count + $mon_no_commute_count + $tue_no_commute_count + $wed_no_commute_count + $thu_no_commute_count + $fri_no_commute_count + $sat_no_commute_count) / 7, 2); ?></td>

											</tr>

										</table>

										<?php

											$total_student_population = 27000;
											$bus_per_person = 0.056;
											$rail_per_person = 0.119;

											$drove_alone_student_population = intval(($drove_alone_student_percentage * $total_student_population) / 100);
											$rideshare_student_population = intval(($rideshare_student_percentage * $total_student_population) / 100);
											$carpool_student_population = intval(($carpool_student_percentage * $total_student_population) / 100);
											$bus_student_population = intval(($bus_student_percentage * $total_student_population) / 100);
											$rail_student_population = intval(($rail_student_percentage * $total_student_population) / 100);

											$total_student_Emissions = round((round($drove_alone_student_population * $drove_alone_per_person, 2) + round($rideshare_student_population * $rideshare_per_person, 2) + round($carpool_student_population * $carpool_per_person, 2) + round($bus_student_population * $bus_per_person, 2) + round($rail_student_population * $rail_per_person, 2)) * 7, 2);

										?>

									</div>

									<div class="col-md-5 col-12">

										<canvas id="chart33"></canvas>

									</div>

								</div>

								<br /><br />

								<div class='row'>

									<div class="col-8 offset-2">

										<canvas id="chart3"></canvas>

									</div>

								</div>

							</div>

						</div>

					</div>

					<br />

					<div class="container">

						<div class="row">

							<div class="col-8 offset-2">
								
								<hr />

							</div>

						</div>

					</div>

					<br /><br /><br />

					<div class="container">

						<div class="row">

							<div class="col-12 text-center">

								<h3 class="text-success">Annual Average CO<sub>2, e</sub> Emissions Per Commute Mode</h3>

							</div>

						</div>

						<div class="row">

							<div class="col-12">

								<table class="table table-striped" style="color: black;">
									
									<thead>
										
										<th>Commute Mode</th>
										<th>CO<sub>2, e</sub> Emissions (Ton CO<sub>2, e</sub>)</th>

									</thead>

									<tbody>
										
										<tr>

											<td>Drive Alone / Drop Off</td>
											<td><?php echo number_format(($drove_alone_student_population * $drove_alone_per_person * 7) / 1000, 2, '.', ''); ?></td>

										</tr>

										<tr>
											
											<td>Rideshare (Uber / Lyft)</td>
											<td><?php echo number_format(($rideshare_student_population * $rideshare_per_person * 7) / 1000, 2, '.', ''); ?></td>

										</tr>

										<tr>
											
											<td>Carpool</td>
											<td><?php echo number_format(($carpool_student_population * $carpool_per_person * 7) / 1000, 2, '.', ''); ?></td>

										</tr>

										<tr>
											
											<td>Bus</td>
											<td><?php echo number_format(($bus_student_population * $bus_per_person * 7) / 1000, 2, '.', ''); ?></td>

										</tr>

										<tr>
											
											<td>Metrolink/Rail</td>
											<td><?php echo number_format(($rail_student_population * $rail_per_person * 7) / 1000, 2, '.', ''); ?></td>

										</tr>

										<?php

											$student_total_emission = array();

											$student_total_emission["drove_alone"] = $drove_alone_student_population * $drove_alone_per_person * 7;
											$student_total_emission["rideshare"] = $rideshare_student_population * $rideshare_per_person * 7;
											$student_total_emission["carpool"] = $carpool_student_population * $carpool_per_person * 7;
											$student_total_emission["bus"] = $bus_student_population * $bus_per_person * 7;
											$student_total_emission["rail"] = $rail_student_population * $rail_per_person * 7;

										?>

									</tbody>

								</table>

							</div>

						</div>

						<br /><br /><hr /><br /><br />

						<div class="row">

							<div class="col-12 text-center">

								<h3 class="text-success">Annual Average CO<sub>2, e</sub> Emissions</h3>

							</div>

						</div>

						<div class="row">

							<div class="col-12">

								<table class="table table-striped" style="color: black;">
									
									<thead>
										
										<th>Category</th>
										<th>CO<sub>2, e</sub> Emissions (Ton CO<sub>2, e</sub>)</th>
										<th>Percentage Emissions</th>

									</thead>

									<tbody>
										
										<tr>

											<td>Student Emissions</td>
											<td><?php echo number_format($total_student_Emissions / 1000, 2, '.', ''); ?></td>
											<td><?php echo number_format(($total_student_Emissions / ($total_student_Emissions + $total_employee_Emissions)) * 100, 2, '.', ''); ?> %</td>

										</tr>

										<tr>
											
											<td>Faculty &amp; Staff Emissions</td>
											<td><?php echo number_format($total_employee_Emissions / 1000, 2, '.', ''); ?></td>
											<td><?php echo number_format(($total_employee_Emissions / ($total_student_Emissions + $total_employee_Emissions)) * 100, 2, '.', ''); ?> %</td>

										</tr>

									</tbody>

									<tfoot>
										
										<th>Total</th>
										<th><?php echo number_format(($total_student_Emissions + $total_employee_Emissions) / 1000, 2, '.', ''); ?> </th>
										<th><?php echo number_format((($total_student_Emissions + $total_employee_Emissions) / ($total_student_Emissions + $total_employee_Emissions)) * 100, 2, '.', ''); ?> %</th>

									</tfoot>

								</table>

							</div>

						</div>

					</div>

					<br /><br /><br />

					<div class="container">

						<div class="row">

							<div class="col-8 offset-2">
								
								<hr />

							</div>

						</div>

					</div>

					<br />

					<div class="container-fluid">

						<div class="row">

							<div class="col-12">

								<div class="row">

									<div class="col-md-6 col-12">

										<canvas id="chart2"></canvas>

									</div>

									<div class="col-md-6 col-12">

										<canvas id="chart1"></canvas>

									</div>

								</div>

							</div>

						</div>

					</div>

				</section>

				<section class="module module-gray">

					<div class="container">

						<div class="row">

							<div class="col-12 text-center">

								<h3 class="text-success">CO<sub>2, e</sub> Emissions Reduction Measures for Students Commute</h3>

							</div>

						</div>

					</div>

				</section>

				<section class="module">
					
					<div class="container">

						<div class="row">

							<div class="col-md-4 col-6">

								<div class="row">

									<div class="col-12">

										<label>Reduced Drove Alone Percentage</label>
										<select class="form-control" name="drove_alone_reduction_percentage" id="drove_alone_reduction_percentage" onchange="getReducedValue();">

											<option selected disabled value="">Select reduced drove alone percentage</option>
											<option value="5">5 %</option>
											<option value="10">10 %</option>
											<option value="15">15 %</option>
											<option value="20">20 %</option>
											<option value="25">25 %</option>
											<option value="30">30 %</option>
											<option value="35">35 %</option>
											<option value="40">40 %</option>
											<option value="45">45 %</option>
											<option value="50">50 %</option>
											<option value="55">55 %</option>
											<option value="60">60 %</option>
											<option value="65">65 %</option>
											<option value="70">70 %</option>
											<option value="75">75 %</option>
											<option value="80">80 %</option>
											<option value="85">85 %</option>
											<option value="90">90 %</option>
											<option value="95">95 %</option>
											<option value="100">100 %</option>

										</select>

										<br /><br />

										<label name="some_id">Select which commute mode this percentage of drivers will switch to</label>
										<br />
										<input type="radio" name="drove_alone_reduction_percentage_alternate_mode" id="drove_alone_reduction_percentage_alternate_mode" value="0.056" onchange="getReducedValue();" checked /> <label name="some_id">Bus</label>
										<br />
										<input type="radio" name="drove_alone_reduction_percentage_alternate_mode" id="drove_alone_reduction_percentage_alternate_mode" value="0.119" onchange="getReducedValue();" /> <label name="some_id">Metrolink/Rail</label>

									</div>

								</div>

							</div>

						</div>

						<br /><br />

						<div class="row" id="reduction_hidden_row">

							<div class="col-12">

								<table class="table table-bordered" style="color: black;">

									<thead>

										<th>Original CO<sub>2, e</sub> Emissions</th>
										<th>Adjusted CO<sub>2, e</sub> Emissions</th>
										<th>Reduced CO<sub>2, e</sub> Emissions</th>

									</thead>

									<tbody>

										<tr>
											
											<td><?php echo round($total_student_Emissions / 1000, 2); ?> Ton CO<sub>2, e</sub></td>
											<td><span id="adjusted_Emissions_value"></span> Ton CO<sub>2, e</sub></td>
											<td><span id="reduced_Emissions_value"></span> Ton CO<sub>2, e</sub></td>

										</tr>

									</tbody>

								</table>

							</div>

						</div>

						<br /><br /><hr /><br /><br />

						<div class="row">

							<div class="col-md-4 col-6">

								<div class="row">

									<div class="col-12">

										<label>Reduced Gasoline Cars Percentage</label>
										<select class="form-control" name="gasoline_car_reduction_percentage" id="gasoline_car_reduction_percentage" onchange="getReducedValue2();">

											<option selected disabled value="">Select reduced gasoline car percentage</option>
											<option value="5">5 %</option>
											<option value="10">10 %</option>
											<option value="15">15 %</option>
											<option value="20">20 %</option>
											<option value="25">25 %</option>
											<option value="30">30 %</option>
											<option value="35">35 %</option>
											<option value="40">40 %</option>
											<option value="45">45 %</option>
											<option value="50">50 %</option>
											<option value="55">55 %</option>
											<option value="60">60 %</option>
											<option value="65">65 %</option>
											<option value="70">70 %</option>
											<option value="75">75 %</option>
											<option value="80">80 %</option>
											<option value="85">85 %</option>
											<option value="90">90 %</option>
											<option value="95">95 %</option>
											<option value="100">100 %</option>

										</select>
										
										<br /><br />

										<label name="some_id2">Select what type of vehicle will be used instead</label>
										<br />
										<input type="radio" name="gasoline_car_reduction_alternate_mode" id="gasoline_car_reduction_alternate_mode" value="0.177" onchange="getReducedValue2();" checked /> <label name="some_id2">HEV or PHEV</label>
										<br />
										<input type="radio" name="gasoline_car_reduction_alternate_mode" id="gasoline_car_reduction_alternate_mode" value="0.095" onchange="getReducedValue2();" /> <label name="some_id2">Zero Emissions cars</label>

									</div>

								</div>

							</div>

						</div>

						<br /><br />

						<div class="row" id="reduction_hidden_row2">

							<div class="col-12">

								<table class="table table-bordered" style="color: black;">

									<thead>

										<th>Original CO<sub>2, e</sub> Emissions</th>
										<th>Adjusted CO<sub>2, e</sub> Emissions</th>
										<th>Reduced CO<sub>2, e</sub> Emissions</th>

									</thead>

									<tbody>

										<tr>
											
											<td><?php echo round($total_student_Emissions / 1000, 2); ?> Ton CO<sub>2, e</sub></td>
											<td><span id="adjusted_Emissions_value2"></span> Ton CO<sub>2, e</sub></td>
											<td><span id="reduced_Emissions_value2"></span> Ton CO<sub>2, e</sub></td>

										</tr>

									</tbody>

								</table>

							</div>

						</div>

					</div>

				</section>

				<!-- <section class="module-gray module">
					
					<div class="container">

						<div class="row">

							<div class="col-12 text-center">

								<h3 class="text-success"><u>KNOW YOUR COMMUTE'S EMISSIONS</u></h3>

							</div>

						</div>

					</div>

				</section> -->
<!-- 
				<section class="module">

					<div class="container">

						<div class="row">

										<div class="col-md-7 col-12">

											<div class="row">

												<div class="col-md-12 col-12">

													<strong>Origin</strong>
													<input type="text" class="form-control" name="source" id="source" placeholder="Enter Origin" required />

												</div>

											</div>

											<br />

											<div class="row">

												<div class="col-md-12 col-12">

													<strong>Destination</strong>
													<input type="text" class="form-control" name="destination" id="destination" placeholder="Enter Destination" required />

												</div>

											</div>

											<br />

											<div class="row">

												<div class="col-md-6 col-12">

													<strong>Vehicle Efficiency (Miles / Gallon)</strong>
													<input type="number" class="form-control" name="car_miles" id="car_miles" min="1" value='5' max="50" placeholder="Enter Miles/Gallon" required />

												</div>

												<div class="col-md-6 col-12">

													<strong>Number of Trips / week</strong>
													<input type="number" class="form-control" name="car_trips" id="car_trips" min="1" value='1' max="15" placeholder="Enter Number of Trips/week" required />

												</div>

											</div>

											<br />

											<div class="row">

												<div class="col-12">

													<strong>Vehicle Type</strong>
													<br />

												</div>

												<div class="col-md-3">
													
													<input type="radio" name="vehicle_type" id="vehicle_type_gasoline" onchange="getLocationMap();" checked> Gasoline

												</div>

												<div class="col-md-3">
													
													<input type="radio" name="vehicle_type" id="vehicle_type_zev" onchange="getLocationMap();"> Zero Emissions

												</div>

												<div class="col-md-3">
													
													<input type="radio" name="vehicle_type" id="vehicle_type_hybrid" onchange="getLocationMap();"> Plug-In Hybrid

												</div>

												<div class="col-md-3">
													
													<input type="radio" name="vehicle_type" id="vehicle_type_mc" onchange="getLocationMap();"> Motorcycle

												</div>

											</div>

										</div>

										<div class="col-md-5 col-12" id="map_canvas">

											<center><div id="map_chart" style="width: 600px; height: 300px;"></div></center>

										</div>

									</div>

									<br /><br />

									<div class="row" id="datatable">

										<div class="col-8 offset-2">

											<table class="table table-striped table-light" width="100%" style="color: black;">
												
												<tr>
													
													<th>Number of Miles (One-Way)<br />(<i>Source to destination</i>)</th>
													<td><span id="display_distance"></span> Miles</td>

												</tr>
												
												<tr>
													
													<th>Number of Miles (Round-Trip)</th>
													<td><span id="display_total_distance"></span> Miles</td>

												</tr>

												<tr>
													
													<th>Fuel Consumed / Round-Trip</th>
													<td><span id="trip_fuel"></span> Gallons</td>

												</tr>

												<tr>
													
													<th>Fuel Consumed / Week</th>
													<td><span id="week_fuel"></span> Gallons</td>

												</tr>

												<tr>
													
													<th>CO<sub>2</sub> Emissions / Week</th>
													<td><span id="week_energy"></span> KG CO<sub>2</sub></td>

												</tr>


											</table>

										</div>

									</div>

					</div>

				</section> -->

				<?php include "includes/footer.php"; ?>

				<a class="scroll-top" href="#top"><i class="fa fa-angle-up"></i></a>

			</div>

			<?php

				function js_str($s) {

				    return '"' . addcslashes($s, "\0..\37\"\\") . '"';

				}

				function js_array($array) {

				    $temp = array_map('js_str', $array);
				    return '[' . implode(',', $temp) . ']';

				}

				$energy_consumption_category = array();
				array_push($energy_consumption_category, number_format($drove_alone_per_person, 2, '.', ''));
				array_push($energy_consumption_category, number_format($rideshare_per_person, 2, '.', ''));
				array_push($energy_consumption_category, number_format($carpool_per_person, 2, '.', ''));
				array_push($energy_consumption_category, number_format($rail_per_person, 2, '.', ''));
				array_push($energy_consumption_category, number_format($bus_per_person, 2, '.', ''));
					

				echo '<script>var energy_consumption_category = ', js_array($energy_consumption_category), ';</script>';

				$energy_consumption_category_percentage = array();
				array_push($energy_consumption_category_percentage, number_format(($total_energy["drove_alone"] * 100 / array_sum($total_energy)), 2, '.', ''));
				array_push($energy_consumption_category_percentage, number_format(($total_energy["rideshare"] * 100 / array_sum($total_energy)), 2, '.', ''));
				array_push($energy_consumption_category_percentage, number_format(($total_energy["carpool"] * 100 / array_sum($total_energy)), 2, '.', ''));
				array_push($energy_consumption_category_percentage, number_format(($total_energy["metrolink"] * 100 / array_sum($total_energy)), 2, '.', ''));
				array_push($energy_consumption_category_percentage, number_format(($total_energy["bus"] * 100 / array_sum($total_energy)), 2, '.', ''));
					

				echo '<script>var energy_consumption_category_percentage = ', js_array($energy_consumption_category_percentage), ';</script>';

				echo '<script>var student_total_emission = ', js_array($student_total_emission), ';</script>';

				echo "<script>
					var student_contribution = ",number_format(($total_student_Emissions / ($total_employee_Emissions + $total_student_Emissions)) * 100, 2, '.', ''),";
					var faculty_contribution = ",number_format(($total_employee_Emissions / ($total_employee_Emissions + $total_student_Emissions)) * 100, 2, '.', ''),";
					</script>";

				echo "<script>
					var drove_alone_student_percentage = ",number_format($drove_alone_student_percentage, 2, '.', ''),";
					var rideshare_student_percentage = ",number_format($rideshare_student_percentage, 2, '.', ''),";
					var carpool_student_percentage = ",number_format($carpool_student_percentage, 2, '.', ''),";
					var rail_student_percentage = ",number_format($rail_student_percentage, 2, '.', ''),";
					var bus_student_percentage = ",number_format($bus_student_percentage, 2, '.', ''),";

					var drove_alone_student_count = ",$drove_alone_student_population,";
					var rideshare_student_count = ",$rideshare_student_population,";
					var carpool_student_count = ",$carpool_student_population,";
					var rail_student_count = ",$rail_student_population,";
					var bus_student_count = ",$bus_student_population,";

					var student_energy = ",$total_student_Emissions,";

					</script>";

			?>

			<script type="text/javascript">

				$(document).ready(function() {

					$("#reduction_hidden_row").hide();
					$("#reduction_hidden_row2").hide();
					$("input[name=drove_alone_reduction_percentage_alternate_mode]").hide();
					$("label[name=some_id]").hide();
					$("input[name=gasoline_car_reduction_alternate_mode]").hide();
					$("label[name=some_id2]").hide();

				});

				function getReducedValue() {

					var reduced_percentage = $("#drove_alone_reduction_percentage").val();
					var mode = $("input[name=drove_alone_reduction_percentage_alternate_mode]:checked").val();
					var rdac = Math.floor(drove_alone_student_count * reduced_percentage / 100);

					var adjusted_energy = (reduced_percentage / 100) * student_total_emission[0] * (mode / 0.343);
					adjusted_energy = student_energy - ((reduced_percentage / 100) * student_total_emission[0]) + adjusted_energy;

					$("#adjusted_Emissions_value").html(Math.round( adjusted_energy * 0.1 ) / 100);
					$("#reduced_Emissions_value").html(Math.round( (student_energy - adjusted_energy) * 0.1 ) / 100);

					$("input[name=drove_alone_reduction_percentage_alternate_mode]").show();
					$("label[name=some_id]").show();
					$("#reduction_hidden_row").show();

				}

				function getReducedValue2() {

					var reduced_percentage = $("#gasoline_car_reduction_percentage").val();
					var mode = $("input[name=gasoline_car_reduction_alternate_mode]:checked").val();
					var rdac = Math.floor(drove_alone_student_count * reduced_percentage / 100);

					var adjusted_energy = (reduced_percentage / 100) * student_total_emission[0] * (mode / 0.343);
					adjusted_energy = student_energy - ((reduced_percentage / 100) * student_total_emission[0]) + adjusted_energy;

					$("#adjusted_Emissions_value2").html(Math.round( adjusted_energy * 0.1 ) / 100);
					$("#reduced_Emissions_value2").html(Math.round( (student_energy - adjusted_energy) * 0.1 ) / 100);

					$("input[name=gasoline_car_reduction_alternate_mode]").show();
					$("label[name=some_id2]").show();
					$("#reduction_hidden_row2").show();

				}

				var ctx = document.getElementById('chart1').getContext('2d');

				var myLineChart = new Chart(ctx, {

				    type: 'doughnut',
				    data: {
				        labels: ['Student', 'Faculty / Staff'],
				        datasets: [{

				            label: 'Percentage CO2, e (%)',
				            backgroundColor: ['rgb(255, 153, 51)', 'rgb(255, 99, 132)'],
				            //borderColor: 'rgb(255, 99, 132)',
				            data: [student_contribution, faculty_contribution],
				            fill: false

				        }]
				    },
				    options: {

				    	title: {
				    		display: true,
				    		position: 'top',
				    		text: 'Percentage CO2, e (%)'
				    	},
				    	legend: {

				    		display: true,
				    		position: 'bottom'

				    	}

				    }

				});
				
				var ctx = document.getElementById('chart2').getContext('2d');

				var myLineChart = new Chart(ctx, {

				    type: 'pie',
				    data: {
				        labels: ['Drove Alone / Dropped Off', 'Rideshare (Uber / Lyft)', 'Carpool', 'Metrolink/Rail', 'Bus'],
				        datasets: [{

				            //label: 'Percentage Carbon Emissions (%)',
				            backgroundColor: ['rgb(255, 153, 51)', 'rgb(160, 160, 160)', 'rgb(153, 255, 51)', 'rgb(51, 153, 255)', 'rgb(153, 51, 255)'],
				            //borderColor: 'rgb(255, 99, 132)',
				            data: energy_consumption_category_percentage,
				            fill: false

				        }]
				    },
				    options: {

				    	title: {
				    		display: true,
				    		position: 'top',
				    		text: 'Percentage Carbon Emissions (%)'
				    	},
				    	legend: {

				    		display: true,
				    		position: 'bottom'

				    	}

				    }

				});

				var ctx = document.getElementById('chart3').getContext('2d');

				var myLineChart = new Chart(ctx, {

				    type: 'horizontalBar',
				    data: {
				        labels: ['Drove Alone / Dropped Off', 'Rideshare (Uber / Lyft)', 'Carpool', 'Metrolink/Rail', 'Bus'],
				        datasets: [{

				            label: 'CO2, e Emissions (Kg CO2, e)',
				            backgroundColor: 'rgb(255, 99, 132)',
				            borderColor: 'rgb(255, 99, 132)',
				            data: energy_consumption_category,
				            fill: false

				        }]
				    },
				    options: {

				    	title: {
				    		display: true,
				    		position: 'top',
				    		text: 'Weekly Average CO2, e Emissions / Commute Mode'
				    	},
				    	legend: {

				    		display: true,
				    		position: 'bottom'

				    	},
				    	scales: {
				    		
				    		yAxes: [{
				      			
				      			scaleLabel: {
				        			
				        			display: true,
				        			labelString: 'Commute Mode'
				      			
				      			}
				    		
				    		}],
				    		xAxes: [{
				      			
				      			scaleLabel: {
				        			
				        			display: true,
				        			labelString: 'Average KG CO2 per Commute Mode',
				        			ticks: {

						                min: 0,
            							max: 100,
            							stepSize: 5

						            }
				      			
				      			}
				    		
				    		}]
				  		
				  		}
				    
				    }

				});

				var ctx = document.getElementById('chart33').getContext('2d');

				var myDoughnutChart = new Chart(ctx, {

				    type: 'doughnut',
				    data: {
				        labels: ['Drove Alone / Dropped Off', 'Rideshare', 'Carpool', 'Metrolink/Rail', 'Bus', 'Did not commute'],
				        datasets: [{

				            label: 'Percentage (%)',
				            backgroundColor: ['rgb(255, 153, 51)', 'rgb(160, 160, 160)', 'rgb(153, 255, 51)', 'rgb(51, 153, 255)', 'rgb(153, 51, 255)', 'rgb(160, 25, 51)'],
				            //borderColor: 'rgb(255, 99, 132)',
				            data: [27.25, 2.03, 2.08, 4.41, 21.42, 42.82],
				            fill: false

				        }]
				    },
				    options: {

				    	title: {
				    		display: true,
				    		position: 'top',
				    		text: 'Average Weekly Commuter Percentage'
				    	},
				    	legend: {

				    		display: true,
				    		position: 'bottom'

				    	}

				    }

				});

			</script>

			<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyABKW379vMBY_CCHQ1OGxom15J4pTWi9WA&libraries=places"></script>

			<script type="text/javascript">

				$(document).ready(function() {

					$("#map_canvas").hide();
					$("#datatable").hide();

				});

				var source = null;
				var destination = null;
				var bounds = new google.maps.LatLngBounds();
				var distance = 0.0;
				var efficiency = 5;
				var trips = 1;
				var gasoline_value = 33.70;
				var diesel_value = 14.00;
				var hybrid_value = 33.70;
				var electric_value = 1.00;

				$("#car_miles").keyup(function() {

					if($("#car_miles").val() != "") {

						efficiency = parseFloat($("#car_miles").val());

						getLocationMap();
					
					}

				});

				$("#car_trips").keyup(function() {

					if($("#car_trips").val() != "") {

						trips = parseInt($("#car_trips").val());

						getLocationMap();

					}

				});

				$("#car_miles").change(function() {

					if($("#car_miles").val() != "") {

						efficiency = parseFloat($("#car_miles").val());

						getLocationMap();
					
					}

				});

				$("#car_trips").change(function() {

					if($("#car_trips").val() != "") {

						trips = parseInt($("#car_trips").val());

						getLocationMap();

					}

				});

				var sourceSearchBox = new google.maps.places.SearchBox(document.getElementById("source"));

				google.maps.event.addListener(sourceSearchBox, 'places_changed', function() {

					getLocationMap();

				});

				var destinationSearchBox = new google.maps.places.SearchBox(document.getElementById("destination"));

				google.maps.event.addListener(destinationSearchBox, 'places_changed', function() {

					getLocationMap();

				});

				function getLocationMap() {

					if($("#source").val() != "" && $("#destination").val() != "") {

						bounds = new google.maps.LatLngBounds();

						source = sourceSearchBox.getPlaces();
						destination = destinationSearchBox.getPlaces();

						var i, place;

						var map = new google.maps.Map(document.getElementById("map_chart"), {

							center:{

								lat: 34.066,
								lng: -118.168
							},
							scrollwheel: false,
							draggable: false

						});

						var sourceMarker =  new google.maps.Marker({

							map: map,
							draggable: false

						});

						var destinationMarker =  new google.maps.Marker({

							map: map,
							draggable: false

						});

						for(i = 0; place = source[i]; i++) {

							bounds.extend(place.geometry.location);
							sourceMarker.setPosition(place.geometry.location);

						}

						for(i = 0; place = destination[i]; i++) {

							bounds.extend(place.geometry.location);
							destinationMarker.setPosition(place.geometry.location);

						}

						map.fitBounds(bounds);

						$("#source_text").html($("#source").val());
						$("#destination_text").html($("#destination").val());

						var source = $("#source").val();
						var destination = $("#destination").val();

						var service = new google.maps.DistanceMatrixService();
						service.getDistanceMatrix({

						    origins: [source],
						    destinations: [destination],
						    travelMode: 'DRIVING',
						    unitSystem: google.maps.UnitSystem.IMPERIAL

						  }, callback);

						function callback(response, status) {

							response = response['rows'][0];

							distance = response['elements'][0]['distance']['text'];

							distance = distance.split(" ");

							distance = parseFloat(distance[0]);

							$("#display_distance").html(distance.toFixed(2));
							$("#display_total_distance").html((distance * 2).toFixed(2));
							$("#trip_fuel").html(((distance * 2) / efficiency).toFixed(2));
							$("#week_fuel").html((((distance * 2) / efficiency) * trips).toFixed(2));

							if($('#vehicle_type_gasoline').prop('checked'))
								$("#week_energy").html(((((distance * 2) / efficiency) * trips) * 0.343).toFixed(2));
							else if($('#vehicle_type_zev').prop('checked'))
								$("#week_energy").html(((((distance * 2) / efficiency) * trips) * 0.095).toFixed(2));
							else if($('#vehicle_type_hybrid').prop('checked'))
								$("#week_energy").html(((((distance * 2) / efficiency) * trips) * 0.177).toFixed(2));
							else if($('#vehicle_type_mc').prop('checked'))
								$("#week_energy").html(((((distance * 2) / efficiency) * trips) * 0.189).toFixed(2));

						}

						$("#map_canvas").show();
						$("#datatable").show();

					}

				}

				document.addEventListener('contextmenu', event => event.preventDefault());

			</script>

		</div>

	</body>

</html>