<commit_before><?php require_once 'init.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/navigation.php'; ?>


<?php if (!securePage($_SERVER['PHP_SELF'])){die();} ?>
<?php
$validation = new Validate ();
// PHP Goes Here!
$errors = [ ];
$successes = [ ];
$donationId = Input::get ( 'id' );
// Check if selected user exists
if (! donationIdExists ( $donationId )) {
	Redirect::to ( "../index.php" );
	die ();
}

$token = Input::get('csrf');
if(Input::exists()){
	if(!Token::check($token)){
		die('Token doesn\'t match!');
	}
}



$donationDetails = fetchDonationDetails ( $donationId );
$date = $donationDetails->date;
$cdate = $donationDetails->created_at;
$amount = $donationDetails->amount;
$dtype = $donationDetails->dtype;
$company = $donationDetails->company;
$comment = $donationDetails->comment;
$donationId = $donationDetails->id;
$visibility = $donationDetails->visibility;

$userId = $donationDetails->user_id;
$userdetails = fetchUserDetails ( NULL, NULL, $userId ); // Fetch user details

$loggedInUserId = $user->data ()->id;
if ($loggedInUserId != $userId &&!checkMenu(2,$user->data()->id)) {
	// not your donation. You cannot access it.
	Redirect::to ( "../index.php" );
	die ();
}

//Forms posted
if (!empty($_POST) && !empty($_POST["email"])) {
	echo "sending email";
	$subject = "Your donation receipt #$donationId";
	$options = array(
			'fname' => $userdetails->fname,
			'lname' => $userdetails->lname,
	);
	$body =  email_body('_receipt.php',$options);
	$attachment = array(
			"data" => Input::get("pdfdata"),
			"filename" => receiptFileName($donationDetails, $userdetails) . "pdf",
			"encoding" => "base64", "type" => "application/pdf"
	);
	
	$email_sent=email($userdetails->email,$subject,$body, $attachment);
	
	if(!$email_sent){
		$errors[] = 'Email NOT sent due to error. Please contact site administrator.';
	} else {
		$successes[] ="Successfully sent receipt to $userdetails->email.";
	}
}

?>
<div id="page-wrapper">

	<div class="container">

			<div class="row">
				<div class="col-md-12">
          <?php
										
										echo resultBlock ( $errors, $successes );
										?>
		<div class="row">
			<div class="col-xs-3 text-center">
			<form class="form-signup" action="donation_receipt.php?id=<?=$donationId?>" method="POST" id="payment-form">
				<label> &nbsp; </label>
				<input class='btn btn-primary print-receipt' type='submit'
												name='print' value='Print' />
												<label>&nbsp;</label>
												
				<input class='btn btn-primary download-receipt' type='submit'
												name='download' value='Download' />
												<label>&nbsp;</label>
				<input class='btn btn-primary email-receipt' type='submit'
												name='email' value='Email' />
												<label>&nbsp;</label>
				<input type="hidden" id="pdfdata" name="pdfdata" value="Mickey Mouse">
				<input type="hidden" value="<?=Token::generate();?>" name="csrf">
			</form>
			</div>
			<div class="col-xs-9 text-center">
			<iframe class="preview-pane" type="application/pdf"  width="600" height="900" frameborder="0" style="position:relative;z-index:999">
			</iframe>
			</div>
			
		</div>
	</div>
</div>




<?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>

<!-- Place any per-page javascript here -->
<script src="../js/jspdf.debug.js"></script>
<script src="../js/from_html.js"></script>
<script src="../js/autoprint.js"></script>
<script src="../js/split_text_to_size.js"></script>
<script src="../js/standard_fonts_metrics.js"></script>
<script>

var doc;
	
