Files
booking/booking.balance.inc
2014-12-01 23:06:39 +11:00

85 lines
2.9 KiB
PHP

<?php
// $Id: booking.confirm.inc,v 0.1 2011/07/12
/**
* Confirmation page for event registration
*/
function booking_balance_page() {
global $event;
$output = "";
$waiting_list = False;
$already_paid = false;
$paypal_form = "";
//verify that arg(1) is a uuid
if (! preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) {
//parameter from url is not what we were expecting
drupal_set_message("Error: Invalid session ID supplied to the balance payment page. Please use the contact us form to let us know.", 'error', FALSE);
drupal_goto('<front>');
return "";
}
//TODO: if the person says they're married, query to see if they're listed partner has already registered and paid
//if they have, then let the new registration person know their partner has already paid, and send them the confirmation email
//work out the node id from the session id
$query = db_select('booking_person', 'p');
$query->condition('p.booking_tempid', arg(1), '=')
->fields('p', array('nid'));
$person = $query->execute()
->fetchObject();
/*
//fetch details about the person
$query = db_select('booking_person', 'p');
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
$query->condition('p.booking_tempid', arg(1), '=')
->fields('p')
->fields('pr', array('booking_price', 'booking_price_descrip'));
$person = $query->execute()
->fetchObject();
*/
if ($person)
{
//load all the fields
$node = node_load($person->nid);
//calculate the invoice ID
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $node->booking_lastname . '-' . $node->booking_firstname;
//maximum length for invoice id in paypal is 127 characters so truncate if necessary
$invoiceid = substr($invoiceid, 0, 126);
} else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
return "";
}
//populate tokens and paypal form
$tokens = booking_define_personspecific_tokens($node);
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
//Calculate the amount outstanding
//watchdog('booking', 'Booking Balance form calculating amount owing');
//$amount_owing = _booking_amount_owing($person->nid);
//If the amount outstanding is zero, then display information to that effect.
if ($tokens['paypal-total-amount'] == 0)
{
$output = token_replace(variable_get('booking_regn_balance_page_paid'), $tokens);
}
else
{
$output = token_replace(variable_get('booking_regn_balance_page'), $tokens);
//optional additional text for married people
if ($node->booking_married == 'Y')
$output .= token_replace(variable_get('booking_regn_balance_married_text'), $tokens);
}
//put all the bits together
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
//$return_array[] = array('form' => $paypal_form);
//return the form
return $return_array;
}