<commit_before><?php 
require_once("utilities.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
if (hasParam('id')) {
    $projectId = paramInt('id');
} else {
    include('project_tiles.php');
    return;
}

$donorId = 0;
if (hasParam('d')) {
  $donorId = paramInt('d');
}

if (!CACHING_ENABLED || !file_exists(CACHED_PROJECT_PREFIX.$projectId.'d'.$donorId)) {
    ob_start();
$stmt = prepare("SELECT project_id, village_id, project_name, similar_pictures.picture_filename AS similar_picture, banner_pictures.picture_filename AS banner_picture, 
                project_summary, project_community_problem, project_community_solution, project_community_partners, project_impact, village_name, village_lat, village_lng, 
                project_funded, project_budget, project_type, project_staff_id, COUNT(DISTINCT pe_id) AS eventCount, COUNT(DISTINCT donation_donor_id) AS donorCount,
                CONCAT(donor_first_name, ' ', donor_last_name) AS matchingDonor, project_completion, project_youtube_id, exemplary_pictures.picture_filename AS exemplaryPicture, pu_description
                FROM projects JOIN villages ON village_id=project_village_id 
                LEFT JOIN pictures AS similar_pictures ON project_similar_image_id=similar_pictures.picture_id 
                LEFT JOIN pictures AS banner_pictures ON project_banner_image_id=banner_pictures.picture_id 
                LEFT JOIN project_events ON pe_project_id=project_id 
                LEFT JOIN donors ON project_matching_donor=donor_id 
                LEFT JOIN project_updates ON pu_project_id=project_id AND pu_exemplary=1 LEFT JOIN pictures AS exemplary_pictures ON pu_image_id=exemplary_pictures.picture_id
                LEFT JOIN ((SELECT donation_donor_id, donation_project_id FROM donations WHERE donation_project_id=? AND donation_is_test=0) 
                        UNION (SELECT sd_donor_id AS donation_donor_id, sd_project_id AS donation_project_id FROM subscription_disbursals WHERE sd_project_id=?)) AS derived ON donation_project_id=project_id
                WHERE project_id=? GROUP BY project_id");
$stmt->bind_param('iii', $projectId, $projectId, $projectId);
$result = execute($stmt);
if ($row = $result->fetch_assoc()) {
    $projectName = $row['project_name'];
    $pictureFilename = $row['similar_picture'];
    $bannerPicture = $row['banner_picture'];
    $summary = $row['project_summary'];
    $problem = $row['project_community_problem'];
    $solution = $row['project_community_solution'];
    $partners = $row['project_community_partners'];
    $completion = $row['project_completion'];
    $videoId = $row['project_youtube_id'];
    $impact = $row['project_impact'];
    $villageId = $row['village_id'];
    $villageName = $row['village_name'];
    $villageLat = $row['village_lat'];
    $villageLng = $row['village_lng'];
    $funded = round($row['project_funded']);
    $total = $row['project_budget'];
    $projectType = $row['project_type'];
    $staffId = $row['project_staff_id'];
    $hasEvents = $row['eventCount'] > 0;
    $donorCount = $row['donorCount'];
    $matchingDonor = $row['matchingDonor'];
    $exemplaryPicture = $row['exemplaryPicture'];
    $exemplaryDescription = $row['pu_description'];
    
    $villageContribution = round($total * .05);
    $percentFunded = max(5, round($funded * 100 / $total));
    
    $households = getLatestValueForStat($villageId, "# of HH");
    $population = getLatestValueForStat($villageId, "# of People");
} else {
    print "The requested project could not be found.";
    die(1);
}
$stmt->close();

?>
<meta property="fb:appid" content="<?php print FACEBOOK_APP_ID; ?>"/>
<meta property="og:image" content="<?php print PICTURES_DIR.$bannerPicture; ?>"/>
<meta property="og:title" content="Fund Projects Villages Choose: <?php print $projectName; ?> in <?php print $villageName; ?> Village"/>
<meta property="og:url" content="<?php print BASE_URL.$projectId; ?>"/>
<meta property="og:description" content="Disrupt extreme poverty by funding projects villages choose. <?php print $summary; ?>"/>
<?php 
$metaProvided = 1;
 include('header.inc'); 
?>
<script>
$(document).ready(function(){
    $('.scrollspy').scrollSpy();
  });
</script>
<div id="index-banner" class="parallax-container"
	style="background-color: rgba(0, 0, 0, 0.3); height: 500px">

	<div class="parallax">
		<img style="object-fit: cover; height:100%" src="<?php print PICTURES_DIR.$bannerPicture; ?>">
	</div>

<?php
  $stmt = prepare("SELECT project_id, YEAR(pe_date) AS yearPosted FROM projects JOIN project_events ON project_village_id=? AND project_id<>? AND pe_project_id=project_id AND pe_type=1 ORDER BY yearPosted DESC");
  $stmt->bind_param('ii', $villageId, $projectId);
  $result = execute($stmt);
  $count = 0;
  while ($row = $result->fetch_assoc()) {
    $otherYearProjectId = $row['project_id'];
    $otherYearPosted = $row['yearPosted'];
?>

  <div onclick="document.location='<?php print $otherYearProjectId; ?>';" style='position:absolute; border: 8px solid #55C4F5; border-radius:75px; width:80px;height:80px;right:<?php print ($count * 100 + 10); ?>px;bottom:10px;cursor:pointer;box-shadow: 10px 10px 60px -10px #55C4F5;'>
    <span style='position:absolute;font-weight:bolder;font-size:24px;top:33px;left:5px;color:#55C4F5'><?php print $otherYearPosted; ?></span>  
  </div>
<?php 
  $count++;
} 
$stmt->close(); ?>
</div>

<div class="container">
	
		<div><h4 class="header left brown-text text-lighten-2 text-shadow: 2px 2px 7px #111111">
					<a href='https://api.mapbox.com/styles/v1/jdepree/cj37ll51d00032smurmbauiq4/static/<?php print "$villageLng,$villageLat"; ?>,17,0,60.00/800x600?access_token=<?php print MAPBOX_API_KEY; ?>' data-imagelightbox="map" style='font-weight:bold;color:#654321'><?php print $villageName; ?> Village</a> needs $<?php print $total; ?> to <?php print strtolower($projectName); ?>. This project will help <?php print $population; ?> people across <?php print $households; ?> households. <?php print $villageName; ?> has contributed $<?php print $villageContribution; ?>, materials, and labor.
		</h4>

<script>
			var instanceMap = $( 'a[data-imagelightbox="map"]' ).imageLightbox(
			{
				onLoadStart: function() { activityIndicatorOn(); },
				onLoadEnd:	 function() { activityIndicatorOff(); },
				onEnd:		 function() { activityIndicatorOff(); }
			});
</script>	<commit_msg>Background image for past year badges<commit_after><?php 
require_once("utilities.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
if (hasParam('id')) {
    $projectId = paramInt('id');
} else {
    include('project_tiles.php');
    return;
}

$donorId = 0;
if (hasParam('d')) {
  $donorId = paramInt('d');
}

if (!CACHING_ENABLED || !file_exists(CACHED_PROJECT_PREFIX.$projectId.'d'.$donorId)) {
    ob_start();
$stmt = prepare("SELECT project_id, village_id, project_name, similar_pictures.picture_filename AS similar_picture, banner_pictures.picture_filename AS banner_picture, 
                project_summary, project_community_problem, project_community_solution, project_community_partners, project_impact, village_name, village_lat, village_lng, 
                project_funded, project_budget, project_type, project_staff_id, COUNT(DISTINCT pe_id) AS eventCount, COUNT(DISTINCT donation_donor_id) AS donorCount,
                CONCAT(donor_first_name, ' ', donor_last_name) AS matchingDonor, project_completion, project_youtube_id, exemplary_pictures.picture_filename AS exemplaryPicture, pu_description
                FROM projects JOIN villages ON village_id=project_village_id 
                LEFT JOIN pictures AS similar_pictures ON project_similar_image_id=similar_pictures.picture_id 
                LEFT JOIN pictures AS banner_pictures ON project_banner_image_id=banner_pictures.picture_id 
                LEFT JOIN project_events ON pe_project_id=project_id 
                LEFT JOIN donors ON project_matching_donor=donor_id 
                LEFT JOIN project_updates ON pu_project_id=project_id AND pu_exemplary=1 LEFT JOIN pictures AS exemplary_pictures ON pu_image_id=exemplary_pictures.picture_id
                LEFT JOIN ((SELECT donation_donor_id, donation_project_id FROM donations WHERE donation_project_id=? AND donation_is_test=0) 
                        UNION (SELECT sd_donor_id AS donation_donor_id, sd_project_id AS donation_project_id FROM subscription_disbursals WHERE sd_project_id=?)) AS derived ON donation_project_id=project_id
                WHERE project_id=? GROUP BY project_id");
$stmt->bind_param('iii', $projectId, $projectId, $projectId);
$result = execute($stmt);
if ($row = $result->fetch_assoc()) {
    $projectName = $row['project_name'];
    $pictureFilename = $row['similar_picture'];
    $bannerPicture = $row['banner_picture'];
    $summary = $row['project_summary'];
    $problem = $row['project_community_problem'];
    $solution = $row['project_community_solution'];
    $partners = $row['project_community_partners'];
    $completion = $row['project_completion'];
    $videoId = $row['project_youtube_id'];
    $impact = $row['project_impact'];
    $villageId = $row['village_id'];
    $villageName = $row['village_name'];
    $villageLat = $row['village_lat'];
    $villageLng = $row['village_lng'];
    $funded = round($row['project_funded']);
    $total = $row['project_budget'];
    $projectType = $row['project_type'];
    $staffId = $row['project_staff_id'];
    $hasEvents = $row['eventCount'] > 0;
    $donorCount = $row['donorCount'];
    $matchingDonor = $row['matchingDonor'];
    $exemplaryPicture = $row['exemplaryPicture'];
    $exemplaryDescription = $row['pu_description'];
    
    $villageContribution = round($total * .05);
    $percentFunded = max(5, round($funded * 100 / $total));
    
    $households = getLatestValueForStat($villageId, "# of HH");
    $population = getLatestValueForStat($villageId, "# of People");
} else {
    print "The requested project could not be found.";
    die(1);
}
$stmt->close();

?>
<meta property="fb:appid" content="<?php print FACEBOOK_APP_ID; ?>"/>
<meta property="og:image" content="<?php print PICTURES_DIR.$bannerPicture; ?>"/>
<meta property="og:title" content="Fund Projects Villages Choose: <?php print $projectName; ?> in <?php print $villageName; ?> Village"/>
<meta property="og:url" content="<?php print BASE_URL.$projectId; ?>"/>
<meta property="og:description" content="Disrupt extreme poverty by funding projects villages choose. <?php print $summary; ?>"/>
<?php 
$metaProvided = 1;
 include('header.inc'); 
?>
<script>
$(document).ready(function(){
    $('.scrollspy').scrollSpy();
  });
</script>
<div id="index-banner" class="parallax-container"
	style="background-color: rgba(0, 0, 0, 0.3); height: 500px">

	<div class="parallax">
		<img style="object-fit: cover; height:100%" src="<?php print PICTURES_DIR.$bannerPicture; ?>">
	</div>

<?php
  $stmt = prepare("SELECT project_id, YEAR(pe_date) AS yearPosted, exemplary_pictures.picture_filename AS exemplaryPicture, 
      similar_pictures.picture_filename AS similar_picture
      FROM projects JOIN project_events ON project_village_id=? AND project_id<>? 
      AND pe_project_id=project_id AND pe_type=1
      LEFT JOIN pictures AS similar_pictures ON project_similar_image_id=similar_pictures.picture_id 
      LEFT JOIN project_updates ON pu_project_id=project_id AND pu_exemplary=1
      LEFT JOIN pictures AS exemplary_pictures ON pu_image_id=exemplary_pictures.picture_id
      ORDER BY yearPosted DESC");
  $stmt->bind_param('ii', $villageId, $projectId);
  $result = execute($stmt);
  $count = 0;
  while ($row = $result->fetch_assoc()) {
    $otherYearProjectId = $row['project_id'];
    $otherYearPosted = $row['yearPosted'];
    $otherYearPictureFilename = $row['similar_picture'];
    $otherYearExemplaryPicture = $row['exemplaryPicture'];
?>

  <div onclick="document.location='<?php print $otherYearProjectId; ?>';" style="position:absolute; border: 2px solid #55C4F5; border-radius:75px; width:80px;height:80px;right:<?php print ($count * 100 + 10); ?>px;
        bottom:10px;cursor:pointer;box-shadow: 10px 10px 60px -10px #55C4F5;
        background:url('<?php print PICTURES_DIR.($otherYearExemplaryPicture ? $otherYearExemplaryPicture : $otherYearPictureFilename); ?>');background-size:80px 80px;">
    <span style='position:absolute;font-weight:bolder;font-size:24px;top:40px;left:10px;color:#DDDDDD'><?php print $otherYearPosted; ?></span>  
  </div>
<?php 
  $count++;
} 
$stmt->close(); ?>
</div>

<div class="container">
	
		<div><h4 class="header left brown-text text-lighten-2 text-shadow: 2px 2px 7px #111111">
					<a href='https://api.mapbox.com/styles/v1/jdepree/cj37ll51d00032smurmbauiq4/static/<?php print "$villageLng,$villageLat"; ?>,17,0,60.00/800x600?access_token=<?php print MAPBOX_API_KEY; ?>' data-imagelightbox="map" style='font-weight:bold;color:#654321'><?php print $villageName; ?> Village</a> needs $<?php print $total; ?> to <?php print strtolower($projectName); ?>. This project will help <?php print $population; ?> people across <?php print $households; ?> households. <?php print $villageName; ?> has contributed $<?php print $villageContribution; ?>, materials, and labor.
		</h4>

<script>
			var instanceMap = $( 'a[data-imagelightbox="map"]' ).imageLightbox(
			{
				onLoadStart: function() { activityIndicatorOn(); },
				onLoadEnd:	 function() { activityIndicatorOff(); },
				onEnd:		 function() { activityIndicatorOff(); }
			});
</script>	
{'fraction_non_alphanumeric': 0.14491248887570454, 'fraction_numerical': 0.015870661524770097, 'mean_word_length': 5.074324324324325, 'pattern_counts': {'":': 0, '<': 108, '<?xml version=': 0, '>': 122, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '593438', 'n_tokens_mistral': 4771, 'n_tokens_neox': 4291, 'n_words': 914}