function getDoc() {
	doc=new jsPDF('p', 'mm', 'letter');
	
	doc.setFontType("bold");
	doc.setFontSize(14);
	doc.text(25, 34, "Charitable Donation Receipt");

	doc.setFontType("normal");
	doc.setFontSize(11);
	
	doc.text(25, 40, 'Issued on: <?=mysql2DateString(substr($cdate, 0, 10))?>');

	doc.setFontType("bold");
	doc.text(25, 50, 'Ping Pong Community');

	doc.setFontType("normal");
	doc.text(25, 56, '3273 Falerno Way');
	doc.text(25, 62, 'San Jose, CA 95135');
	doc.text(25, 68, 'Tel: 408-915-7464');
	doc.text(25, 74, 'Email: <EMAIL>');
	doc.text(25, 80, 'EIN#: 81-2451936');

	
	doc.text(25, 92, 'We acknowledge, with thanks, the receipt of following contributions from');

	doc.setFontType('bold');
	doc.text(150, 92, '<?php echo "$userdetails->fname $userdetails->lname"?>:');

	doc.setFontType('normal');
	doc.text(25, 102, 'No.');
	doc.text(105, 102, 'Receipt #', 'right');
	doc.text(145, 102, 'Contribution Date', 'right');
	doc.text(175, 102, 'Amount', 'right');
	doc.line(25, 106, 175, 106);

	doc.text(25, 112, '1');
	doc.text(105, 112, '<?=$donationId?>', 'right');
	doc.text(145, 112, '<?=mysql2DateString($date)?>', 'right');
	doc.text(175, 112, '$<?=money_format('%.2n', $amount)?>', 'right');


	doc.line(25, 134, 175, 134);<commit_msg>add 'cash' for donation resceipt.<commit_after><?php require_once 'init.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/navigation.php'; ?>


<?php if (!securePage($_SERVER['PHP_SELF'])){die();} ?>
<?php
$validation = new Validate ();
// PHP Goes Here!
$errors = [ ];
$successes = [ ];
$donationId = Input::get ( 'id' );
// Check if selected user exists
if (! donationIdExists ( $donationId )) {
	Redirect::to ( "../index.php" );
	die ();
}

$token = Input::get('csrf');
if(Input::exists()){
	if(!Token::check($token)){
		die('Token doesn\'t match!');
	}
}



$donationDetails = fetchDonationDetails ( $donationId );
$date = $donationDetails->date;
$cdate = $donationDetails->created_at;
$amount = $donationDetails->amount;
$dtype = $donationDetails->dtype;
$company = $donationDetails->company;
$comment = $donationDetails->comment;
$donationId = $donationDetails->id;
$visibility = $donationDetails->visibility;

$userId = $donationDetails->user_id;
$userdetails = fetchUserDetails ( NULL, NULL, $userId ); // Fetch user details

$loggedInUserId = $user->data ()->id;
if ($loggedInUserId != $userId &&!checkMenu(2,$user->data()->id)) {
	// not your donation. You cannot access it.
	Redirect::to ( "../index.php" );
	die ();
}

//Forms posted
if (!empty($_POST) && !empty($_POST["email"])) {
	echo "sending email";
	$subject = "Your donation receipt #$donationId";
	$options = array(
			'fname' => $userdetails->fname,
			'lname' => $userdetails->lname,
	);
	$body =  email_body('_receipt.php',$options);
	$attachment = array(
			"data" => Input::get("pdfdata"),
			"filename" => receiptFileName($donationDetails, $userdetails) . "pdf",
			"encoding" => "base64", "type" => "application/pdf"
	);
	
	$email_sent=email($userdetails->email,$subject,$body, $attachment);
	
	if(!$email_sent){
		$errors[] = 'Email NOT sent due to error. Please contact site administrator.';
	} else {
		$successes[] ="Successfully sent receipt to $userdetails->email.";
	}
}

?>
<div id="page-wrapper">

	<div class="container">

			<div class="row">
				<div class="col-md-12">
          <?php
										
										echo resultBlock ( $errors, $successes );
										?>
		<div class="row">
			<div class="col-xs-3 text-center">
			<form class="form-signup" action="donation_receipt.php?id=<?=$donationId?>" method="POST" id="payment-form">
				<label> &nbsp; </label>
				<input class='btn btn-primary print-receipt' type='submit'
												name='print' value='Print' />
												<label>&nbsp;</label>
												
				<input class='btn btn-primary download-receipt' type='submit'
												name='download' value='Download' />
												<label>&nbsp;</label>
				<input class='btn btn-primary email-receipt' type='submit'
												name='email' value='Email' />
												<label>&nbsp;</label>
				<input type="hidden" id="pdfdata" name="pdfdata" value="Mickey Mouse">
				<input type="hidden" value="<?=Token::generate();?>" name="csrf">
			</form>
			</div>
			<div class="col-xs-9 text-center">
			<iframe class="preview-pane" type="application/pdf"  width="600" height="900" frameborder="0" style="position:relative;z-index:999">
			</iframe>
			</div>
			
		</div>
	</div>
</div>




<?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>

<!-- Place any per-page javascript here -->
<script src="../js/jspdf.debug.js"></script>
<script src="../js/from_html.js"></script>
<script src="../js/autoprint.js"></script>
<script src="../js/split_text_to_size.js"></script>
<script src="../js/standard_fonts_metrics.js"></script>
<script>

var doc;
	
function getDoc() {
	doc=new jsPDF('p', 'mm', 'letter');
	
	doc.setFontType("bold");
	doc.setFontSize(14);
	doc.text(25, 34, "Charitable Donation Receipt");

	doc.setFontType("normal");
	doc.setFontSize(11);
	
	doc.text(25, 40, 'Issued on: <?=mysql2DateString(substr($cdate, 0, 10))?>');

	doc.setFontType("bold");
	doc.text(25, 50, 'Ping Pong Community');

	doc.setFontType("normal");
	doc.text(25, 56, '3273 Falerno Way');
	doc.text(25, 62, 'San Jose, CA 95135');
	doc.text(25, 68, 'Tel: 408-915-7464');
	doc.text(25, 74, 'Email: <EMAIL>');
	doc.text(25, 80, 'EIN#: 81-2451936');

	
	doc.text(25, 92, 'We acknowledge, with thanks, the receipt of following cash contributions from');

	doc.setFontType('bold');
	doc.text(159, 92, '<?php echo "$userdetails->fname $userdetails->lname"?>:');

	doc.setFontType('normal');
	doc.text(25, 102, 'No.');
	doc.text(105, 102, 'Receipt #', 'right');
	doc.text(145, 102, 'Contribution Date', 'right');
	doc.text(175, 102, 'Amount', 'right');
	doc.line(25, 106, 175, 106);

	doc.text(25, 112, '1');
	doc.text(105, 112, '<?=$donationId?>', 'right');
	doc.text(145, 112, '<?=mysql2DateString($date)?>', 'right');
	doc.text(175, 112, '$<?=money_format('%.2n', $amount)?>', 'right');


	doc.line(25, 134, 175, 134);
{'fraction_non_alphanumeric': 0.2116758933064922, 'fraction_numerical': 0.03321590337191746, 'mean_word_length': 4.408818726183996, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 165, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4925423', 'n_tokens_mistral': 4124, 'n_tokens_neox': 3484, 'n_words': 730}