process names fields to always be Title Case
This commit is contained in:
@@ -72,6 +72,21 @@ function _booking_remove_emoji($text) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to convert text of any case to Title Case, specifically for names
|
||||||
|
* Taken from http://php.net/manual/en/function.ucwords.php
|
||||||
|
*/
|
||||||
|
function _booking_ucname($string) {
|
||||||
|
$string = ucwords(strtolower($string));
|
||||||
|
|
||||||
|
foreach (array('-', '\'') as $delimiter) {
|
||||||
|
if (strpos($string, $delimiter)!==false) {
|
||||||
|
$string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to perform some validity checking of email addresses
|
* Helper function to perform some validity checking of email addresses
|
||||||
@@ -107,30 +122,29 @@ function _valid_email_address($email) {
|
|||||||
*/
|
*/
|
||||||
function _valid_medicare_number($input) {
|
function _valid_medicare_number($input) {
|
||||||
//strip any whitespace
|
//strip any whitespace
|
||||||
$medicare = preg_replace( '/\s+/', '', $input );
|
$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])
|
//for testing, use the fake medicare number 111111110
|
||||||
{
|
|
||||||
watchdog('booking', 'Medicare number (!mca) validates since check digit !check matches remainder from !remainder',
|
if (is_numeric($medicare) && strlen($medicare) >= 9 && $medicare > 0) {
|
||||||
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
|
$check_digit = $medicare[0] + (3 * $medicare[1]) + (7 * $medicare[2]) + (9 * $medicare[3])
|
||||||
return TRUE;
|
+ $medicare[4] + (3 * $medicare[5]) + (7 * $medicare[6]) + (9 * $medicare[7]);
|
||||||
}
|
|
||||||
else
|
if (($check_digit % 10) == $medicare[8]) {
|
||||||
{
|
watchdog('booking', 'Medicare number (!mca) validates since check digit !check matches remainder from !remainder',
|
||||||
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));
|
||||||
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
|
return TRUE;
|
||||||
return FALSE;
|
}
|
||||||
}
|
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
|
else {
|
||||||
{
|
watchdog('booking', 'Medicare number (!mca) does not validate since it is either non-numeric or too short',
|
||||||
watchdog('booking', 'Medicare number (!mca) does not validate since it is either non-numeric or too short',
|
array('!mca' => $input));
|
||||||
array('!mca' => $input));
|
return FALSE;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@@ -917,7 +917,7 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
|
|||||||
if (variable_get('booking_enable_roommate', 0) == 1) {
|
if (variable_get('booking_enable_roommate', 0) == 1) {
|
||||||
$form['misc-areas']['booking_room_mate1'] = array(
|
$form['misc-areas']['booking_room_mate1'] = array(
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => t('List up to two people you would like to share a room with (subject to availability).'),
|
'#title' => t('List up to two people you would like to share a room with (subject to availability)'),
|
||||||
'#maxlength' => 200,
|
'#maxlength' => 200,
|
||||||
'#required' => FALSE,
|
'#required' => FALSE,
|
||||||
'#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : ''
|
'#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : ''
|
||||||
@@ -935,7 +935,7 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
|
|||||||
if (variable_get('booking_enable_songchoice', 0) == 1) {
|
if (variable_get('booking_enable_songchoice', 0) == 1) {
|
||||||
$form['misc-areas']['booking_song_choice'] = array(
|
$form['misc-areas']['booking_song_choice'] = array(
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => t("Let us know if there's a song you'd love to sing during the week."),
|
'#title' => t("Let us know if there's a song you'd love to sing during the week"),
|
||||||
'#maxlength' => 200,
|
'#maxlength' => 200,
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
'#default_value' => !empty($data->booking_song_choice) ? $data->booking_song_choice : ''
|
'#default_value' => !empty($data->booking_song_choice) ? $data->booking_song_choice : ''
|
||||||
@@ -1216,6 +1216,11 @@ function booking_form_submit($form, &$form_state)
|
|||||||
|
|
||||||
$values = $form_state['input'];
|
$values = $form_state['input'];
|
||||||
|
|
||||||
|
//do some preprocessing on input
|
||||||
|
//convert names from whatever case they're in to Title Case
|
||||||
|
$values['booking_firstname'] = _booking_ucname($values['booking_firstname']);
|
||||||
|
$values['booking_lastname'] = _booking_ucname($values['booking_lastname']);
|
||||||
|
|
||||||
//strip any emojis from user input
|
//strip any emojis from user input
|
||||||
if (variable_get('booking_enable_emoji_removal', 1) == 1) {
|
if (variable_get('booking_enable_emoji_removal', 1) == 1) {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
@@ -7,7 +7,7 @@ function booking_node_presave($node) {
|
|||||||
if($node->type == 'booking') {
|
if($node->type == 'booking') {
|
||||||
$title = t('!event registration: !name', array(
|
$title = t('!event registration: !name', array(
|
||||||
'!event' => $event->booking_eventname,
|
'!event' => $event->booking_eventname,
|
||||||
'!name' => $node->booking_firstname . ' ' . $node->booking_lastname,
|
'!name' => _booking_ucname($node->booking_firstname . ' ' . $node->booking_lastname),
|
||||||
));
|
));
|
||||||
|
|
||||||
//strip any emojis from user input if that feature is enabled
|
//strip any emojis from user input if that feature is enabled
|
||||||
@@ -447,7 +447,12 @@ function booking_update($node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//make sure the name is the correct case
|
||||||
|
$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)));
|
watchdog('booking', 'Updating node: @info', array('@info' => var_export($data, TRUE)));
|
||||||
db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
|
db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
|
||||||
/*
|
/*
|
||||||
|
@@ -148,12 +148,10 @@ function booking_report_summary() {
|
|||||||
$amount_owing = _booking_amount_owing($person, 0, FALSE);
|
$amount_owing = _booking_amount_owing($person, 0, FALSE);
|
||||||
|
|
||||||
//calculate the travel link
|
//calculate the travel link
|
||||||
if ($person->tid > 0)
|
if ($person->tid > 0) {
|
||||||
{
|
|
||||||
$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
|
$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$travel_link = t('N/A');
|
$travel_link = t('N/A');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user