| <?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("emails.php"); |
| |
| $App = new App(); |
| $Nav = new Nav(); |
| $Menu = new Menu(); |
| |
| include($App->getProjectCommon()); |
| |
| // Set up Paypal |
| $Paypal = new Paypal(); |
| $Paypal->set_debug_mode(TRUE); |
| $Paypal->set_sandbox_mode(TRUE); |
| $Paypal->set_show_all(TRUE); |
| // 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 |
| 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']); |
| if (is_numeric($amount)) { |
| $sql = "INSERT INTO thankyou_a_b VALUES (NOW(), '$test', $amount)"; |
| $App->eclipse_sql($sql); |
| } |
| } |
| } |
| // Handle Logged in User Session |
| $Session = new Session(); |
| $friend = $Session->getFriend(); |
| // Handle User Updating Information (anonymity, comments, etc) |
| $Paypal->set_comment($App->sqlSanitize($_POST['comment'])); |
| if (isset($_POST['bugzilla'])) { // Eclipse.org ID submitted by user |
| $_POST['bugzilla'] = filter_var($_POST['bugzilla'], FILTER_SANITIZE_EMAIL); |
| $_POST['bugzilla'] = $App->sqlSanitize($_POST['bugzilla']); |
| $Paypal->set_bugzilla_email($_POST['bugzilla']); |
| } else if ($friend->getEmail()) { // User session information used otherwise |
| $Paypal->set_bugzilla_email($friend->getEmail()); |
| } |
| 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(); |
| |
| if ($data['benefit']) { |
| // Send Email |
| $transaction_id = $data['transaction_id']; |
| if ($data['bugzilla_email'] != "" && !isset($_COOKIE['email_sent' . $transaction_id])) { |
| $check_friend = new Friend(); |
| if (!isset($data['bugzilla_id'])) { |
| $data['bugzilla_id'] = $check_friend->getBugzillaIDFromEmail($data['bugzilla_email']); |
| } |
| send_email($data); |
| // Ensure we don't keep sending emails after user updates |
| setcookie("email_sent" . $data['transaction_id'], TRUE, time()+600, '/', '.eclipse.org'); |
| } |
| // 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(); |
| $bugzilla_id = $check_friends->getBugzillaIDFromEmail($data['bugzilla_email']); |
| $friend_id = $check_friends->selectFriendID("bugzilla_id", $bugzilla_id); |
| if ($friend_id != 0) { // User Already Exist |
| // Lets Update the Friend Information |
| $new_friend = new Friend(); |
| $new_friend->setFirstName($data['firstname']); |
| $new_friend->setLastName($data['lastname']); |
| $new_friend->setBugzillaID($bugzilla_id); |
| $new_friend->setIsAnonymous($data['anonymous']); |
| $new_friend->setIsBenefit($data['benefit']); |
| $new_friend->setFriendID($friend_id); |
| $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->setBugzillaID($bugzilla_id); |
| $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(); |
| } |
| } |
| if (isset($_POST['bugzilla']) && $_POST['bugzilla'] != "") { |
| // 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(); |
| $bugzilla_id = $check_friends->getBugzillaIDFromEmail($_POST['bugzilla']); |
| $friend_id = $check_friends->selectFriendID("bugzilla_id", $bugzilla_id); |
| $existing_friend = new Friend(); |
| if (!$friend_id) { // If no friend_id found, create the friend based on bugzilla information |
| $sql = "SELECT userid, realname FROM profiles WHERE login_name = " . $App->returnQuotedString($_POST['bugzilla']); |
| $result = $App->bugzilla_sql($sql); |
| $values = mysql_fetch_array($result); |
| $name = explode(' ', $values['realname']); |
| $firstname = $name[0]; |
| $lastname = $name[1]; |
| $existing_friend->setBugzillaID($bugzilla_id); |
| $existing_friend->setFirstName($firstname); |
| $existing_friend->setLastName($lastname); |
| $existing_friend->setIsAnonymous(1); |
| $existing_friend->setIsBenefit(1); |
| $existing_friend->setEmail($_POST['bugzilla']); |
| $existing_friend->insertUpdateFriend(); |
| } else { |
| $existing_friend->selectFriend($friend_id); |
| } |
| $anon_friend->setFirstName($existing_friend->getFirstName()); |
| $anon_friend->setLastName($existing_friend->getLastName()); |
| $data['firstname'] = $existing_friend->getFirstName(); |
| $data['lastname'] = $existing_friend->getLastName(); |
| $anon_friend->insertUpdateFriend(); |
| $check_contribution->setFriendID($anon_friend->getFriendID()); |
| $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 ($friend_id != 0) { // User Doesn't Already Exist |
| // Ignore this case - should have been handled above |
| } else { |
| $check_friends->setFirstName($data['firstname']); |
| $check_friends->setLastName($data['lastname']); |
| $check_friends->setIsAnonymous($data['anonymous']); |
| $check_friends->insertUpdateFriend(); |
| } |
| } // Contribution Doesn't Exist, do nothing |
| |
| $pageTitle = "Thank You"; |
| $pageKeywords = "friends of eclipse, donation, contribution"; |
| $pageAuthor = "Christopher Guindon"; |
| |
| ob_start(); |
| 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); |
| } |
| ?> |