258 lines
13 KiB
PHP
258 lines
13 KiB
PHP
<?php
|
|
// $Id: booking.confirm.inc,v 0.1 2011/07/12
|
|
|
|
/**
|
|
* Confirmation page for event registration
|
|
*/
|
|
function booking_confirm_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 registration confirmation 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
|
|
|
|
//fetch details about the person
|
|
$query = db_select('booking_person', 'p');
|
|
$query->condition('p.booking_tempid', arg(1), '=')
|
|
->fields('p', array('nid'));
|
|
$person = $query->execute()
|
|
->fetchObject();
|
|
|
|
|
|
if ($person)
|
|
{
|
|
//load all the fields
|
|
$node = node_load($person->nid);
|
|
//maximum length for invoice id is 127 characters
|
|
$invoiceid = $person->nid . '_' . $node->booking_event_id . '_' . $node->booking_lastname . '-' . $node->booking_firstname;
|
|
$invoiceid = substr($invoiceid, 0, 126);
|
|
} else {
|
|
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
|
|
return "";
|
|
}
|
|
|
|
//check if this registration will be on the waiting list
|
|
if (_booking_check_bookings_full() == True || $node->booking_status == 2)
|
|
$waiting_list = TRUE;
|
|
|
|
//populate tokens
|
|
$tokens = booking_define_personspecific_tokens($node);
|
|
|
|
//TODO: add in the paypal forms as tokens
|
|
$tokens['paypal-deposit-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-deposit-amount'], "Pay Deposit");
|
|
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Full Amount");
|
|
|
|
//watchdog('booking', 'Paypal form "@info"', array ('@info' => var_export($tokens['paypal-total-form'], TRUE)));
|
|
|
|
//$tokens['paypal-total-form'] = drupal_get_form('_booking_paypal_form', arg(1), $person, $invoiceid, $tokens['paypal-total-amount']);
|
|
|
|
if ($waiting_list == FALSE)
|
|
{
|
|
//watchdog('booking', 'Waiting list is false. Un-tokenised text is "@info"', array ('@info' => variable_get('booking_regn_confirm_page')));
|
|
$output = token_replace(variable_get('booking_regn_confirm_page'), $tokens);
|
|
//$paypal_form = drupal_get_form('_booking_paypal_form_builder', $person, $invoiceid, $amount_owing, "Pay Full Amount");
|
|
}
|
|
else
|
|
{
|
|
//calculate waiting list position token
|
|
/*
|
|
$waitinglist_query = db_query("SELECT count(*) as num_ppl FROM {booking_person} where booking_event_id = :eventid and (booking_status = 1 or booking_status = 2)",
|
|
array(':eventid' => $event->eid))
|
|
->fetchObject();
|
|
$tokens['waitinglist-position'] = $waitinglist_query->num_ppl - variable_get('booking_regn_limit', 350) + 1;
|
|
*/
|
|
$output = token_replace(variable_get('booking_regn_confirm_waiting_page'), $tokens);
|
|
|
|
//only offer the deposit amount
|
|
//TODO: query this from the booking_price table
|
|
//$paypal_form = drupal_get_form('_booking_paypal_form', arg(1), $person, $invoiceid, '50.00');
|
|
}
|
|
|
|
//optional additional text for married people
|
|
if ($node->booking_married == 'Y')
|
|
{
|
|
$output .= token_replace(variable_get('booking_regn_confirm_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;
|
|
}
|
|
|
|
|
|
/*
|
|
* ORIGINAL VERSION FROM STUDY WEEK
|
|
|
|
function booking_confirm_page() {
|
|
global $event;
|
|
$output = "";
|
|
$waiting_list = False;
|
|
$already_paid = false;
|
|
|
|
$form_action = variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL;
|
|
|
|
//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. Please use the contact us form to let us know.", 'error', FALSE);
|
|
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
|
|
|
|
//fetch details about the person
|
|
$person = db_query("SELECT person.nid, person.booking_event_id, person.booking_lastname, person.booking_firstname, price.booking_buttonid, price.booking_price, price.booking_price_descrip, " .
|
|
" person.booking_married, person.booking_partner_name, person.booking_status " .
|
|
"FROM {booking_person} person, {booking_price} price " .
|
|
"WHERE booking_tempid = :tempid " .
|
|
"AND person.booking_payment_id = price.pid",
|
|
array(':tempid' => arg(1)))
|
|
->fetchObject();
|
|
|
|
if ($person) {
|
|
//maximum length for invoice id is 127 characters
|
|
$invoiceid = $person->nid . '_' . $person->booking_event_id . '_' . $person->booking_lastname . '-' . $person->booking_firstname;
|
|
$invoiceid = substr($invoiceid, 0, 126);
|
|
} else {
|
|
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
|
|
return "";
|
|
}
|
|
|
|
//check if this person is married and their partner has already paid the deposit
|
|
if ($person->booking_married == 'Y')
|
|
{
|
|
//temporary hack
|
|
$output .= t("<p>In your registration details, you indicated that you were married. Please note that both you and your spouse must pay a deposit and book in individually, " .
|
|
"although the total married couple of $!fee only needs to be paid once.</p>",
|
|
array('!fee' => $person->booking_price));
|
|
|
|
//watchdog('booking', 'Partner name "@info"', array ('@info' => var_export($person->booking_partner_name, TRUE)));
|
|
if (preg_match('/^(\w*?)\s+(\w*)/', $person->booking_partner_name, $matches))
|
|
{
|
|
watchdog('booking', 'Spouse checking. Firstname: "!first", surname "!last"',
|
|
array ('!first' => $matches[1], '!last' => $matches[2]));
|
|
|
|
//try and find their partner
|
|
|
|
$spouse = db_query("SELECT person.nid, person.booking_amount_paid, person.booking_total_pay_reqd " .
|
|
"FROM {booking_person} person " .
|
|
"WHERE person.booking_married = 'Y' AND person.booking_firstname = :first " .
|
|
"AND person.booking_lastname = :last AND person.booking_event_id = :event",
|
|
array(':first' => $matches[1], ':last' => $matches[2], ':event' => $event->eid))
|
|
->fetchObject();
|
|
if ($spouse && ($spouse->booking_amount_paid >= $spouse->booking_total_pay_reqd))
|
|
{
|
|
//TODO: Fix this
|
|
watchdog('booking', 'Spouse checking. Paid: "!paid", Total Due "!total"',
|
|
array ('!paid' => $spouse->booking_amount_paid, '!total' => $spouse->booking_total_pay_reqd));
|
|
if ($spouse->booking_amount_paid >= $spouse->booking_total_pay_reqd)
|
|
watchdog('booking', 'This is calculated as having paid fully.');
|
|
else
|
|
watchdog('booking', 'This is calculated as having money outstanding.');
|
|
//drupal_set_message('Our records indicate your spouse has already paid all money outstanding. ' .
|
|
// 'There is no need to make any further payment', $type = 'status');
|
|
$already_paid = true;
|
|
}
|
|
elseif ($spouse)
|
|
{
|
|
watchdog('booking', 'Partner "!name" has already paid "!price".',
|
|
array ('!name' => $person->booking_partner_name, '!price' => $spouse->booking_amount_paid));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//fetch the info for the deposit only button
|
|
$deposit = db_query("SELECT price.booking_buttonid, price.booking_price, price.booking_price_descrip " .
|
|
"FROM {booking_price} price WHERE booking_eventid = :eventid and booking_depositonly = 1 and booking_price_active = 1",
|
|
array(':eventid' => $event->eid))
|
|
->fetchObject();
|
|
|
|
//check if this registration will be on the waiting list
|
|
if (_booking_check_bookings_full() == True || $person->booking_status == 2)
|
|
$waiting_list = TRUE;
|
|
|
|
//$waiting_list = $person->booking_status == 2 ? TRUE : FALSE;
|
|
|
|
//For testing only
|
|
//_booking_registration_email($person->nid);
|
|
|
|
//TODO: Also have different options for people that have chosen married
|
|
|
|
|
|
//Have different options for waiting list, and no full payment button
|
|
if ($waiting_list == TRUE)
|
|
{
|
|
$waitinglist_query = db_query("SELECT count(*) as num_ppl FROM {booking_person} where booking_event_id = :eventid and (booking_status = 1 or booking_status = 2)",
|
|
array(':eventid' => $event->eid))
|
|
->fetchObject();
|
|
$output .= t("<p>Unfortunately the bookings for !event have reached the maximum number of attendees. " .
|
|
"If you wish to reserve your place on the waiting list at number !waitnum, please pay the deposit using this paypal button:<br />",
|
|
array('!event' => $event->booking_eventname, '!waitnum' => $waitinglist_query->num_ppl - variable_get('booking_regn_limit', 350) + 1));
|
|
}
|
|
else
|
|
{
|
|
$output .= t("<p>If you wish to only pay your deposit for !event at this stage, please click on this paypal button:<br />",
|
|
array('!event' => $event->booking_eventname));
|
|
}
|
|
|
|
//Paypal form for paying the deposit only
|
|
$output .= t('<form action="!url" method="post">', array('!url' => $form_action));
|
|
$output .= t('<input type="hidden" name="cmd" value="_s-xclick">');
|
|
$output .= t('<input type="hidden" name="hosted_button_id" value="!id">', array('!id' => $deposit->booking_buttonid));
|
|
$output .= t('<input type="hidden" name="invoice" value="!invoice">', array('!invoice' => $invoiceid));
|
|
$output .= t('<input type="hidden" name="item_name" value="!name">', array('!name' => $event->booking_eventname . ' ' . $person->booking_price_descrip . ' (Deposit)'));
|
|
$output .= t('<input type="hidden" name="cbt" value="!text">', array('!text' => "Return to " . $event->booking_eventname . " website"));
|
|
//$output .= t('<input type="hidden" name="image_url" value="!url">', array('!url' => "http://example.com/image.jpg"));
|
|
$output .= t('<input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/x-click-but6.gif" border="0" name="submit" alt="Pay deposit via PayPal.">');
|
|
$output .= t('<img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">');
|
|
$output .= t('</form></p>');
|
|
|
|
//Full payment option, only show if $waiting_list is false
|
|
if ($waiting_list == false)
|
|
{
|
|
$output .= t("<p>Otherwise, you can submit the full payment of $!price via the paypal button below to complete your booking as a !price_descrip.</p>",
|
|
array('!price' => $person->booking_price, '!price_descrip' => $person->booking_price_descrip));
|
|
$output .= t('<form action="!url" method="post">', array('!url' => $form_action));
|
|
$output .= t('<input type="hidden" name="cmd" value="_s-xclick">');
|
|
$output .= t('<input type="hidden" name="hosted_button_id" value="!id">', array('!id' => $person->booking_buttonid));
|
|
$output .= t('<input type="hidden" name="invoice" value="!invoice">', array('!invoice' => $invoiceid));
|
|
//$output .= t('<input type="hidden" name="amount" value="!amount">', array('!amount' => $person->booking_price));
|
|
$output .= t('<input type="hidden" name="item_name" value="!name">', array('!name' => $event->booking_eventname . ' ' . $person->booking_price_descrip));
|
|
$output .= t('<input type="hidden" name="cbt" value="!text">', array('!text' => "Return to " . $event->booking_eventname . " website"));
|
|
//TODO: Include the study week logo
|
|
//The URL of the 150x50-pixel image displayed as your logo in the upper left corner of the PayPal checkout pages.
|
|
//$output .= t('<input type="hidden" name="image_url" value="!url">', array('!url' => "http://example.com/image.jpg"));
|
|
|
|
$output .= t('<input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/x-click-but6.gif" border="0" name="submit" alt="Pay !amount via PayPal.">',
|
|
array('!amount' => $person->booking_price));
|
|
$output .= t('<img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">');
|
|
$output .= t('</form>');
|
|
}
|
|
|
|
//cheque information
|
|
$output .= t("<p> </p>");
|
|
$output .= t("<p>Paypal is the preferred method of payment, but if you absolutely cannot pay via paypal, please send a cheque to the following address. ");
|
|
$output .= t("Cheques should be made payable to "Study Week".</p>");
|
|
$output .= t("<p>!event<br />6 School Parade<br />PADSTOW NSW 2211<br /> Australia</p>", array('!event' => $event->booking_eventname));
|
|
$output .= t("<p>Please include with the cheque the name you used when registering (!name), and your registration id (!id). You will not receive an email confirming your place until the cheque is received and processed.</p>",
|
|
array('!name' => $person->booking_lastname . ', ' . $person->booking_firstname, '!id' => $person->nid));
|
|
return $output;
|
|
}*/
|