blob: 765db38cded023aebe04b8f4669cd76c81885aed [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2014 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Edouard Poitras (Eclipse Foundation) - Minor Modifications
*******************************************************************************/
if (isset($_SERVER['HTTP_REFERER']) &&
strpos($_SERVER['HTTP_REFERER'], 'dev.eclipse.org/site_login') !== FALSE) {
header('Location: /donate');
return;
}
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/session.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/paypal.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/friend.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/smartconnection.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/contribution.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/friendsContributionsList.class.php");
require_once("/home/data/httpd/eclipse-php-classes/system/ldapconnection.class.php");
require_once("emails.php");
$App = new App();
$Nav = new Nav();
$Menu = new Menu();
$LDAP = new LDAPConnection();
include($App->getProjectCommon());
// Disable Caching
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// Set up Paypal
$Paypal = new Paypal();
//$Paypal->set_debug_mode(TRUE);
//$Paypal->set_sandbox_mode(TRUE);
//$Paypal->set_show_all(TRUE);
// Handle Logged in User Session
$Session = new Session();
$Friend = $Session->getFriend();
function getLDAPUIDFromEmail($_email) {
$LDAP = new LDAPConnection();
if ($response = $LDAP->getUIDFromMail($_email)) {
return $response;
}
return NULL;
}
function getActiveEmail($friend, $paypal) {
if ($_POST['login'] && $_POST['login'] != '') return $_POST['login']; // User posted Eclipse.org ID
else if ($friend && $friend->getEmail() != '') return $friend->getEmail();
else return $paypal->get_email(); // Paypal email on first page load after redirect
}
function sendEmail($data) {
$transaction_id = $data['transaction_id'];
if ($data['amount'] >= 35 && $data['email'] != "" && !isset($_COOKIE['email_sent' . $transaction_id])) {
// Need the UID to store in tshirt table
if ($data['amount'] >= 100 && !$data['uid']) return; // User should submit Eclipse Login ID to receive shirt
send_email($data);
// Ensure we don't keep sending emails after user updates
setcookie("email_sent" . $data['transaction_id'], TRUE, time()+600, '/', '.eclipse.org');
}
}
function logABTesting($paypal, $app) {
if (isset($_GET['cm']) && ($_GET['cm'] === 'A' || $_GET['cm'] === 'B')) { // Custom Variable (A or B)
$data = $paypal->get_transaction_data();
$amount = $app->sqlSanitize($data['amount']);
$test = $app->sqlSanitize($_GET['cm']);
$transaction_id = $data['transaction_id'];
$sql = "SELECT * FROM thankyou_a_b WHERE transaction_id = '$transaction_id'";
$res = $app->eclipse_sql($sql);
if (is_numeric($amount) && mysql_num_rows($res) === 0) {
$sql = "INSERT INTO thankyou_a_b VALUES (NOW(), '$test', $amount, '$transaction_id')";
$app->eclipse_sql($sql);
}
}
}
// PHP sends headers every print/echo statement
// We use ob_start so that the setcookie() function can be used to set header values without PHP complaining
// about headers having already been sent (through a print/echo statement somewhere else).
ob_start();
// Confirm Donation
$success = $Paypal->confirm_donation();
if ($success) {
// Make sure user stops getting bothered by donation banner
setcookie ("thankyou_page[donation]", TRUE, time() + (3600 * 24 * 279), '/', '.eclipse.org');
// A/B Testing
logABTesting($Paypal, $App);
// Sanitize Variables
$_POST['first_name'] = $App->sqlSanitize(filter_var($_POST['first_name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS));
$_POST['last_name'] = $App->sqlSanitize(filter_var($_POST['last_name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS));
$_POST['comment'] = $App->sqlSanitize(filter_var($_POST['comment'], FILTER_SANITIZE_FULL_SPECIAL_CHARS));
$_POST['login'] = $App->sqlSanitize(filter_var($_POST['login'], FILTER_SANITIZE_EMAIL));
// Handle User Updating Information (anonymity, comments, etc)
$Paypal->set_comment($_POST['comment']);
$Paypal->set_email(getActiveEmail($Friend, $Paypal));
if ($Friend->getFirstName()) $Paypal->set_first_name($Friend->getFirstName());
else if ($_POST['first_name'] != "") $Paypal->set_first_name($_POST['first_name']);
if ($Friend->getLastName()) $Paypal->set_last_name($Friend->getLastName());
else if ($_POST['last_name'] != "") $Paypal->set_last_name($_POST['last_name']);
// Anonymity
if (isset($_POST['save'])) { // On Save/POST
$Paypal->set_anonymous($_POST['os1'] === 'Private');
} else { // First time always anonymous
$Paypal->set_anonymous(TRUE);
}
// Ready Transaction Data
$data = $Paypal->get_transaction_data();
$data['uid'] = getLDAPUIDFromEmail(getActiveEmail($Friend, $Paypal));
sendEmail($data);
// Check to see if this transaction has already been processed.
$check_contribution = new Contribution();
$check_transaction = $check_contribution->selectContributionExists($data['transaction_id']);
if ($check_transaction == FALSE) { // Contribution Doesn't Already Exist
//Check to see if user already exists in friends
$check_friends = new Friend();
$ldapuid = getLDAPUIDFromEmail(getActiveEmail($Friend, $Paypal));
$friend_id = $check_friends->selectFriendID("uid", $ldapuid);
if ($friend_id != 0) { // User Already Exist
// Lets Update the Friend Information
$new_friend = new Friend();
$new_friend->selectFriend($friend_id); // Want to keep existing date_joined
$new_friend->setFirstName($data['firstname']);
$new_friend->setLastName($data['lastname']);
$new_friend->setIsAnonymous($data['anonymous']);
$new_friend->setIsBenefit($data['benefit']);
$new_friend->setFriendID($friend_id);
$new_friend->setLDAPUID($ldapuid);
$new_friend_id = $new_friend->insertUpdateFriend();
// Friend_id does not equal 0 so we have an existing user. We need to add a new contribution
$insert_contribution = new Contribution();
$insert_contribution->setFriendID($friend_id);
$insert_contribution->setAmount($data['amount']);
$insert_contribution->setMessage($data['comment']);
$insert_contribution->setTransactionID($data['transaction_id']);
$insert_contribution->insertContribution();
//Record Inserted
} else {
// No friend_id found so add a new friend record then add the contribution record.
$new_friend = new Friend();
$new_friend->setFirstName($data['firstname']);
$new_friend->setLastName($data['lastname']);
$new_friend->setLDAPUID($ldapuid);
$new_friend->setIsAnonymous($data['anonymous']);
$new_friend->setIsBenefit($data['benefit']);
$new_friend_id = $new_friend->insertUpdateFriend();
$insert_contribution = new Contribution();
$insert_contribution->setFriendID($new_friend_id);
$insert_contribution->setAmount($data['amount']);
$insert_contribution->setMessage($data['comment']);
$insert_contribution->setTransactionID($data['transaction_id']);
$insert_contribution->insertContribution();
}
}
// User submitted an Eclipse.org ID
if (isset($_POST['login']) && $_POST['login'] != "") {
// Need to reload friend incase we're dealing with a non-logged in user
// Update Anonymity
$check_contribution->selectContributionWithTransaction($data['transaction_id']);
$anon_friend = new Friend();
$anon_friend->selectFriend($check_contribution->getFriendID());
$anon_friend->setIsAnonymous($data['anonymous']);
// Update Name
$check_friends = new Friend();
$ldapuid = getLDAPUIDFromEmail($_POST['login']);
$friend_id = $check_friends->selectFriendID("uid", $ldapuid);
if (!$friend_id) { // If no friend_id found, create the friend based on ldap information
$dn = $LDAP->getDNFromMail($_POST['login']);
$firstname = $LDAP->getLDAPAttribute($dn, 'givenName');
$lastname = $LDAP->getLDAPAttribute($dn, 'sn');
$anon_friend->setFirstName($firstname);
$anon_friend->setLastName($lastname);
$anon_friend->setEmail($_POST['login']);
$anon_friend->setLDAPUID($ldapuid);
$data['firstname'] = $firstname;
$data['lastname'] = $lastname;
$anon_friend->insertUpdateFriend();
$check_contribution->setFriendID($anon_friend->getFriendID());
$check_contribution->updateContribution();
} else {
$existing_friend = new Friend();
$existing_friend->selectFriend($friend_id);
$existing_friend->setIsAnonymous($data['anonymous']);
$existing_friend->insertUpdateFriend();
$data['firstname'] = $existing_friend->getFirstName();
$data['lastname'] = $existing_friend->getLastName();
$check_contribution->setFriendID($friend_id);
$check_contribution->updateContribution();
}
}
// Check to see if this transaction has already been processed.
$check_contribution = new Contribution();
$check_transaction = $check_contribution->selectContributionExists($data['transaction_id']);
if ($check_transaction == TRUE) { // Contribution Already Exist - Check for name and message change
// Update contribution
$check_contribution->selectContributionWithTransaction($data['transaction_id']);
$check_contribution->setMessage($data['comment']);
$check_contribution->updateContribution();
// Get friend from friend_id from transaction
$check_friends = new Friend();
$check_friends->selectFriend($check_contribution->getFriendID());
if ($check_friends->getFriendID() != 0) { // User Already Exist
// Update Anonymity
$check_friends->setIsAnonymous($data['anonymous']);
$check_friends->insertUpdateFriend();
} else {
$ldapuid = getLDAPUIDFromEmail(getActiveEmail($Friend, $Paypal));
$check_friends->setFirstName($data['firstname']);
$check_friends->setLastName($data['lastname']);
$check_friends->setIsAnonymous($data['anonymous']);
$check_friends->setIsBenefit($data['benefit']);
$check_friends->setLDAPUID($ldapuid);
$check_friends->insertUpdateFriend();
}
}
}
$pageTitle = "Thank You";
$pageKeywords = "friends of eclipse, donation, contribution";
$pageAuthor = "Edouard Poitras";
include('content/en_thankyou.php');
$html = ob_get_clean();
# Generate the web page
$App->AddExtraHtmlHeader('<script type="text/javascript" src="/donate/functions.js"></script>');
$App->AddExtraHtmlHeader('<link rel="stylesheet" type="text/css" href="/donate/style.css" media="screen" />');
// Don't generate the page for PayPal IPN
if (!isset($_GET['IPN'])) {
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html);
}
?>