799 lines
28 KiB
PHP
799 lines
28 KiB
PHP
<?php
|
|
// $Id: booking.helper.inc,v 0.1 2011/07/12
|
|
|
|
/**
|
|
* Helper function to perform some validity checking of email addresses
|
|
*/
|
|
function _valid_email_address($email) {
|
|
//firstly use the built-in function to validate the format
|
|
if (! valid_email_address($email))
|
|
return false;
|
|
//now check the domain exists
|
|
|
|
if (preg_match('/^(.*?)\@(.*)/', $email, $matches)) {
|
|
//watchdog('booking', 'Email address checking: @info', array('@info' => var_export($matches, TRUE)));
|
|
if (! checkdnsrr($matches[2], "MX"))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
//watchdog('booking', 'Email address checking doesnt match');
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Helper function to perform some validity checking of Medicare Numbers
|
|
* Based on http://dyball.wordpress.com/2007/12/05/validation-of-medicare-numbers/
|
|
*/
|
|
function _valid_medicare_number($input) {
|
|
//strip any whitespace
|
|
$medicare = preg_replace( '/\s+/', '', $input );
|
|
if (is_numeric($medicare) && strlen($medicare) >= 9 && $medicare > 0)
|
|
{
|
|
$check_digit = $medicare[0] + (3 * $medicare[1]) + (7 * $medicare[2]) + (9 * $medicare[3])
|
|
+ $medicare[4] + (3 * $medicare[5]) + (7 * $medicare[6]) + (9 * $medicare[7]);
|
|
|
|
if (($check_digit % 10) == $medicare[8])
|
|
{
|
|
watchdog('booking', 'Medicare number (!mca) validates since check digit !check matches remainder from !remainder',
|
|
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
watchdog('booking', 'Medicare number (!mca) does not validate since check digit !check does not match remainder from !remainder',
|
|
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
|
|
return FALSE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
watchdog('booking', 'Medicare number (!mca) does not validate since it is either non-numeric or too short',
|
|
array('!mca' => $input));
|
|
return FALSE;
|
|
}
|
|
}
|
|
/**
|
|
* Helper function to perform some validity checking of a passport number
|
|
* Based on http://dyball.wordpress.com/2007/04/12/validation-of-passport-numbers/
|
|
* @param $input string containing passport number to be verified
|
|
* @return boolean indicating if passport number is valid
|
|
*/
|
|
function _valid_passport_number($input) {
|
|
//strip whitespace
|
|
$passport = preg_replace( '/\s+/', '', $input );
|
|
//check for a match
|
|
if (preg_match('/^[a-zA-Z]\d{7}$/', $input, $matches)) {
|
|
watchdog('booking', 'Passport number "!passnum" validates since it passed our regexp',
|
|
array('!passnum' => $input));
|
|
return TRUE;
|
|
}
|
|
watchdog('booking', 'Passport number "!passnum" fails to validate',
|
|
array('!passnum' => $input));
|
|
return FALSE;
|
|
}
|
|
|
|
function _valid_phone_number($input)
|
|
{
|
|
//strip any whitespace
|
|
$number = preg_replace( '/\s+/', '', $input );
|
|
//strip any non-numeric characters
|
|
$number = preg_replace('/\D+/','', $number);
|
|
|
|
if (is_numeric($number))
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
|
|
/*
|
|
if (preg_match('^(?:\+61|0061|0)(\d{3})\s*(\d{3})\s*(\d{3})$', $number, $matches))
|
|
{
|
|
|
|
}
|
|
*/
|
|
}
|
|
|
|
|
|
/**
|
|
* Helper function to check whether the number of registrations for the current event have reached their defined maximum size
|
|
*/
|
|
function _booking_check_bookings_full()
|
|
{
|
|
global $event;
|
|
$waitinglist_query = db_query("SELECT count(*) as num_ppl FROM {booking_person} where booking_event_id = :eventid and booking_status = 1",
|
|
array(':eventid' => $event->eid))
|
|
->fetchObject();
|
|
//check the number of people registered against the defined max
|
|
if ($waitinglist_query->num_ppl >= variable_get('booking_regn_limit', 350))
|
|
{
|
|
watchdog('booking', 'There are !num people booked in, which is greater than or equal to the limit of !limit.',
|
|
array('!num' => $waitinglist_query->num_ppl, '!limit' => variable_get('booking_regn_limit', 350) ));
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
watchdog('booking', 'There are !num people booked in, which is less than the limit of !limit.',
|
|
array('!num' => $waitinglist_query->num_ppl, '!limit' => variable_get('booking_regn_limit', 350) ));
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper function to check who is the first person on the waiting list
|
|
*/
|
|
function _booking_get_waitinglist_top()
|
|
{
|
|
global $event;
|
|
|
|
$result = db_query('SELECT p.nid, p.booking_firstname, p.booking_lastname, pay.booking_payment_date
|
|
FROM {booking_person} p, {booking_payment} pay
|
|
WHERE booking_status = 2 and booking_event_id = :eid and p.nid = pay.booking_person_nid
|
|
ORDER BY pay.booking_payment_date
|
|
LIMIT 1',
|
|
array(':eid' => $event->eid));
|
|
|
|
foreach ($result as $person)
|
|
{
|
|
watchdog('booking', "First person on the waiting list: @info", array('@info' => var_export($person, TRUE)));
|
|
return $person->nid;
|
|
}
|
|
//in case there was no one on the waiting list
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* Helper function to update the status of a registration
|
|
*/
|
|
function _booking_change_status($nid, $status_id)
|
|
{
|
|
db_update('booking_person')
|
|
->fields(array(
|
|
'booking_status' => $status_id,
|
|
))
|
|
->condition('nid', $nid)
|
|
->execute();
|
|
}
|
|
|
|
function _datearray_to_ts($date)
|
|
{
|
|
date_default_timezone_set(TIMEZONE);
|
|
$tz = new DateTimeZone(TIMEZONE);
|
|
|
|
if (empty($date) || ($date['month'] == '' && $date['day'] == '' && $date['year'] == ''))
|
|
return 0;
|
|
else
|
|
watchdog('booking', "Date array to timestamp: @info", array('@info' => var_export($date, TRUE)));
|
|
|
|
$gmt_ts = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
|
|
$ts = new DateTime("@$gmt_ts");
|
|
$ts->setTimezone($tz);
|
|
|
|
return $ts->format("U");
|
|
}
|
|
|
|
function _datetime_array_to_ts($date)
|
|
{
|
|
//watchdog('booking', 'Date-time Conversion: @info', array('@info' => var_export($date, TRUE)));
|
|
date_default_timezone_set(TIMEZONE);
|
|
$tz = new DateTimeZone(TIMEZONE);
|
|
|
|
$gmt_ts = mktime($date['hour'], $date['minute'], 0, $date['month'], $date['day'], $date['year']);
|
|
$ts = new DateTime("@$gmt_ts");
|
|
$ts->setTimezone($tz);
|
|
|
|
return $ts->format("U");
|
|
}
|
|
|
|
|
|
function _date_to_ts($date) {
|
|
$date_split = _split_date($date);
|
|
|
|
date_default_timezone_set(TIMEZONE);
|
|
$tz = new DateTimeZone(TIMEZONE);
|
|
|
|
if ($date_split[0] == '-1' )
|
|
return 0;
|
|
else
|
|
{
|
|
$gmt_ts = mktime(0, 0, 0, $date_split[2], $date_split[3], $date_split[1]);
|
|
$ts = new DateTime("@$gmt_ts");
|
|
$ts->setTimezone($tz);
|
|
|
|
return $ts->format("U");
|
|
}
|
|
//return mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[3], $date_split[1]);
|
|
}
|
|
|
|
function _datetime_to_ts($date) {
|
|
$date_split = _split_date($date);
|
|
|
|
date_default_timezone_set(TIMEZONE);
|
|
$tz = new DateTimeZone(TIMEZONE);
|
|
|
|
if ($date_split[0] == '-1' )
|
|
return 0;
|
|
else
|
|
{
|
|
$gmt_ts = mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[3], $date_split[1]);
|
|
$ts = new DateTime("@$gmt_ts");
|
|
$ts->setTimezone($tz);
|
|
|
|
return $ts->format("U");
|
|
}
|
|
//return mktime($date_split[5], $date_split[6], 0, $date_split[2], $date_split[3], $date_split[1]);
|
|
}
|
|
|
|
/**
|
|
* Function to split date into array
|
|
*
|
|
* @param $date in format YYYY-MM-DD
|
|
* @return array containing Year, Month, Day
|
|
*/
|
|
function _split_date($date) {
|
|
$pattern = '/^(\d{4})-(\d{2})-(\d{2})(\s(\d{2})\:(\d{2}))?/';
|
|
if (preg_match($pattern, $date, $matches)) {
|
|
return $matches;
|
|
} else {
|
|
return array('-1');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Function to re-arrange date
|
|
*
|
|
* @param $date in format YYYY-MM-DD
|
|
* @return array containing Year, Month, Day
|
|
*/
|
|
function _arrange_date($date) {
|
|
$pattern = '/^(\d{4})-(\d{2})-(\d{2})/';
|
|
if (preg_match($pattern, $date, $matches)) {
|
|
return $matches;
|
|
} else {
|
|
return array('-1');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper function to ensure timestamp is converted to correct local time
|
|
*/
|
|
function _booking_convert_ts($timestamp)
|
|
{
|
|
//load the timestamp
|
|
date_default_timezone_set(TIMEZONE);
|
|
$tz = new DateTimeZone(TIMEZONE);
|
|
|
|
$date = new DateTime("@$timestamp");
|
|
$date->setTimezone($tz);
|
|
|
|
return $date;
|
|
}
|
|
|
|
function _date_range_to_string($date_start, $date_end) {
|
|
$start = _split_date($date_start);
|
|
$end = _split_date($date_end);
|
|
$final_string = '';
|
|
|
|
//check for correctly formatted dates
|
|
if ($start[0] == '-1' || $end[0] == '-1') {
|
|
//incorrect response
|
|
form_set_error('yc_date_endbeforestart', t('Invalid date format received from !date or !date_end.', array('!date' => $date_start, '!date_end' => $date_end)));
|
|
} else {
|
|
//start with the day field
|
|
//mktime uses format month, day, year
|
|
$end_string = strftime("%e", mktime(12, 0, 0, $end[2], $end[3], $end[1]));
|
|
$start_string = strftime("%e", mktime(12, 0, 0, $start[2], $start[3], $start[1]));
|
|
|
|
//now include the month in the comparison. Compare including the year.
|
|
if (mktime(12, 0, 0, $end[2], 1, $end[1]) > mktime(12, 0, 0, $start[2], 1, $start[1])) {
|
|
//use the textual version to make things more readable
|
|
//strftime ( string $format [, int $timestamp = time() ] )
|
|
//%B Full month name, based on the locale
|
|
$end_string .= ' ' . strftime("%B", mktime(12, 0, 0, $end[2], 1, $end[1]));
|
|
$start_string .= ' ' . strftime("%B", mktime(12, 0, 0, $start[2], 1, $start[1]));
|
|
} else {
|
|
$end_string .= ' ' . strftime("%B", mktime(12, 0, 0, $end[2], 1, $end[1]));
|
|
//no need to append anything to $start_string
|
|
}
|
|
|
|
//create a timestamp based on 1 Jan that year to compare
|
|
if (mktime(12, 0, 0, 1, 1, $end[1]) > mktime(12, 0, 0, 1, 1, $start[1])) {
|
|
//create two seperate strings, one to hold the last part of the date range
|
|
//the other to hold the first part
|
|
$end_string .= ' ' . $end[1];
|
|
$start_string .= ' ' . $start[1];
|
|
} else {
|
|
$end_string .= ' ' . $end[1];
|
|
//no need to append anything to $start_string
|
|
}
|
|
|
|
//put both parts together
|
|
$final_string = $start_string . ' to ' . $end_string;
|
|
}
|
|
return $final_string;
|
|
}
|
|
|
|
|
|
//figure out if we're in the right time period for discounted registration rates
|
|
function _booking_is_earlybird()
|
|
{
|
|
global $event;
|
|
|
|
//figure out if we're in the earlybird rate section
|
|
//$early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array(
|
|
// ':eid' => $event->eid))
|
|
// ->fetchObject();
|
|
if ($event->booking_earlybird_close > time())
|
|
return TRUE;
|
|
else
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
function _booking_datepaid_ts($nid)
|
|
{
|
|
$query = db_query("SELECT * FROM {booking_payment} where booking_person_nid = :nid", array(':nid' => $nid))
|
|
->fetchObject();
|
|
|
|
if ($query)
|
|
return $query->booking_payment_date;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Helper function to return the amount for a booking deposit, if there is one
|
|
*/
|
|
function _booking_deposit_amount()
|
|
{
|
|
global $event;
|
|
|
|
$deposit = db_query("SELECT 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();
|
|
|
|
if ($deposit)
|
|
{
|
|
//if we're using paypal, add the transaction fee
|
|
if (variable_get('booking_use_paypal', 0) == 1)
|
|
{
|
|
//add the 30 cent fixed cost
|
|
$amount_owing = $deposit->booking_price + 0.3;
|
|
//and the 2.4 percent transaction fee
|
|
$amount_owing = $amount_owing / (1 - 0.024);
|
|
}
|
|
else
|
|
{
|
|
$amount_owing = $deposit->booking_price;
|
|
}
|
|
//return the calculated amount rounded to two decimal places
|
|
return number_format($amount_owing, 2, '.', '');
|
|
}
|
|
else
|
|
{
|
|
//there is no deposit amount
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Calculate exactly how much a person has already paid
|
|
*/
|
|
function _booking_amount_paid($nid, $person = NULL)
|
|
{
|
|
$amount_paid = 0;
|
|
|
|
//fetch details about the person if we don't already have them
|
|
if ($person == NULL)
|
|
{
|
|
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
|
|
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id " .
|
|
"FROM {booking_person} person, {booking_price} price " .
|
|
"WHERE person.nid = :nid " .
|
|
"AND person.booking_payment_id = price.pid",
|
|
array(':nid' => $nid))
|
|
->fetchObject();
|
|
}
|
|
|
|
//check for a spouse
|
|
if ($person->booking_partner_id > 0)
|
|
{
|
|
watchdog('booking', "Checking total paid for married person");
|
|
|
|
//if we're combining the payment for married couples
|
|
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
|
{
|
|
//check for payments in the paypal transaction table from either spouse
|
|
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid OR booking_person_nid = :spousenid",
|
|
array(':nid' => $nid, 'spousenid' => $person->booking_partner_id));
|
|
}
|
|
else {
|
|
//check for payments in the paypal transaction table from just this person
|
|
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid",
|
|
array(':nid' => $nid));
|
|
}
|
|
|
|
//add up all the payments
|
|
foreach ($query as $payment)
|
|
$amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee);
|
|
|
|
watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
|
|
|
|
//if there were no results, $amount_paid will still be 0
|
|
if ($amount_paid == 0)
|
|
{
|
|
//if we're combining the payment for married couples
|
|
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
|
{
|
|
$spouse = db_query("SELECT person.booking_amount_paid " .
|
|
"FROM {booking_person} person " .
|
|
"WHERE person.nid = :nid ",
|
|
array(':nid' => $person->booking_partner_id))
|
|
->fetchObject();
|
|
$amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid;
|
|
watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid);
|
|
}
|
|
else
|
|
{
|
|
$amount_paid = $person->booking_amount_paid;
|
|
watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Check if there are payment records in the paypal transaction table for this unmarried person
|
|
//if so, base their payments on the gross amount in there rather than what the person booking_person database says
|
|
$query = db_query("SELECT booking_mc_gross, booking_mc_fee FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid",
|
|
array(':nid' => $nid));
|
|
foreach ($query as $payment)
|
|
$amount_paid += ($payment->booking_mc_gross - $payment->booking_mc_fee);
|
|
|
|
//if there were no results, $amount_paid will still be 0
|
|
if ($amount_paid == 0)
|
|
$amount_paid = $person->booking_amount_paid;
|
|
//in case there has been some manual adjustment
|
|
//elseif ($amount_paid < $person->booking_amount_paid)
|
|
// $amount_paid = $person->booking_amount_paid;
|
|
}
|
|
|
|
watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
|
|
|
|
return $amount_paid;
|
|
}
|
|
|
|
//calculate the amount outstanding for a person/married couple
|
|
function _booking_amount_owing($nid, $amount_paid = 0)
|
|
{
|
|
//$amount_paid = 0;
|
|
$total_due = 0;
|
|
|
|
//fetch details about the person
|
|
$person = db_query("SELECT price.booking_price, price.booking_late_price, person.booking_payment_id, " .
|
|
"person.booking_total_pay_reqd, person.booking_amount_paid, person.booking_partner_id " .
|
|
"FROM {booking_person} person, {booking_price} price " .
|
|
"WHERE person.nid = :nid " .
|
|
"AND person.booking_payment_id = price.pid",
|
|
array(':nid' => $nid))
|
|
->fetchObject();
|
|
|
|
//check for early bird rate or full rate
|
|
if (_booking_is_earlybird() == TRUE)
|
|
$total_due = $person->booking_total_pay_reqd;
|
|
else
|
|
$total_due = $person->booking_late_price;
|
|
|
|
watchdog('booking', "Total amount due for this registration " . $nid . " is " . $total_due);
|
|
|
|
//if we didn't get the amount paid as a command line parameter, check it now
|
|
if ($amount_paid == 0)
|
|
{
|
|
watchdog('booking', "Checking total amount already paid by " . $nid);
|
|
$amount_paid = _booking_amount_paid($nid, $person);
|
|
}
|
|
|
|
/*
|
|
//check for a spouse
|
|
if ($person->booking_partner_id > 0)
|
|
{
|
|
watchdog('booking', "Checking outstanding balance for married person");
|
|
|
|
//if we're combining the payment for married couples
|
|
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
|
{
|
|
//check for payments in the paypal transaction table from either spouse
|
|
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid OR booking_person_nid = :spousenid",
|
|
array(':nid' => $nid, 'spousenid' => $person->booking_partner_id));
|
|
}
|
|
else {
|
|
//check for payments in the paypal transaction table from just this person
|
|
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid",
|
|
array(':nid' => $nid));
|
|
}
|
|
|
|
//add up all the payments
|
|
foreach ($query as $payment)
|
|
$amount_paid += $payment->booking_mc_gross;
|
|
|
|
watchdog('booking', "Total amount paid according to paypal payments table is " . $amount_paid);
|
|
|
|
//if there were no results, $amount_paid will still be 0
|
|
if ($amount_paid == 0)
|
|
{
|
|
//if we're combining the payment for married couples
|
|
if (variable_get('booking_enable_combined_pricing', 0) == 1)
|
|
{
|
|
$spouse = db_query("SELECT person.booking_amount_paid " .
|
|
"FROM {booking_person} person " .
|
|
"WHERE person.nid = :nid ",
|
|
array(':nid' => $person->booking_partner_id))
|
|
->fetchObject();
|
|
$amount_paid = $person->booking_amount_paid + $spouse->booking_amount_paid;
|
|
watchdog('booking', "Total combined payments for couple based on totals in booking_person table is " . $amount_paid);
|
|
}
|
|
else
|
|
{
|
|
$amount_paid = $person->booking_amount_paid;
|
|
watchdog('booking', "Total amount paid for individual based on totals in booking_person table is " . $amount_paid);
|
|
}
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Check if there are payment records in the paypal transaction table for this unmarried person
|
|
//if so, base their payments on the gross amount in there rather than what the person booking_person database says
|
|
$query = db_query("SELECT booking_mc_gross FROM booking_payment " .
|
|
"WHERE booking_person_nid = :nid",
|
|
array(':nid' => $nid));
|
|
foreach ($query as $payment)
|
|
$amount_paid += $payment->booking_mc_gross;
|
|
|
|
//if there were no results, $amount_paid will still be 0
|
|
if ($amount_paid == 0)
|
|
$amount_paid = $person->booking_amount_paid;
|
|
//in case there has been some manual adjustment
|
|
elseif ($amount_paid < $person->booking_amount_paid)
|
|
$amount_paid = $person->booking_amount_paid;
|
|
}
|
|
|
|
watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
|
|
*/
|
|
|
|
if ($amount_paid >= $total_due)
|
|
{
|
|
watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE)));
|
|
return 0;
|
|
}
|
|
|
|
//if we're using paypal, add the transaction fee
|
|
if (variable_get('booking_use_paypal', 0) == 1)
|
|
{
|
|
//add the 30 cent fixed cost
|
|
$amount_owing = $total_due - $amount_paid + 0.3;
|
|
//and the 2.4 percent transaction fee
|
|
$amount_owing = $amount_owing / (1 - 0.024);
|
|
}
|
|
else
|
|
$amount_owing = $total_due - $amount_paid;
|
|
return number_format($amount_owing, 2, '.', '');
|
|
}
|
|
|
|
/**
|
|
* Helper function to generate paypal form for payments
|
|
*/
|
|
function _booking_paypal_form($person, $invoiceid, $amount_owing, $button_text) {
|
|
return drupal_render(drupal_get_form('_booking_paypal_form_builder', $person, $invoiceid, $amount_owing, $button_text));
|
|
}
|
|
|
|
/**
|
|
* Helper function to generate form elements for paypal form
|
|
*/
|
|
function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
|
|
global $event;
|
|
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
|
|
|
|
//paypal specific settings
|
|
$vars = array(
|
|
'module' => 'Booking System',
|
|
'type' => $event->booking_eventname,
|
|
//'custom' => $data,
|
|
'item_name' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
|
|
'invoice' => $invoiceid,
|
|
'no_shipping' => TRUE,
|
|
'no_note' => TRUE,
|
|
'currency_code' => 'AUD',
|
|
'return' => url('bookingfinal', array('absolute' => TRUE)),
|
|
'cancel_return' => url($path, array('absolute' => TRUE)),
|
|
'rm' => '2',
|
|
'amount' => $amount_owing,
|
|
'last_name' => $person->booking_lastname,
|
|
'first_name' => $person->booking_firstname,
|
|
'cmd' => '_xclick',
|
|
'notify_url' => url(BOOKING_PAYPAL_IPN_PATH, array('absolute' => TRUE)),
|
|
'business' => variable_get('booking_paypal_account', '')
|
|
);
|
|
|
|
$form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE));
|
|
|
|
|
|
foreach($vars as $name => $value) {
|
|
$form[$name] = array(
|
|
'#type' => 'hidden',
|
|
'#value' => $value,
|
|
);
|
|
}
|
|
|
|
$form['submit'] = array(
|
|
'#type' => 'button',
|
|
'#value' => t($button_text),
|
|
);
|
|
|
|
//watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
|
|
return $form;
|
|
}
|
|
|
|
/**
|
|
* Helper function to format registrations details for summary in the confirmation email
|
|
*/
|
|
function _booking_details_email_summary($node) {
|
|
|
|
//query for payment type description
|
|
$payment_description_query = db_select('booking_price', 'p')
|
|
->condition('p.pid', $node->booking_payment_id,'=')
|
|
->fields('p', array('booking_price_descrip'))
|
|
->execute()
|
|
->fetchObject();
|
|
|
|
//watchdog('booking', "Payment description: @info", array('@info' => var_export($payment_description_query, TRUE)));
|
|
|
|
$rows = array();
|
|
$rows[] = t('Registration Reference Number: !id', array('!id' => $node->nid));
|
|
$rows[] = t('Date/Time registered: !timestamp', array('!timestamp' => _booking_convert_ts($node->booking_timestamp)->format('j F, Y H:i')));
|
|
$rows[] = t('Name: !first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname));
|
|
$rows[] = t('Gender: !gender', array('!gender' => $node->booking_gender == 'M' ? 'Male' : 'Female'));
|
|
$rows[] = t('Date of birth: !dob', array('!dob' => _booking_convert_ts($node->booking_dob)->format('d/m/Y')));
|
|
|
|
if (variable_get('booking_enable_passport', 1) == 1)
|
|
{
|
|
$rows[] = t('Passport Number: !value', array('!value' => $node->booking_passport_num));
|
|
$rows[] = t('Passport Expiry: !timestamp', array('!timestamp' => _booking_convert_ts($node->booking_passport_expiry_date)->format('d/m/Y')));
|
|
$rows[] = t('Passport Exact Issued Name: !value', array('!value' => $node->booking_passport_issue_name));
|
|
$rows[] = t('Passport Issue Location: !value', array('!value' => $node->booking_passport_issue_location));
|
|
}
|
|
|
|
$rows[] = t('Email address: !email', array('!email' => $node->booking_email));
|
|
$rows[] = t('Home Phone Number: !home', array('!home' => $node->booking_phone));
|
|
$rows[] = t('Mobile Phone Number: !mob', array('!mob' => $node->booking_mobile));
|
|
$rows[] = t("Postal Address:\n!street\n!suburb !state !code\n!country",
|
|
array('!street' => $node->booking_street, '!suburb' => $node->booking_suburb,
|
|
'!state' => $node->booking_state, '!code' => $node->booking_postcode,
|
|
'!country' => $node->booking_country));
|
|
$rows[] = t('Ecclesia: !ecclesia', array('!ecclesia' => $node->booking_ecclesia));
|
|
$rows[] = t('Baptised: !ans', array('!ans' => ($node->booking_baptised == 'Y' ? 'Yes' : 'No')));
|
|
$rows[] = t('Married: !ans', array('!ans' => ($node->booking_married == 'Y' ? 'Yes' : 'No')));
|
|
$rows[] = t("If married, attending partner's name: !name", array('!name' => $node->booking_partner_name));
|
|
|
|
if (variable_get('booking_enable_tshirts', 1) == 1)
|
|
$rows[] = t('Hoodie Size: !size', array('!size' => $node->booking_shirt_size));
|
|
|
|
$rows[] = t('Emergency Contact Name: !contact', array('!contact' => $node->booking_guardian_name));
|
|
$rows[] = t('Emergency Contact Relationship: !relationship', array('!relationship' => $node->booking_guardian_type));
|
|
$rows[] = t('Emergency Contact Phone: !phone', array('!phone' => $node->booking_guardian_phone));
|
|
$rows[] = t('Emergency Contact Alternate Phone: !phone', array('!phone' => $node->booking_guardian_phone_alt));
|
|
if (variable_get('booking_enable_medicare', 1) == 1)
|
|
$rows[] = t('Medicare Number: !medicare', array('!medicare' => $node->booking_medicare));
|
|
|
|
if (variable_get('booking_enable_roommate', 0) == 1)
|
|
{
|
|
$rows[] = t('Preferred room-mates: !room', array('!room' => $node->booking_room_mate1 . ' ' . $node->booking_room_mate2));
|
|
}
|
|
|
|
if (variable_get('booking_enable_helpareas', 1) == 1)
|
|
{
|
|
$help_areas = '';
|
|
if ($node->booking_help_music)
|
|
$help_areas .= 'music: ' . $node->booking_help_music . ', ';
|
|
if ($node->booking_help_reading == 'Y')
|
|
$help_areas .= 'reading, ';
|
|
if ($node->booking_help_chairing == 'Y')
|
|
$help_areas .= 'chairing, ';
|
|
if ($node->booking_help_readgroup_lead == 'Y')
|
|
$help_areas .= 'reading group leading, ';
|
|
if ($node->booking_help_discussgroup_lead == 'Y')
|
|
$help_areas .= 'discussion group leading, ';
|
|
if ($node->booking_help_praying == 'Y')
|
|
$help_areas .= 'praying, ';
|
|
if ($node->booking_help_meditations == 'Y')
|
|
$help_areas .= 'meditations, ';
|
|
|
|
$rows[] = t('Help areas: !help', array('!help' => $help_areas));
|
|
}
|
|
|
|
if (variable_get('booking_enable_skills', 1) == 1)
|
|
{
|
|
$skill_areas = '';
|
|
if ($node->booking_skills_builder == 'Y')
|
|
$skill_areas .= 'builder, ';
|
|
if ($node->booking_skills_cooking == 'Y')
|
|
$skill_areas .= 'cook, ';
|
|
if ($node->booking_skills_childminding == 'Y')
|
|
$skill_areas .= 'child minding, ';
|
|
if ($node->booking_skills_language == 'Y')
|
|
$skill_areas .= 'speaks languages: ' . $node->booking_skills_language_details . ', ';
|
|
if ($node->booking_skills_other == 'Y')
|
|
$skill_areas .= 'other skills: ' . $node->booking_skills_other_details . ', ';
|
|
$rows[] = t('Mission related skills: !value', array('!value' => $skill_areas));
|
|
$rows[] = t('Previous Mission Experience: !value', array('!value' => $node->booking_mission_experience_details));
|
|
}
|
|
$rows[] = t('Special Dietary Requirements: !dietary', array('!dietary' => $node->booking_dietary));
|
|
$rows[] = t('Special Medical Conditions: !medical', array('!medical' => $node->booking_medical_conditions));
|
|
$rows[] = t('Gross Amount Paid: !payment', array('!payment' => $node->booking_amount_paid));
|
|
$rows[] = t('Net Amount Due: !payment', array('!payment' => $node->booking_total_pay_reqd));
|
|
$rows[] = t('Payment Type: !payment', array('!payment' => $payment_description_query->booking_price_descrip));
|
|
|
|
foreach ($rows as $key => $value)
|
|
$rows[$key] = wordwrap($value);
|
|
return implode("\n", $rows);
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Generates a Universally Unique IDentifier, version 4.
|
|
*
|
|
* This function generates a truly random UUID. The built in CakePHP String::uuid() function
|
|
* is not cryptographically secure. You should uses this function instead.
|
|
*
|
|
* @see http://tools.ietf.org/html/rfc4122#section-4.4
|
|
* @see http://en.wikipedia.org/wiki/UUID
|
|
* @return string A UUID, made up of 32 hex digits and 4 hyphens.
|
|
*/
|
|
function _booking_uuidSecure() {
|
|
|
|
$pr_bits = null;
|
|
$fp = @fopen('/dev/urandom','rb');
|
|
if ($fp !== false) {
|
|
$pr_bits .= @fread($fp, 16);
|
|
@fclose($fp);
|
|
} else {
|
|
// If /dev/urandom isn't available (eg: in non-unix systems), use mt_rand().
|
|
$pr_bits = "";
|
|
for($cnt=0; $cnt < 16; $cnt++){
|
|
$pr_bits .= chr(mt_rand(0, 255));
|
|
}
|
|
}
|
|
|
|
$time_low = bin2hex(substr($pr_bits,0, 4));
|
|
$time_mid = bin2hex(substr($pr_bits,4, 2));
|
|
$time_hi_and_version = bin2hex(substr($pr_bits,6, 2));
|
|
$clock_seq_hi_and_reserved = bin2hex(substr($pr_bits,8, 2));
|
|
$node = bin2hex(substr($pr_bits,10, 6));
|
|
|
|
/**
|
|
* Set the four most significant bits (bits 12 through 15) of the
|
|
* time_hi_and_version field to the 4-bit version number from
|
|
* Section 4.1.3.
|
|
* @see http://tools.ietf.org/html/rfc4122#section-4.1.3
|
|
*/
|
|
$time_hi_and_version = hexdec($time_hi_and_version);
|
|
$time_hi_and_version = $time_hi_and_version >> 4;
|
|
$time_hi_and_version = $time_hi_and_version | 0x4000;
|
|
|
|
/**
|
|
* Set the two most significant bits (bits 6 and 7) of the
|
|
* clock_seq_hi_and_reserved to zero and one, respectively.
|
|
*/
|
|
$clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved);
|
|
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2;
|
|
$clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000;
|
|
|
|
return sprintf('%08s-%04s-%04x-%04x-%012s',
|
|
$time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node);
|
|
}
|