Tweaks to refunds, study groups, travel emails
This commit is contained in:
@@ -11,7 +11,9 @@ function booking_import_data_admin()
|
||||
{
|
||||
global $event;
|
||||
|
||||
$prefix = "<p>Upload csv file containing data to import. Minimum fields present should be <strong>nid,booking_status,booking_total_pay_reqd,booking_amount_paid</strong> with column names matching that exactly (case sensitive).</p>";
|
||||
$prefix = t("<p>Upload csv file containing data to import. Minimum fields present should be <strong>nid</strong>, " .
|
||||
" along with user-specified fields of <strong>!config</strong>. CSV Column names should match exactly (case sensitive).</p>",
|
||||
array('!config' => variable_get('booking_import_include_fields', '')));
|
||||
|
||||
$form = array();
|
||||
|
||||
@@ -59,12 +61,16 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
{
|
||||
global $event;
|
||||
$array = array();
|
||||
$expected_fields = array('nid', 'booking_amount_paid', 'booking_total_pay_reqd', 'booking_status');
|
||||
//$expected_fields = array('nid', 'booking_amount_paid', 'booking_total_pay_reqd', 'booking_status');
|
||||
$error = false;
|
||||
$update_counter = 0;
|
||||
$delimiter = ",";
|
||||
$result_array = array();
|
||||
|
||||
$builtin_fields_to_import = array('nid', 'booking_status');
|
||||
$custom_fields_to_import = explode(";", variable_get('booking_import_include_fields', ''));
|
||||
$fields_to_import = array_merge($builtin_fields_to_import, $custom_fields_to_import);
|
||||
|
||||
//get the file name from temporary storage field
|
||||
$file = $form_state['storage']['file'];
|
||||
// We are done with the file, remove it from storage.
|
||||
@@ -82,7 +88,7 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
$headerRecord = $rowData;
|
||||
} else {
|
||||
foreach( $rowData as $key => $value) {
|
||||
$array[ $rowCounter - 1][ $headerRecord[ $key] ] = $value;
|
||||
$array[$rowCounter - 1][ $headerRecord[$key] ] = $value;
|
||||
}
|
||||
}
|
||||
$rowCounter++;
|
||||
@@ -95,14 +101,18 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
return;
|
||||
}
|
||||
|
||||
//watchdog('booking', "<pre>Import data:\n@info</pre>", array('@info' => print_r( $array, true)));
|
||||
|
||||
//process the input data
|
||||
foreach ($array as $record)
|
||||
{
|
||||
//watchdog('booking', 'Processing user record: @info', array ('@info' => $record['nid']));
|
||||
//watchdog('booking', "<pre>Processing row data:\n@info</pre>", array('@info' => print_r( $record, true)));
|
||||
$update_counter++;
|
||||
$update_text = "";
|
||||
$update_array = array();
|
||||
|
||||
//do some error checking
|
||||
foreach($expected_fields as $field)
|
||||
foreach($fields_to_import as $field)
|
||||
{
|
||||
/*
|
||||
if (! isset($record[$field]))
|
||||
@@ -110,17 +120,44 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
if ($record[$field] == '')
|
||||
watchdog('booking', 'Blank field !field: !info', array ('!field' => $field, '!info' => var_export($record, TRUE)));
|
||||
*/
|
||||
|
||||
if ( (! isset($record[$field])) || $record[$field] == '' )
|
||||
|
||||
//make sure to skip the nid field since we can't update that
|
||||
if ($field == 'nid')
|
||||
{
|
||||
drupal_set_message("Error: Unable to locate expected field '$field' in input file for record number $update_counter.", 'error', FALSE);
|
||||
//do nothing
|
||||
}
|
||||
//convert the booking status to the number used internally
|
||||
elseif ($field == 'booking_status')
|
||||
{
|
||||
$update_array[$field] = _booking_status_lookup($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;
|
||||
//continue 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$update_text .= " set '" . $field . "' to '" . $record[$field] . "'; ";
|
||||
$update_array[$field] = $record[$field];
|
||||
}
|
||||
}
|
||||
|
||||
drupal_set_message(t("Updating record !nid as follows: !update", array('!nid' => $record['nid'], '!update' => $update_text)));
|
||||
|
||||
$query = db_update('booking_person')
|
||||
->fields($update_array)
|
||||
->condition('nid', $record['nid']);
|
||||
$rows = $query->execute();
|
||||
|
||||
//$args = $query->getArguments();
|
||||
|
||||
watchdog('booking', "Update Query:<br />@info<br />Rows affected<br />@rows", array('@info' => (string) $query, '@rows' => $rows));
|
||||
|
||||
/*
|
||||
$result_array[] = t('Setting payment for id !nid to $!price of total required $!total and status to !status',
|
||||
array('!nid' => $record['nid'],
|
||||
'!price' => $record['booking_amount_paid'],
|
||||
@@ -128,6 +165,8 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
'!status' => _booking_status_lookup($record['booking_status'])
|
||||
)
|
||||
);
|
||||
*/
|
||||
/*
|
||||
//TODO: output this from $result_array
|
||||
drupal_set_message(t('Setting payment for id !nid to $!price of total required $!total and status to !status',
|
||||
array('!nid' => $record['nid'],
|
||||
@@ -135,10 +174,12 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
'!total' => $record['booking_total_pay_reqd'],
|
||||
'!status' => _booking_status_lookup($record['booking_status']))
|
||||
));
|
||||
*/
|
||||
|
||||
// watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status',
|
||||
// array('!nid' => $record['nid'], '!price' => $record['booking_amount_paid'], '!status' => _booking_status_lookup($record['booking_status'])));
|
||||
|
||||
/*
|
||||
db_update('booking_person')
|
||||
->fields(array(
|
||||
'booking_amount_paid' => $record['booking_amount_paid'],
|
||||
@@ -147,11 +188,12 @@ function booking_import_data_admin_submit($form, &$form_state)
|
||||
))
|
||||
->condition('nid', $record['nid'])
|
||||
->execute();
|
||||
*/
|
||||
|
||||
} //end processing input data
|
||||
|
||||
//output our results to watchdog
|
||||
watchdog('booking', '<pre>@print_r</pre>', array('@print_r', print_r( $result_array, TRUE)));
|
||||
//watchdog('booking', '<pre>@print_r</pre>', array('@print_r', print_r( $result_array, TRUE)));
|
||||
|
||||
//delete the uploaded file
|
||||
file_delete($file);
|
||||
|
Reference in New Issue
Block a user