Files
booking/booking.regn_node.inc
2019-09-10 09:49:26 +10:00

1072 lines
47 KiB
PHP

<?php
//Update node table specific attributes before hook_update is called
function booking_node_presave($node) {
global $event;
if($node->type == 'booking') {
$title = t('!event registration: !name', array(
'!event' => $event->booking_eventname,
// no longer needed since applied at node creation
'!name' => _booking_ucname($node->booking_firstname . ' ' . $node->booking_lastname),
//'!name' => $node->booking_firstname . ' ' . $node->booking_lastname,
));
//strip any emojis from user input if that feature is enabled
if (variable_get('booking_enable_emoji_removal', 1) == 1) {
$title = _booking_remove_emoji($title);
}
$node->title = $title;
}
}
/**
* Function to create a mysql view of all information relating to an attendee
*
* @param
* @return
*/
function _booking_node_create_mysqlview()
{
global $event;
$studygroups = array();
//sometimes we will execute when hook_init hasn't been called
//for example at install or upgrade time
//so query the database directly for the event currently active
if ($event == NULL) {
watchdog('booking_debug', "Calling _booking_node_create_mysqlview() when hook_init not yet run.");
$event = db_query("SELECT * from {booking_event} where booking_event_active=1")->fetchObject();
}
$query = db_select('booking_person', 'p');
//add price info
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
//add the join for earlyaccess code if enabled
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1) {
$query->leftJoin('booking_earlyaccess_codes', 'c', 'p.nid = c.booking_earlyaccess_code_nid');
}
//add travel form info if it exists
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
//add the joins for room allocation info if enabled
if (variable_get('booking_enable_roomallocations', 0) == 1) {
$query->leftJoin('booking_room_mapping', 'rm', 'p.nid = rm.booking_nodeid');
$query->leftJoin('booking_room_definition', 'r', 'rm.booking_roomid = r.rid');
$query->leftJoin('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
}
//add the joins to flatten out study groups into columns
if (variable_get('booking_enable_studygroups', 0) == 1) {
//get details of the study groups defined for this event
//but when this function gets called we don't have the global $event variable populated, so do the join here ourselves
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} l INNER JOIN {booking_event} e ON l.booking_eventid = e.eid WHERE e.booking_event_active=1");
$studygroups = $studygroups_query->fetchAllAssoc('sid');
foreach ($studygroups as $studygroup) {
$id = $studygroup->sid;
$query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id);
}
}
//add the joins for variety session info if enabled
if (variable_get('booking_enable_variety_sessions', 0) == 1) {
$query->leftJoin('booking_variety_regn', 'v', 'p.nid = v.booking_person_nid');
}
//filter the results either by current active event
// @todo is this filter really necessary?
$query->condition('p.booking_eventid', $event->eid, '=');
//add the database fields we always want to retrieve
$query->fields('p')
->fields('t')
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1) {
$query->fields('c', array('cid', 'booking_earlyaccess_code'));
}
if (variable_get('booking_enable_roomallocations', 0) == 1) {
$query->fields('rm', array('booking_room_bedtype'))
->fields('r', array('rid', 'booking_room_location_id', 'booking_room_number'))
->fields('l');
}
//now add the study group fields if applicable
if (variable_get('booking_enable_studygroups', 0) == 1) {
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->addField('s' . $id, 'booking_session_id', 'session' . $id);
$query->addField('s' . $id, 'booking_studygroup_role', 'session' . $id . '_role');
}
}
//add field for variety session registrations if enabled
if (variable_get('booking_enable_variety_sessions', 0) == 1) {
$query->fields('v', array('booking_variety_ids'));
}
//now that we have built the query as a SelectObject, turn it into a string we can use to create a view
$querystring=$query->__toString();
$querystring=str_replace("{",'',$querystring);
$querystring=str_replace("}",'',$querystring);
foreach($query->getArguments() as $key=> $item) {
if(!$item) {
$item = 'NULL';
}
$querystring=str_replace($key.')',$item.')',$querystring);
}
$querystring = "CREATE OR REPLACE VIEW booking_person_view AS " . $querystring;
watchdog('booking_debug', "<pre>Booking Person View creation query string:\n@info</pre>", array('@info' => print_r($querystring, true)));
$viewquery = db_query($querystring)->execute();
//$result = $viewquery->fetchObject();
watchdog('booking_debug', "<pre>Booking Person View creation result:\n@info</pre>", array('@info' => print_r($viewquery, true)));
}
/**
* Function to add single quote marks around a string
* @see booking_load_query
*
* @param $input - string to add quote marks around
* @return quoted string
*/
function _booking_quote_string($input) {
return sprintf("'%s'", $input);
}
/**
* Function to query the database for the complete object representing a registration
*
* @param $node_ids - a list of node IDs to query for
* @return list of objects
*/
function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
{
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
if (! is_null($node_ids)) {
$nid_string = implode(',', array_map('_booking_quote_string', $node_ids));
$query_string = "SELECT * FROM {booking_person_view} WHERE nid IN ( " . $nid_string . " )";
//watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r($query_string, true)));
$result = db_query($query_string)->fetchAllAssoc('nid');
}
else {
$result = db_query("SELECT * FROM {booking_person_view}")->fetchAllAssoc('nid');
}
//watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
return $result;
}
/**
* Function to query the database for the complete object representing a registration
*
* @param $node_ids - a list of node IDs to query for
* @return list of objects
*/
function booking_load_query_old($node_ids = NULL, $fetchAssoc = FALSE)
{
//$studygroup_count = variable_get('booking_studygroup_count','0');
$studygroups = array();
$query = db_select('booking_person', 'p');
//add price info
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
//add travel form info if it exists
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
//add the joins for room allocation info if enabled
if (variable_get('booking_enable_roomallocations', 0) == 1)
{
$query->leftJoin('booking_room_mapping', 'rm', 'p.nid = rm.booking_nodeid');
$query->leftJoin('booking_room_definition', 'r', 'rm.booking_roomid = r.rid');
$query->leftJoin('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id');
}
//add the joins to flatten out study groups into columns
if (variable_get('booking_enable_studygroups', 0) == 1)
{
//get details of the study groups defined for this event
//but when this function gets called we don't have the global $event variable populated, so do the join here ourselves
//TODO: Fix up all the other places where we stupidly hard coded study group numbers 1 to n instead of using the ids from the database (see commented out for loop below for an example)
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} l INNER JOIN {booking_event} e ON l.booking_eventid = e.eid WHERE e.booking_event_active=1");
$studygroups = $studygroups_query->fetchAllAssoc('sid');
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id);
}
/*
for ($i = 1; $i <= $studygroup_count; $i++)
{
$query->leftJoin('booking_studygroup_mapping', 's' . $i,
'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i);
}
*/
}
//filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id
if (! is_null($node_ids))
{
$query->condition('p.nid', $node_ids, 'IN');
}
else
{
$query->condition('p.booking_eventid', $event->eid, '=');
}
//add the database fields we always want to retrieve
$query->fields('p')
->fields('t')
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
if (variable_get('booking_enable_roomallocations', 0) == 1)
{
$query->fields('rm', array('booking_room_bedtype'))
->fields('r', array('rid', 'booking_room_location_id', 'booking_room_number'))
->fields('l');
}
//now add the study group fields if applicable
if (variable_get('booking_enable_studygroups', 0) == 1)
{
foreach ($studygroups as $studygroup)
{
$id = $studygroup->sid;
$query->addField('s' . $id, 'booking_session_id', 'session' . $id);
$query->addField('s' . $id, 'booking_studygroup_role', 'session' . $id . '_role');
}
/*
for ($i = 1; $i <= $studygroup_count; $i++)
{
//$label = "Group_" . $studygroups[$i]->booking_studygroup_descrip;
$query->addField('s' . $i, 'booking_session_id', 'session' . $i);
$query->addField('s' . $i, 'booking_studygroup_role', 'session' . $i . '_role');
//$query->addField('s' . $i, 'booking_is_leader', 'session' . $i . '_leader');
//$query->addField('s' . $i, 'booking_is_reserveleader', 'session' . $i . '_reserveleader');
//$query->addField('s' . $i, 'booking_is_helper', 'session' . $i . '_helper');
}
*/
}
watchdog('booking_debug', "<pre>Loading node query:\n@info</pre>", array('@info' => print_r( (string)$query, true)));
//get the query result as either an associative array
if ($fetchAssoc == TRUE)
{
$result = $query->execute()->fetchAllAssoc('nid');
}
else
{
$result = $query->execute();
}
//watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
return $result;
}
/**
* Function implementing hook_load for the node-type booking
* @see booking_load_query
*
* @param $nodes - An array of the nodes being loaded, keyed by nid
* @return nothing
*/
function booking_load($nodes) {
global $event;
$result = booking_load_query(array_keys($nodes));
//add that data to the array of node references
foreach ($result as $record)
{
//watchdog('booking', "<pre>Loading node:\n@info</pre>", array('@info' => print_r( $record, true)));
// run through each result row and add in the needed attributes
foreach ($record as $key => $value)
{
$nodes[$record->nid]->$key = $value;
}
}
//watchdog('booking', 'Final loaded node: @info', array('@info' => var_export($nodes, TRUE)));
// no return necessary since $nodes array members reference objects global to this function
}
function booking_insert($node) {
//TODO: Generalise this by using the keys from $node instead of hard coding everything
$data = array();
foreach ($node as $key => $value) {
//check if the key is a field that belongs in the database
if ((strpos($key, "booking_") === 0) || $key === "nid") {
$data[$key] = $value;
}
}
watchdog('booking_debug', "<pre>Inserting node:\n@info</pre>", array('@info' => print_r($data, TRUE)));
db_insert('booking_person')->fields($data)->execute();
/*
db_insert('booking_person')
->fields(array(
'nid' => $node->nid,
'booking_eventid' => $node->booking_eventid,
'booking_firstname' => $node->booking_firstname,
'booking_lastname' => $node->booking_lastname,
'booking_dob' => $node->booking_dob,
'booking_barcode' => $node->booking_barcode,
'booking_luckynum' => $node->booking_luckynum,
'booking_gender' => $node->booking_gender,
'booking_street' => $node->booking_street,
'booking_suburb' => $node->booking_suburb,
'booking_postcode' => $node->booking_postcode,
'booking_state' => $node->booking_state,
'booking_country' => $node->booking_country,
'booking_phone' => $node->booking_phone,
'booking_mobile' => $node->booking_mobile,
'booking_email' => $node->booking_email,
'booking_timestamp' => $node->booking_timestamp,
'booking_ecclesia' => $node->booking_ecclesia,
'booking_baptised' => $node->booking_baptised,
'booking_married' => $node->booking_married,
'booking_partner_name' => $node->booking_partner_name,
'booking_partner_id' => $node->booking_partner_id,
'booking_dependant_children' => $node->booking_dependant_children,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_shirt_size' => empty($node->booking_shirt_size) ? 'N/A' : $node->booking_shirt_size,
'booking_help_music' => $node->booking_help_music,
'booking_help_praying' => $node->booking_help_praying,
'booking_help_meditations' => $node->booking_help_meditations,
'booking_help_reading' => $node->booking_help_reading,
'booking_help_chairing' => $node->booking_help_chairing,
'booking_help_readgroup_lead' => $node->booking_help_readgroup_lead,
'booking_help_discussgroup_lead' => $node->booking_help_discussgroup_lead,
'booking_readinggroup' => $node->booking_readinggroup,
'booking_tempid' => $node->booking_tempid,
'booking_payment_id' => $node->booking_payment_id,
'booking_amount_paid' => $node->booking_amount_paid,
'booking_total_pay_reqd' => $node->booking_total_pay_reqd,
'booking_guardian_name' => $node->booking_guardian_name,
'booking_guardian_type' => $node->booking_guardian_type,
'booking_guardian_email' => $node->booking_guardian_email,
'booking_guardian_phone' => $node->booking_guardian_phone,
'booking_guardian_phone_alt' => $node->booking_guardian_phone_alt,
'booking_medicare' => empty($node->booking_medicare) ? '' : $node->booking_medicare,
'booking_lifesaver' => $node->booking_lifesaver,
'booking_firstaid' => $node->booking_firstaid,
'booking_nurse' => $node->booking_nurse,
'booking_doctor' => $node->booking_doctor,
'booking_dietary' => $node->booking_dietary,
'booking_medical_conditions' => $node->booking_medical_conditions,
'booking_has_mission_experience' => $node->booking_has_mission_experience,
'booking_mission_experience_details' => $node->booking_mission_experience_details,
'booking_skills_builder' => $node->booking_skills_builder,
'booking_skills_cooking' => $node->booking_skills_cooking,
'booking_skills_childminding' => $node->booking_skills_childminding,
'booking_skills_language' => $node->booking_skills_language,
'booking_skills_language_details' => $node->booking_skills_language_details,
'booking_skills_other' => $node->booking_skills_other,
'booking_skills_other_details' => $node->booking_skills_other_details,
'booking_status' => $node->booking_status,
'booking_welfare_required' => $node->booking_welfare_required,
'booking_payment_complete' => $node->booking_payment_complete,
'booking_refund_due' => $node->booking_refund_due,
'booking_refund_processed' => $node->booking_refund_processed,
'booking_committee_member' => $node->booking_committee_member,
'booking_random_facts' => $node->booking_random_facts,
'booking_comment_field' => $node->booking_comment_field,
))
->execute();
*/
}
/**
* Convert $node attribute values (from form) into appropriate formats for persistence
*
* @param $node from form submission
* @return nothing
*/
function booking_update($node) {
global $event;
$data = array();
//TODO: make sure these exclusions match with admin selected options (eg passport details)
//these fields should be stored in the database as Y or N, but come back from the FAPI as 1 or 0
$boolean_keys = array('booking_baptised', 'booking_married', 'booking_help_praying', 'booking_help_meditations', 'booking_help_reading',
'booking_help_chairing', 'booking_help_readgroup_lead', 'booking_help_discussgroup_lead', 'booking_lifesaver',
'booking_firstaid', 'booking_nurse', 'booking_doctor', 'booking_has_mission_experience', 'booking_skills_builder',
'booking_skills_cooking', 'booking_skills_childminding', 'booking_skills_language', 'booking_skills_other',
'booking_welfare_required', 'booking_payment_complete', 'booking_refund_processed', 'booking_committee_member'
);
//these fields should be zero if not defined
$default_zero_keys = array('booking_luckynum', 'booking_bf_gf_nid', 'booking_keepseparate_id', 'booking_refund_due', 'booking_earlyaccess_code_id',
'booking_prev_sw_count');
//some fields are present in $node from the SQL view we use that don't belong in booking_person so exclude them
$excluded_keys = array('booking_person_nid', 'booking_transport_type', 'booking_transport_from_morriset_reqd', 'booking_transport_to_morriset_reqd',
'booking_flightnum_inbound', 'booking_flight_datetime_inbound', 'booking_flightnum_outbound', 'booking_flight_datetime_outbound', 'booking_accom_before_reqd',
'booking_accom_before_staying_with', 'booking_accom_after_reqd', 'booking_accom_after_staying_with', 'booking_roomlocation_descrip',
'booking_roomlocation_active', 'booking_price', 'booking_price_descrip', 'booking_late_price', 'booking_earlyaccess_code',
'booking_room_bedtype', 'booking_room_location_id', 'booking_room_number', 'booking_agreement', 'booking_deposit_timestamp', 'booking_variety_ids'
);
//before we update this user, check what their previous registration status was
$previous_status = db_query("SELECT booking_status, booking_payment_id, booking_total_pay_reqd, booking_amount_paid FROM {booking_person} where nid = :nid", array(
':nid' => $node->nid))
->fetchObject();
// process the input data before updating database
foreach ($node as $key => $value) {
//check if the key is a field that belongs in the database
if ((strpos($key, "booking_") === 0) || $key === "nid") {
//what special handling does this field need?
//handle dates properly
if ((strpos($key, "booking_dob") === 0) || (strpos($key, "booking_passport_issue_date") === 0)) {
$data[$key] = _date_to_ts($value);
}
//skip these fields from the update of booking_person
elseif (in_array($key, $excluded_keys, FALSE)) {
//do nothing
}
//this field needs 0/1 translated to N/Y
elseif (in_array($key, $boolean_keys, FALSE)) {
$data[$key] = $value == 1 ? 'Y' : 'N';
}
//this field has a default value of zero rather than null
elseif (in_array($key, $default_zero_keys, FALSE)) {
$data[$key] = $value == '' ? 0 : $value;
}
//just handle this field normally
else {
if (variable_get('booking_enable_emoji_removal', 1) == 1) {
$data[$key] = _booking_remove_emoji($value);
}
else {
$data[$key] = $value;
}
}
}
}
//make sure the name is the correct case
//not really needed for node updates since it now applies at node creation
$data['booking_firstname'] = _booking_ucname($data['booking_firstname']);
$data['booking_lastname'] = _booking_ucname($data['booking_lastname']);
watchdog('booking', 'Updating node: @info', array('@info' => var_export($data, TRUE)));
db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
/*
//watchdog('booking', 'Updating node: @info', array('@info' => var_export($node, TRUE)));
db_update('booking_person')
->fields(array (
'booking_firstname' => $node->booking_firstname,
'booking_lastname' => $node->booking_lastname,
'booking_dob' => _date_to_ts($node->booking_dob),
'booking_barcode' => $node->booking_barcode,
'booking_luckynum' => $node->booking_luckynum == '' ? 0 : $node->booking_luckynum,
'booking_gender' => $node->booking_gender,
'booking_street' => $node->booking_street,
'booking_suburb' => $node->booking_suburb,
'booking_postcode' => $node->booking_postcode,
'booking_state' => $node->booking_state,
'booking_country' => $node->booking_country,
'booking_phone' => $node->booking_phone,
'booking_mobile' => $node->booking_mobile,
'booking_email' => $node->booking_email,
'booking_timestamp' => $node->booking_timestamp,
'booking_ecclesia' => $node->booking_ecclesia,
'booking_baptised' => ($node->booking_baptised == 1 ? 'Y' : 'N'),
'booking_married' => ($node->booking_married == 1 ? 'Y' : 'N'),
'booking_partner_name' => $node->booking_partner_name,
'booking_partner_id' => $node->booking_partner_id,
'booking_dependant_children' => $node->booking_dependant_children,
'booking_bf_gf_nid' => $node->booking_bf_gf_nid == '' ? 0 : $node->booking_bf_gf_nid,
'booking_keepseparate_id' => $node->booking_keepseparate_id == '' ? 0 : $node->booking_keepseparate_id,
'booking_room_mate1' => $node->booking_room_mate1,
'booking_room_mate2' => $node->booking_room_mate2,
'booking_random_facts' => $node->booking_random_facts,
'booking_shirt_size' => $node->booking_shirt_size,
'booking_help_music' => $node->booking_help_music,
'booking_help_praying' => ($node->booking_help_praying == 1 ? 'Y' : 'N'),
'booking_help_meditations' => ($node->booking_help_meditations == 1 ? 'Y' : 'N'),
'booking_help_reading' => ($node->booking_help_reading == 1 ? 'Y' : 'N'),
'booking_help_chairing' => ($node->booking_help_chairing == 1 ? 'Y' : 'N'),
'booking_help_readgroup_lead' => ($node->booking_help_readgroup_lead == 1 ? 'Y' : 'N'),
'booking_help_discussgroup_lead' => ($node->booking_help_discussgroup_lead == 1 ? 'Y' : 'N'),
'booking_readinggroup' => $node->booking_readinggroup,
'booking_tempid' => $node->booking_tempid,
'booking_payment_id' => $node->booking_payment_id,
'booking_total_pay_reqd' => $node->booking_total_pay_reqd,
'booking_amount_paid' => $node->booking_amount_paid,
'booking_refund_due' => $node->booking_refund_due == '' ? 0 : $node->booking_refund_due,
'booking_guardian_name' => $node->booking_guardian_name,
'booking_guardian_type' => $node->booking_guardian_type,
'booking_guardian_email' => $node->booking_guardian_email,
'booking_guardian_phone' => $node->booking_guardian_phone,
'booking_guardian_phone_alt' => $node->booking_guardian_phone_alt,
'booking_medicare' => $node->booking_medicare,
'booking_lifesaver' => ($node->booking_lifesaver == 1 ? 'Y' : 'N'),
'booking_firstaid' => ($node->booking_firstaid == 1 ? 'Y' : 'N'),
'booking_nurse' => ($node->booking_nurse == 1 ? 'Y' : 'N'),
'booking_doctor' => ($node->booking_doctor == 1 ? 'Y' : 'N'),
'booking_dietary' => $node->booking_dietary,
'booking_medical_conditions' => $node->booking_medical_conditions,
'booking_has_mission_experience' => ($node->booking_has_mission_experience == 1 ? 'Y' : 'N'),
'booking_mission_experience_details' => $node->booking_mission_experience_details,
'booking_skills_builder' => ($node->booking_skills_builder == 1 ? 'Y' : 'N'),
'booking_skills_cooking' => ($node->booking_skills_cooking == 1 ? 'Y' : 'N'),
'booking_skills_childminding' => ($node->booking_skills_childminding == 1 ? 'Y' : 'N'),
'booking_skills_language' => ($node->booking_skills_language == 1 ? 'Y' : 'N'),
'booking_skills_language_details' => $node->booking_skills_language_details,
'booking_skills_other' => ($node->booking_skills_other == 1 ? 'Y' : 'N'),
'booking_skills_other_details' => $node->booking_skills_other_details,
'booking_welfare_required' => ($node->booking_welfare_required == 1 ? 'Y' : 'N'),
'booking_payment_complete' => ($node->booking_payment_complete == 1 ? 'Y' : 'N'),
'booking_refund_processed' => ($node->booking_refund_processed == 1 ? 'Y' : 'N'),
'booking_committee_member' => ($node->booking_committee_member == 1 ? 'Y' : 'N'),
'booking_random_facts' => $node->booking_random_facts,
'booking_status' => $node->booking_status,
'booking_comment_field' => $node->booking_comment_field,
'booking_song_choice' => $node->booking_song_choice,
'booking_freestyle_text' => $node->booking_freestyle_text,
))
->condition('nid', $node->nid)
->execute();
*/
//***now process some post-update triggers***
//if booking_partner_id is set, make sure the nid it refers to has this node as its booking_partner_id
if ($node->booking_partner_id != 0) {
$partner = db_query("Select booking_partner_id from {booking_person} where nid = :nid",
array(':nid' => $node->booking_partner_id))
->fetchObject();
if ($partner->booking_partner_id == 0) {
watchdog('booking', 'Updating partner node !partner to refer to this node !nid',
array('!partner' => $node->booking_partner_id, '!nid' => $node->nid));
//update the partner id of the partner to refer to this node
db_update('booking_person')
->fields(array(
'booking_partner_id' => $node->nid,
))
->condition('nid', $node->booking_partner_id)
->execute();
}
}
//repeat the process for bf/gf
if ($node->booking_bf_gf_nid != 0) {
$partner = db_query("Select booking_bf_gf_nid from {booking_person} where nid = :nid",
array(':nid' => $node->booking_bf_gf_nid))
->fetchObject();
if ($partner->booking_bf_gf_nid == 0) {
watchdog('booking', 'Updating bf/gf node !partner to refer to this node !nid',
array('!partner' => $node->booking_bf_gf_nid, '!nid' => $node->nid));
//update the partner id of the partner to refer to this node
db_update('booking_person')
->fields(array(
'booking_bf_gf_nid' => $node->nid,
))
->condition('nid', $node->booking_bf_gf_nid)
->execute();
}
}
//status change triggers start here
//check if someone has moved to not-coming list from the booked-in list
if ($previous_status->booking_status == 1 && $node->booking_status == 3)
{
watchdog('booking', 'Detected person moving from Booked In list to No Longer Coming');
//let this person know their request has been processed
_booking_demoted_to_notcoming_email($node->nid);
//Calculate refund
$refund = _booking_process_refund($node);
drupal_set_message(t('Refund calculated for !first !last is $!refund.',
array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname, '!refund' => $refund)));
//Remove from any study groups
_booking_person_studygroups_cleanup($node->nid);
//Remove from any rooms allocated
_booking_person_rooms_cleanup($node->nid);
//check if there is room on the booked-in list
if (_booking_check_bookings_full() == False) {
watchdog('booking', 'Looks like there was room on the booked in list, so lets tell the next person');
//find the first person on the waiting list
$temp_nid = _booking_get_waitinglist_top();
//-1 means there was no one on the waiting list
if ($temp_nid != -1) {
//update their registration status
_booking_change_status($temp_nid,1);
//send them an email
_booking_promoted_from_waitinglist_email($temp_nid);
}
}
else {
watchdog('booking', 'Still no room on the booked in list though.');
}
// Update waiting list positions
_booking_waitinglist_update_trigger();
}
//check if someone has moved to booked-in list from waiting-list
elseif ($previous_status->booking_status == 2 && $node->booking_status == 1) {
watchdog('booking', 'Detected person moving from Waiting list to Booked In');
//send them an email
_booking_promoted_from_waitinglist_email($node->nid);
//see if there are others to process also
$waitinglist_nid = _booking_get_waitinglist_top();
//check if there is room on the booked-in list
while (_booking_check_bookings_full() == False && $waitinglist_nid > 0)
{
watchdog('booking', 'There is room on the booked in list, so process the next person on the waiting list, who has a node id of ' . $waitinglist_nid);
//update their registration status
_booking_change_status($waitinglist_nid, 1);
//send them an email
_booking_promoted_from_waitinglist_email($waitinglist_nid);
$waitinglist_nid = _booking_get_waitinglist_top();
}
// Update waiting list positions
_booking_waitinglist_update_trigger();
}
//check if someone has been demoted to the "missed payment deadline" status from being booked-in
elseif ($previous_status->booking_status == 1 && $node->booking_status == 4) {
watchdog('booking', 'Detected person moving from Booked In list to Missed Payment Deadline list.');
//let this person know they're no longer "booked in"
_booking_missedpayment_email($node->nid);
//Remove from any study groups
_booking_person_studygroups_cleanup($node->nid);
//Remove from any rooms allocated
_booking_person_rooms_cleanup($node->nid);
//check if there is room on the booked-in list
if (_booking_check_bookings_full() == False) {
watchdog('booking', 'Position available, so lets tell the next person');
//find the first person on the waiting list
$temp_nid = _booking_get_waitinglist_top();
//-1 means there was no one on the waiting list
if ($temp_nid != -1) {
//update their registration status
_booking_change_status($temp_nid, 1);
//send them an email
_booking_promoted_from_waitinglist_email($temp_nid);
}
}
else {
watchdog('booking', 'Still no room on the booked in list.');
}
}
//if someone is moving to the not-coming list from the waiting list
elseif ($previous_status->booking_status == 2 && $node->booking_status == 3) {
watchdog('booking', 'Detected person moving from waiting list to No Longer Coming');
//let this person know their request has been processed
_booking_demoted_to_notcoming_email($node->nid);
//Calculate refund
$refund = _booking_process_refund($node);
drupal_set_message(t('Refund calculated for !first !last is $!refund.',
array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname, '!refund' => $refund)));
//Remove from any study groups
_booking_person_studygroups_cleanup($node->nid);
}
//if we're not automatically sending emails on registration
//and someone moved from not-paid to booked-in (ie, manual payment process)
elseif (variable_get('booking_auto_confirm_email', 0) == 0 && $previous_status->booking_status == 0 && $node->booking_status == 1) {
watchdog('booking', 'Detected person moving from Not Paid list to Booked In list');
//make sure the booked in list isn't full
if (_booking_check_bookings_full() == False)
{
watchdog('booking', 'Confirmed room on the booked in list');
//send them an email
_booking_registration_email($node->nid, FALSE, FALSE);
//_booking_promoted_from_waitinglist_email($node->nid);
}
}
//if someone moved from the not-paid list to waiting list by manual update
elseif ($previous_status->booking_status == 0 && $node->booking_status == 2) {
watchdog('booking', 'Detected person moving from Not Paid list to Waiting List');
//create a manual payment entry of zero dollars
//so things like the waiting list report work
$result = db_insert('booking_payment')
->fields(array(
'booking_person_nid' => $node->nid,
'booking_eventid' => $event->eid,
'booking_mc_gross' => '0.00',
'booking_mc_currency' => 'AUD',
'booking_mc_fee' => '0.00',
'booking_quantity' => 1,
'booking_invoice' => 'ManualPayment',
'booking_payer_id' => '',
'booking_payment_date' => REQUEST_TIME,
'booking_payment_status' => '',
'booking_first_name' => $node->booking_firstname,
'booking_last_name' => $node->booking_lastname,
'booking_buyer_email' => '',
'booking_payer_status' => '',
'booking_item_name' => '',
'booking_ipn_track_id' => '',
))
->execute();
//send them an email
_booking_registration_email($node->nid, FALSE, FALSE);
}
//if the payment ID has changed then update the total pay required
if ($previous_status->booking_payment_id != $node->booking_payment_id) {
$total_due = 0;
watchdog('booking', 'Detected payment type change for attendee');
//look up the total pay required for the new payment id
$price = db_select('booking_price', 'p')
->condition('p.pid', $node->booking_payment_id,'=')
->fields('p', array('booking_price', 'booking_late_price'))
->execute()
->fetchObject();
/*
//check for early bird rate or full rate
if (_booking_is_earlybird() == TRUE)
$total_due = $price->booking_price;
else
$total_due = $price->booking_late_price;
*/
//always set the payment required to the "early" price, since the late price is calculated dynamically if required
//update the person with the new total pay required
db_update('booking_person')
->fields(array(
'booking_total_pay_reqd' => $price->booking_price,
))
->condition('nid', $node->nid)
->execute();
}
//end trigger processing
}
function booking_delete($node) {
$last = $node->booking_lastname;
$first = $node->booking_firstname;
//clean up other tables first
_booking_person_rooms_cleanup($node->nid);
_booking_person_studygroups_cleanup($node->nid);
//then clean up primary table
$num_deleted = db_delete('booking_person')
->condition('nid', $node->nid)
->execute();
$message = t("Successfully deleted !num row(s), corresponding to '!last, !first'",
array('!num' => $num_deleted, '!last' => $last, '!first' => $first));
drupal_set_message($message, $type = 'status');
}
/**
* Helper function to update the waiting list position for everyone on the waiting list
*/
function _booking_waitinglist_update_trigger()
{
global $event;
$waiting_list = _booking_get_waitinglist();
$counter = 1;
foreach ($waiting_list as $person) {
//watchdog('booking_debug', "Updating node !nid to have waitlist position of !counter", array('!nid' => $person->nid, '!counter' => $counter));
db_update('booking_person')
->fields(array(
'booking_waitlist_pos' => $counter++,
))
->condition('nid', $person->nid)
->execute();
}
}
function booking_view($node, $view_mode) {
global $event;
$rows = array();
$travel_rows = array();
//watchdog('booking_debug', 'booking view node: <pre>@info</pre>', array('@info' => print_r( $node, true)));
//calculate the price owed by this person
//if (_booking_is_earlybird() == true || _booking_amount_owing($node->nid) == 0)
if (_booking_is_earlybird() == true || _booking_amount_owing($node) == 0 || $node->booking_committee_member == 'Y' || $node->booking_welfare_required == 'Y') {
$price = $node->booking_price;
}
else {
$price = $node->booking_late_price;
}
//include the price description to display with this view
$payment_type = $node->booking_price_descrip . ' ($' . $price . ')';
//look up the actual name for a linked partner
if ($node->booking_partner_id != 0) {
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
array(':nid' => $node->booking_partner_id))
->fetchObject();
$partner_name = $query->booking_firstname . " " . $query->booking_lastname;
}
else {
$partner_name = "N/A";
}
//also look up the actual name if a boyfriend/girlfriend is defined
if ($node->booking_bf_gf_nid != 0) {
$query = db_query("Select booking_firstname, booking_lastname from {booking_person} where nid = :nid",
array(':nid' => $node->booking_bf_gf_nid))
->fetchObject();
$bf_gf = $query->booking_firstname . " " . $query->booking_lastname;
}
else {
$bf_gf = "N/A";
}
//define column widths along with the header
$header = array(
array('data' => t('Attribute'), 'width' => '40%'),
array('data' => t('Value'), 'width' => '60%'),
);
//now populate the table
$rows[] = array(t('Date/Time registered:'), t('!timestamp', array('!timestamp' => format_date($node->booking_timestamp, 'custom', 'd/m/Y H:i'))));
$rows[] = array(t('Name:'), t('!first !last', array('!first' => $node->booking_firstname, '!last' => $node->booking_lastname)));
$rows[] = array(t('Gender:'), t('!gender', array('!gender' => $node->booking_gender == 'M' ? 'Male' : 'Female')));
$rows[] = array(t('Status:'), t('!status', array('!status' => _booking_status_generate($node->booking_status))));
if (variable_get('booking_enable_earlyaccess_codes', 0) == 1) {
$rows[] = array(t('Early Access Code:'), t('!code', array('!code' => $node->booking_earlyaccess_code)));
}
$rows[] = array(t('Internal comments on this registration:'), t('<i>!comment</i>', array('!comment' => $node->booking_comment_field)));
$rows[] = array(t('Committee Member:'), t('!ans', array('!ans' => ($node->booking_committee_member == 'Y' ? '<b>Yes</b>' : 'No'))));
$rows[] = array(t('Welfare Required:'), $node->booking_welfare_required == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Barcode:'), t('!id', array('!id' => $node->booking_barcode)));
$rows[] = array(t('QR Code:'), t('!id', array('!id' => $node->booking_qrcode_url)));
$rows[] = array(t('Lanyard lucky number:'), $node->booking_luckynum);
$rows[] = array(t('Reading Group:'), t('!group', array('!group' => $node->booking_readinggroup)));
$rows[] = array(t('Date of birth:'), t('!dob', array('!dob' => format_date($node->booking_dob, 'custom', 'd/m/Y'))));
$rows[] = array(t('Email address:'), t('!email', array('!email' => $node->booking_email)));
$rows[] = array(t('Payment Type Selected:'), t('!amount_paid', array('!amount_paid' => $payment_type)));
$rows[] = array(t('Amount Paid:'), t('!amount_paid', array('!amount_paid' => $node->booking_amount_paid)));
$rows[] = array(t('Payment Complete Flag:'), t('!ans', array('!ans' => $node->booking_payment_complete == 'Y' ? 'Yes' : 'No')));
$rows[] = array(t('Total Amount Due:'), t('!amount_paid', array('!amount_paid' => $node->booking_total_pay_reqd)));
$rows[] = array(t('Refund Due:'), t('!amount_due', array('!amount_due' => $node->booking_refund_due)));
$rows[] = array(t('Refund Processed:'), t('!ans', array('!ans' => ($node->booking_refund_processed == 'Y' ? 'Yes' : 'No'))));
//$rows[] = array(t('Random Facts:'), t('!facts', array('!facts' => $node->booking_random_facts)));
if (variable_get('booking_enable_songchoice', 0) == 1) {
$rows[] = array(t('Song Choice:'), t('!song', array('!song' => $node->booking_song_choice)));
}
if (variable_get('booking_enable_freestyle', 0) == 1) {
$rows[] = array(t('Freestyle:'), t('!song', array('!song' => $node->booking_freestyle_text)));
}
if (variable_get('booking_enable_previous_studyweeks', 0) == 1) {
$rows[] = array(t('Number of previous SW:'), t('!sw', array('!sw' => $node->booking_prev_sw_count)));
}
if (variable_get('booking_enable_tshirts', 0) == 1) {
$rows[] = array(t('Hoodie Size:'), t('!size', array('!size' => $node->booking_shirt_size)));
}
$rows[] = array(t('Ecclesia:'), t('!ecclesia', array('!ecclesia' => $node->booking_ecclesia)));
$rows[] = array(t('Baptised:'), t('!ans', array('!ans' => ($node->booking_baptised == 'Y' ? 'Yes' : 'No'))));
$rows[] = array(t('Married:'), t('!ans', array('!ans' => ($node->booking_married == 'Y' ? 'Yes' : 'No'))));
if (variable_get('booking_ask_dependant_children', 0) == 1) {
$rows[] = array(t('Bringing dependant children:'), t('!ans', array('!ans' => ($node->booking_dependant_children == 'Y' ? 'Yes' : 'No'))));
}
$rows[] = array(t('Linked Partner:'), t($partner_name));
$rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf));
$rows[] = array(t('Node ID to keep separate:'), $node->booking_keepseparate_id == 0 ? 'N/A' : $node->booking_keepseparate_id);
$rows[] = array(t('Home Phone Number:'), t('!home', array('!home' => $node->booking_phone)));
$rows[] = array(t('Mobile Phone Number:'), t('!mob', array('!mob' => $node->booking_mobile)));
$rows[] = array(t('Postal Address:'), t('!street<br />!suburb !state !code<br />!country',
array('!street' => $node->booking_street, '!suburb' => $node->booking_suburb,
'!state' => ($node->booking_state == 'N/A' ? '' : $node->booking_state),
'!code' => $node->booking_postcode,
'!country' => $node->booking_country)));
$rows[] = array(t('Emergency Contact Name:'), $node->booking_guardian_name);
$rows[] = array(t('Emergency Contact Relationship:'), $node->booking_guardian_type);
$rows[] = array(t('Emergency Contact Email Address:'), $node->booking_guardian_email);
$rows[] = array(t('Emergency Contact Phone:'), $node->booking_guardian_phone);
$rows[] = array(t('Emergency Contact Alternate Phone:'), $node->booking_guardian_phone_alt);
if (variable_get('booking_enable_medicare', 1) == 1) {
$rows[] = array(t('Medicare Number:'), $node->booking_medicare);
}
$rows[] = array(t('Special Dietary Requirements:'), $node->booking_dietary);
$rows[] = array(t('Special Medical Conditions:'), $node->booking_medical_conditions);
if (variable_get('booking_enable_roommate', 0) == 1) {
$rows[] = array(t('Preferred room-mates:'), t('!room', array('!room' => $node->booking_room_mate1 . ' ' . $node->booking_room_mate2)));
}
if (variable_get('booking_enable_helpareas', 1) == 1) {
$rows[] = array(t('Qualified Life Saver:'), $node->booking_lifesaver == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Qualified First Aider:'), $node->booking_firstaid == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Qualified Nurse:'), $node->booking_nurse == 'Y' ? 'Yes' : 'No');
$rows[] = array(t('Qualified Doctor:'), $node->booking_doctor == 'Y' ? 'Yes' : 'No');
$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[] = array(t('Help areas:'), t('!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[] = array(t('Mission related skills:'), t('!value', array('!value' => $skill_areas)));
$rows[] = array(t('Previous Mission Experience:'), $node->booking_mission_experience_details);
}
$rows[] = array(t('Temporary UUID:'), $node->booking_tempid);
//display room allocation data if enabled
if (variable_get('booking_enable_roomallocations', 0) == 1) {
$room_heading = t("<h2>Room Allocation</h2><p>!link</p>",
array('!link' => l(t('Edit Room Allocation'), t('admin/booking/!id/edit-room', array('!id' => $node->nid)), array('query' => drupal_get_destination()) )
));
$room_rows = array();
//$room_rows[] = array(t('Room Location'), _booking_room_location_lookup($node->booking_room_location_id));
$room_rows[] = array(t('Room Location'), $node->booking_roomlocation_descrip);
$room_rows[] = array(t('Room Number'), $node->booking_room_number);
$room_rows[] = array(t('Bed Type'), _booking_room_bedtype_lookup($node->booking_room_bedtype));
$node->content['room-heading'] = array(
'#markup' => $room_heading,
'#weight' => 4,
);
$node->content['room-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $room_rows)),
'#weight' => 5,
);
}
//add the travel info if it has been defined for this attendee
if (! empty($node->tid)) {
$travel_heading = t("<h2>Travel Details</h2><p>!link</p>",
array('!link' => l(t('Edit Travel Details'), t('node/!id/edit', array('!id' => $node->tid)))
));
$travel_rows[] = array(t('Transport Type:'), $node->booking_transport_type);
$travel_rows[] = array(t('Catching the train to Study Week:'), $node->booking_transport_from_morriset_reqd == 1 ? 'Yes' : 'No');
$travel_rows[] = array(t('Inbound Flight Number:'), $node->booking_flightnum_inbound == '' ? 'N/A' : $node->booking_flightnum_inbound);
$travel_rows[] = array(t('Flight Arrival:'), t('!date',
array('!date' => $node->booking_flight_datetime_inbound == 0 ? 'N/A' : format_date($node->booking_flight_datetime_inbound, 'custom', 'd/m/Y H:i'))));
$travel_rows[] = array(t('Outbound Flight Number:'), $node->booking_flightnum_outbound == '' ? 'N/A' : $node->booking_flightnum_outbound);
$travel_rows[] = array(t('Flight Departure:'), t('!date',
array('!date' => $node->booking_flight_datetime_outbound == 0 ? 'N/A' : format_date($node->booking_flight_datetime_outbound, 'custom', 'd/m/Y H:i'))));
$travel_rows[] = array(t('Accommodation before Study Week Required:'), $node->booking_accom_before_reqd == 1 ? 'Yes' : 'No');
$travel_rows[] = array(t('Accommodation after Study Week Required:'), $node->booking_accom_after_reqd == 1 ? 'Yes' : 'No');
$node->content['travel-heading'] = array(
'#markup' => $travel_heading,
'#weight' => 6,
);
$node->content['travel-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $travel_rows)),
'#weight' => 7,
);
}
//display study session data if enabled
if (variable_get('booking_enable_studygroups', 0) == 1)
{
$studygroup_heading = t("<h2>Study Groups</h2><p>!link</p>",
array('!link' => l(t('Edit Groups'), t('admin/booking/!id/edit-studygroup-membership', array('!id' => $node->nid)))
));
$group_rows = array();
//look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid');
//watchdog('booking', "<pre>Displaying node studygroups query output:\n@info</pre>", array('@info' => print_r( $studygroups, true)));
foreach ($studygroups as $studygroup) {
//calculate the session references
$sessionid = "session" . $studygroup->sid;
$roleid = $sessionid . "_role";
$group_rows[] = array(t('<b>' . $studygroup->booking_studygroup_descrip . '</b> group number'), $node->$sessionid);
$group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid));
}
//only add to the render array if there were some study groups found
if (count($group_rows) > 0) {
$node->content['group-heading'] = array(
'#markup' => $studygroup_heading,
'#weight' => 8,
);
$node->content['group-details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $group_rows)),
'#weight' => 9,
);
}
}
$node->content['details'] = array(
'#markup' => theme('table', array('header' => $header, 'rows' => $rows)),
'#weight' => 1,
);
//all finished, let's render this mess
return $node;
}