add QR code and change import csv page

This commit is contained in:
Nathan Coad
2018-06-22 17:15:29 +10:00
parent 8d83e08419
commit 94cf7b89b5
3 changed files with 41 additions and 32 deletions

View File

@@ -22,6 +22,17 @@ function booking_import_data_admin()
'#description' => t('Upload CSV data to be processed'),
);
$booking_view_fields = _booking_get_person_fields();
$form['booking_import_data_fields'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Select database fields for this import'),
'#description' => t('Select database fields to import from an uploaded CSV file. Ensure you hold down control/command when selecting multiple options.'),
'#options' => $booking_view_fields,
//'#default_value' => variable_get('booking_import_include_fields_dynamic', ''),
);
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Submit'),
@@ -59,7 +70,7 @@ function booking_import_data_admin_validate($form, &$form_state) {
function booking_import_data_admin_submit($form, &$form_state)
{
global $event;
$array = array();
$csvdata = array();
//$expected_fields = array('nid', 'booking_amount_paid', 'booking_total_pay_reqd', 'booking_status');
$error = false;
$update_counter = 0;
@@ -69,8 +80,11 @@ function booking_import_data_admin_submit($form, &$form_state)
$datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts',
'booking_rtrnflight_destination_ts','booking_dob', 'booking_passport_expiry_date');
$builtin_fields_to_import = array('nid');
$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
$fields_to_import = array_merge($builtin_fields_to_import, $custom_fields_to_import);
//$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
$data = $form_state['input'];
$import_fields = $data['booking_import_data_fields']
$fields_to_import = array_merge($builtin_fields_to_import, $import_fields);
watchdog('booking_debug', "<pre>CSV import fields\n@info</pre>", array('@info' => print_r($fields_to_import, true)));
//get the file name from temporary storage field
$file = $form_state['storage']['file'];
@@ -92,7 +106,7 @@ function booking_import_data_admin_submit($form, &$form_state)
$headerRecord = $rowData;
} else {
foreach( $rowData as $key => $value) {
$array[$rowCounter - 1][ $headerRecord[$key] ] = $value;
$csvdata[$rowCounter - 1][ $headerRecord[$key] ] = $value;
}
}
$rowCounter++;
@@ -105,11 +119,10 @@ function booking_import_data_admin_submit($form, &$form_state)
return;
}
//watchdog('booking', "<pre>Import data:\n@info</pre>", array('@info' => print_r( $array, true)));
//watchdog('booking', "<pre>Import data:\n@info</pre>", array('@info' => print_r( $csvdata, true)));
//process the input data
foreach ($array as $record)
{
foreach ($csvdata as $record) {
$rows = 0;
//watchdog('booking', "<pre>Processing row data:\n@info</pre>", array('@info' => print_r( $record, true)));
$update_counter++;
@@ -119,61 +132,45 @@ function booking_import_data_admin_submit($form, &$form_state)
$studygroup_roles_update_array = array();
//do some error checking
foreach($fields_to_import as $field)
{
/*
if (! isset($record[$field]))
watchdog('booking', 'Non-set field !field: !info', array ('!field' => $field, '!info' => var_export($record, TRUE)));
if ($record[$field] == '')
watchdog('booking', 'Blank field !field: !info', array ('!field' => $field, '!info' => var_export($record, TRUE)));
*/
foreach($fields_to_import as $field) {
//make sure to skip the nid field since we can't update that
if ($field == 'nid')
{
if ($field == 'nid') {
//do nothing
}
//convert the booking status to the number used internally
elseif ($field == 'booking_status')
{
elseif ($field == 'booking_status') {
$update_text .= " set booking status to '" . $record[$field] . "'; ";
$update_array[$field] = _booking_status_lookup($record[$field]);
}
//check for fields that need to be converted to a timestamp from text
elseif (in_array($field, $datetime_fields))
{
elseif (in_array($field, $datetime_fields)) {
$update_array[$field] = _datetime_to_ts_nonstrict($record[$field]);
$update_text .= " set '" . $field . "' to '" . $update_array[$field] . "'; ";
}
elseif ( (! isset($record[$field])) || $record[$field] == '' )
{
elseif ( (! isset($record[$field])) || $record[$field] == '') {
//drupal_set_message("Error: Unable to locate expected field '$field' in input file for record number $update_counter.", 'error', FALSE);
//watchdog('booking', 'Processing user record: @info', array ('@info' => $record['nid']));
//$error = true;
//skip to the next record
//continue 2;
}
elseif (preg_match('/session(\d{1,2})_role/i', $field, $matches))
{
elseif (preg_match('/session(\d{1,2})_role/i', $field, $matches)) {
$session_id = $matches[1];
//drupal_set_message(t('Setting session id !field role to value: !info', array ('!field' => $session_id, '!info' => var_export($record[$field], TRUE))));
$studygroup_roles_update_array[$session_id] = $record[$field];
}
elseif (preg_match('/session(\d{1,2})$/i', $field, $matches))
{
elseif (preg_match('/session(\d{1,2})$/i', $field, $matches)) {
$session_id = $matches[1];
//drupal_set_message(t('Setting session id !field group to value: !info', array ('!field' => $session_id, '!info' => var_export($record[$field], TRUE))));
$studygroups_update_array[$session_id] = $record[$field];
}
else
{
else {
$update_text .= " set '" . $field . "' to '" . $record[$field] . "'; ";
$update_array[$field] = $record[$field];
}
}
if (count($update_array) > 0)
{
if (count($update_array) > 0) {
$query = db_update('booking_person')
->fields($update_array)
->condition('nid', $record['nid']);

View File

@@ -811,6 +811,17 @@ function booking_update_7256() {
_booking_node_create_mysqlview();
}
/**
* Add field to store URL to QR code
*/
function booking_update_7257() {
$spec = array('type' => 'varchar', 'length' => '500', 'not null' => FALSE);
db_add_field('booking_person', 'booking_qrcode_url', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/**
* Implementation of hook_install().
*/

View File

@@ -873,6 +873,7 @@ function booking_view($node, $view_mode) {
$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'))));