'max-width:30%'); //define sorting information with the header //as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7 $header = array(); $header[] = array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'); $header[] = array('data' => t('Name'), 'field' => 'booking_lastname'); $header[] = array('data' => t('Booking Status'), 'field' => 'booking_status'); if (variable_get('booking_enable_studygroups', 0) == 1) { $header[] = array('data' => t('Studygroups')); } if (variable_get('booking_enable_roomallocations', 0) == 1) { $header[] = array('data' => t('Room')); } $header[] = array('data' => t('Travel')); $header[] = array('data' => t('Email'), 'field' => 'booking_email'); $header[] = array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'); $header[] = array('data' => t('Total Payment Required')); $header[] = array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'); $header[] = array('data' => t('Refund Processed?'), 'field' => 'booking_refund_processed'); $header[] = array('data' => t('Refund Due'), 'field' => 'booking_refund_due'); $header[] = array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'); $header[] = array('data' => t('Committee?'), 'field' => 'booking_committee_member'); $rows = array(); //the state summary table $state_header = array('State', 'Count', 'Males', 'Females', 'Baptised', 'Male Average Age', 'Female Average Age', 'Overall Average Age'); $state_rows = array(); $state_statistics = array(); //$state_statistics = new stdClass(); //do some analysis about the people booked in //first the summary of states $query = db_select('booking_person', 'p') ->fields('p', array('booking_state', 'booking_country')); //include people either booked in or on the waiting list, that belong to the current event id $db_or = db_or(); $db_or->condition('p.booking_status', 1, '='); $db_or->condition('p.booking_status', 2, '='); $db_and = db_and()->condition($db_or)->condition('p.booking_eventid', $event->eid, '='); $query->condition($db_and); $query->groupBy('p.booking_state'); $query->addExpression('COUNT(p.booking_state)', 'state_count'); $query->orderBy('state_count', 'DESC'); $state_stats = $query->execute(); //TODO: add some info to a hash so we can calculate age info and generate the actual rows after the more detailed summary loop //include count of guys, girls, minimum, maximum and average ages foreach ($state_stats as $state) { if (strcmp($state->booking_country,'Australia') == 0 ) { //$state_rows[] = array($state->booking_state, $state->state_count); //store the total count for this state if (!isset($state_statistics[$state->booking_state])) { $state_statistics[$state->booking_state] = new stdClass(); } $state_statistics[$state->booking_state]->total_count = $state->state_count; $state_statistics[$state->booking_state]->male_count = 0; $state_statistics[$state->booking_state]->male_avg = 0; $state_statistics[$state->booking_state]->female_count = 0; $state_statistics[$state->booking_state]->female_avg = 0; $state_statistics[$state->booking_state]->total_avg = 0; $state_statistics[$state->booking_state]->baptised_count = 0; } else { $non_australia_count += $state->state_count; } } //non australian states //$state_rows[] = array('International', $non_australia_count); $state_statistics['International'] = new stdClass(); $state_statistics['International']->total_count = $non_australia_count; $state_statistics['International']->male_count = 0; $state_statistics['International']->male_avg = 0; $state_statistics['International']->female_count = 0; $state_statistics['International']->female_avg = 0; $state_statistics['International']->total_avg = 0; $state_statistics['International']->baptised_count = 0; //the ecclesia summary table $ecclesia_header = array('State','Ecclesia', 'Count'); $ecclesia_rows = array(); //bookings by ecclesia $query = db_select('booking_person', 'p') ->fields('p', array('booking_ecclesia','booking_state')) ->condition('p.booking_eventid', $event->eid, '='); $query->groupBy('p.booking_ecclesia'); $query->addExpression('COUNT(p.booking_ecclesia)', 'ecclesia_count'); $query->orderBy('booking_state') ->orderBy('ecclesia_count','DESC'); $stats = $query->execute(); foreach ($stats as $ecclesia) { $ecclesia_rows[] = array($ecclesia->booking_state,$ecclesia->booking_ecclesia, $ecclesia->ecclesia_count); } //more detailed summary //allow user-selectable sorting of columns as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7 $query = db_select('booking_person', 'p'); $query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id'); $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid'); $query->condition('p.booking_eventid', $event->eid, '=') ->fields('p') ->fields('t') ->fields('pr', array('booking_price', 'booking_late_price')); $table_sort = $query->extend('TableSort')->orderbyHeader($header); $result = $table_sort->execute(); foreach ($result as $person) { $this_row = array(); //$amount_owing = _booking_amount_owing($person->nid, 0, FALSE); $amount_owing = _booking_amount_owing($person, 0, FALSE); //calculate the travel link if ($person->tid > 0) { $travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid))); } else { $travel_link = t('N/A'); } //define the row for this person $this_row[] = l(t('Edit !id', array('!id' => $person->nid)), t('node/!id/edit', array('!id' => $person->nid))); $this_row[] = l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), t('node/!id', array('!id' => $person->nid)) ); $this_row[] = _booking_status_generate($person->booking_status); if (variable_get('booking_enable_studygroups', 0) == 1) { $this_row[] = l(t('Groups'), t('admin/booking/!id/edit-studygroup-membership', array('!id' => $person->nid))); } if (variable_get('booking_enable_roomallocations', 0) == 1) { $this_row[] =l(t('Room'), t('admin/booking/!id/edit-room', array('!id' => $person->nid))); } $this_row[] = $travel_link; $this_row[] = t('!email', array('!email' => $person->booking_email)); $this_row[] = t('!payment', array('!payment' => $person->booking_amount_paid)); $this_row[] = t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person))); //$this_row[] = t('!fullypaid', array('!fullypaid' => $amount_owing == 0 ? 'Yes' : 'No')); $this_row[] = t('!fullypaid', array('!fullypaid' => $person->booking_payment_complete == 'Y' ? 'Yes' : 'No')); $this_row[] = t('!reqd', array('!reqd' => $person->booking_refund_processed == 'Y' ? 'Yes' : 'No')); $this_row[] = t('!payment', array('!payment' => $person->booking_refund_due)); $this_row[] = t($person->booking_welfare_required == 'Y' ? 'Yes' : 'No'); $this_row[] = t($person->booking_committee_member == 'Y' ? 'Yes' : 'No'); $rows[] = $this_row; //add up the total paid $total_paid += $person->booking_amount_paid; //subtract any refund if ($person->booking_refund_processed == 'Y' && $person->booking_refund_due > 0) { $total_refunds += $person->booking_refund_due; } //travel form completed? if (! empty($person->tid)) $travelform_count++; //booking status if ($person->booking_status == 0) $notpaid_counter++; elseif ($person->booking_status == 1) $bookedin_counter++; elseif ($person->booking_status == 2) $waiting_counter++; elseif ($person->booking_status == 5) $hosts_counter++; else $notcoming_counter++; //welfare if ($person->booking_welfare_required == 'Y') $welfare_count++; //committee? if ($person->booking_committee_member == 'Y') $committee_count++; //fully paid? if ($amount_owing == 0) $fullypaid_count++; $person_count++; $state = strcmp($person->booking_country,'Australia') == 0 ? $person->booking_state : 'International'; //general stats for booked in people if ($person->booking_status == 1) { //for overall average age $dob_total += $person->booking_dob; //store data for average ages per gender and state if ($person->booking_gender == 'M') { $male_count++; $male_dob_total += $person->booking_dob; $state_statistics[$state]->male_avg += $person->booking_dob; $state_statistics[$state]->male_count++; } else { $female_count++; $female_dob_total += $person->booking_dob; $state_statistics[$state]->female_avg += $person->booking_dob; $state_statistics[$state]->female_count++; } if ($person->booking_baptised == 'Y') { $baptised_count++; $state_statistics[$state]->baptised_count++; } if ($person->booking_married == 'Y') $married_count++; } } //generate the table for state statistics foreach ($state_statistics as $key => $value) { //$state_rows[] = array($state, $state->total_count, $state->male_count, $state->female_count, 0); $male_average_age = _booking_avg_age($value->male_avg, $value->male_count, $event->booking_event_start); $female_average_age = _booking_avg_age($value->female_avg, $value->female_count, $event->booking_event_start); $state_average_age = _booking_avg_age($value->female_avg + $value->male_avg, $value->female_count + $value->male_count, $event->booking_event_start); $data = array($key, $value->total_count, $value->male_count, $value->female_count, $value->baptised_count, $male_average_age, $female_average_age, $state_average_age); //watchdog('booking', "
State statistics:\n@info", array('@info' => print_r( $data, true))); $state_rows[] = $data; } //output everything $output .= t("
There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, !hosts are hosts, " . "and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form. !travel people have filled in their travel form.
", array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count, '!travel' => $travelform_count, '!notcoming' => $notcoming_counter, '!hosts' => $hosts_counter)); $output .= t("There are !boys males and !girls females currently booked in. Of these, !baptised are baptised and !married are married.
", array('!boys' => $male_count, '!girls' => $female_count, '!baptised' => $baptised_count, '!married' => $married_count )); $output .= t("The combined average age at the start of the week will be !average.
The male average age will be !maleaverage.
The female average age will be !femaleaverage.
There are !welfare people with special financial consideration approved, and !committee people on the committee. " . "!fullypaid people have completed their payments.
", array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!committee' => $committee_count, )); $output .= t("Total amount paid: $!paid, minus $!refunds in refunds.", array('!paid' => $total_paid, '!refunds' => $total_refunds)); $output .= t("The following table presents payment entries from paypal and manual payments that have been made for !event.
", array('!event' => $event->booking_eventname)); $output .= theme('table', array('header' => $header, 'rows' => $rows)); $output .= t("Gross amount paid: $!paid. Total amount of fees paid: $!fees
", array('!paid' => $total_paid, '!fees' => $total_fees)); return $output; } /** * List everyone's flight info */ function booking_report_flight_details() { global $event; $form = array(); $prefix = t("View flight information for all attendees with status currently set to booked in.
"); $header = array( 'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'), 'booking_destination_country' => array('data' => t('Country'), 'field' => 'booking_destination_country'), 'booking_outflight_bookingnum' => array('data' => t('Reference'), 'field' => 'booking_outflight_bookingnum'), 'booking_outflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_outflight_flightnum'), 'booking_outflight_origin' => array('data' => t('Description'), 'field' => 'booking_outflight_origin'), 'booking_outflight_origin_ts' => array('data' => t('Departure Time'), 'field' => 'booking_outflight_origin_ts'), 'booking_outflight_connecting_flightnum' => array('data' => t('Connecting Flight'), 'field' => 'booking_outflight_connecting_flightnum'), 'booking_outflight_destination' => array('data' => t('Description'), 'field' => 'booking_outflight_destination'), 'booking_outflight_destination_ts' => array('data' => t('Time'), 'field' => 'booking_outflight_destination_ts'), 'booking_rtrnflight_bookingnum' => array('data' => t('Return Reference'), 'field' => 'booking_rtrnflight_bookingnum'), 'booking_rtrnflight_flightnum' => array('data' => t('Flight #'), 'field' => 'booking_rtrnflight_flightnum'), 'booking_rtrnflight_origin' => array('data' => t('Description'), 'field' => 'booking_rtrnflight_origin'), 'booking_rtrnflight_origin_ts' => array('data' => t('Time'), 'field' => 'booking_rtrnflight_origin_ts'), ); $query = db_select('booking_person', 'p'); $query->fields('p'); $db_and = db_and(); $db_and->condition('p.booking_eventid', $event->eid, '='); $db_and->condition('p.booking_status', 1, '='); $query->condition($db_and); $table_sort = $query->extend('TableSort')->orderbyHeader($header); $result = $table_sort->execute(); foreach($result as $data) { $name_link = l(t('!first !last', array('!first' => ucwords($data->booking_firstname), '!last' => ucwords($data->booking_lastname))), t('node/!id', array('!id' => $data->nid)) ); $rows[] = array ( 'data' => array( $name_link, $data->booking_destination_country, $data->booking_outflight_bookingnum, $data->booking_outflight_flightnum, $data->booking_outflight_origin, $data->booking_outflight_origin_ts == 0 ? '' : format_date($data->booking_outflight_origin_ts, 'custom', 'd/m/Y H:i'), $data->booking_outflight_connecting_flightnum, $data->booking_outflight_destination, $data->booking_outflight_destination_ts == 0 ? '' : format_date($data->booking_outflight_destination_ts, 'custom', 'd/m/Y H:i'), $data->booking_rtrnflight_bookingnum, $data->booking_rtrnflight_flightnum, $data->booking_rtrnflight_origin, $data->booking_rtrnflight_origin_ts == 0 ? '' : format_date($data->booking_rtrnflight_origin_ts, 'custom', 'd/m/Y H:i'), ), ); } $result = array ( 'first_para' => array ( '#type' => 'markup', '#markup' => $prefix, ), 'table' => array ( '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('id' => 'sort-table'), //'#sticky' => FALSE, ) ); return $result; } function booking_coming_page() { global $event; $output = ""; $table = ""; $attributes = array('style' => 'width:50%;/* margin-left:25%; margin-right:25%;*/'); $booking_limit = variable_get('booking_regn_limit','350'); $rows = array(); //work out whether to include the team colour in this page if (variable_get('booking_publish_readinggroups', 0) == 1) { $header = array('Name', 'Team Colour', 'State'); } else { $header = array('Name', 'State'); } //if configuration is set to show on lists even when no payment has been made, then include booking status of 0 (unpaid) or 1 (booked in) //also ensure any committee members always show if (variable_get('booking_auto_show_on_lists', 1) == 1) { $or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1)>condition('p.booking_committee_member', 'Y'); $result = db_select('booking_person', 'p') ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country')) ->condition($or) ->condition('p.booking_eventid', $event->eid, '=') ->orderBy('booking_country') ->orderBy('booking_state') ->orderBy('booking_lastname') ->orderBy('booking_firstname') ->execute(); } else { //payment must be made before someone will show up as booked in, but also include any committee member that might not have paid $or = db_or()->condition('p.booking_status', 1)->condition('p.booking_committee_member', 'Y'); $result = db_select('booking_person', 'p') ->fields('p', array('booking_firstname', 'booking_lastname', 'booking_state', 'booking_readinggroup', 'booking_country')) ->condition($or) ->condition('p.booking_eventid', $event->eid, '=') ->orderBy('booking_country') ->orderBy('booking_state') ->orderBy('booking_lastname') ->orderBy('booking_firstname') ->execute(); } foreach ($result as $person) { $state = $person->booking_country === variable_get('booking_default_country') ? $person->booking_state : $person->booking_country; //if we're allowed to publish reading groups, specify them in the array element if (variable_get('booking_publish_readinggroups', 0) == 1) { $rows[] = array( t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), t('!group',array('!group' => $person->booking_readinggroup)), t('!state', array('!state' => $state)), ); } //don't publish reading group information else { $rows[] = array( t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), t('!state', array('!state' => $state)), ); } } //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE))); //output the results //check there were some bookings if (count($rows) > 0) { if (count($rows) >= $booking_limit) { //there is a waiting list $output .= token_replace(variable_get('booking_whoscoming_pre_waitlist_text'), booking_define_tokens()); } else { //there's no waiting list $output .= token_replace(variable_get('booking_whoscoming_pre_text'), booking_define_tokens()); } //theme the table of registrations $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes)); } else { //no bookings $output .= token_replace(variable_get('booking_whoscoming_pre_noregistrations_text'), booking_define_tokens()); } //include any post-text $output .= token_replace(variable_get('booking_whoscoming_post_text'), booking_define_tokens()); return $output; } function booking_waitinglist_page() { global $event; $output = ""; $table = ""; $count = 1; //$header = array('Name', 'Occupation', 'State'); $header = array('Name', 'State', 'Position'); $booking_limit = variable_get('booking_regn_limit','350'); $rows = array(); /* $result = db_query('SELECT DISTINCT nid, booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country FROM ( SELECT p.nid, p.booking_firstname, p.booking_lastname, p.booking_state, p.booking_country, p.booking_readinggroup, pay.booking_payment_date FROM {booking_person} p, {booking_payment} pay WHERE booking_status = 2 and booking_eventid = :eid and p.nid = pay.booking_person_nid ) AS booking ORDER BY booking_payment_date', array(':eid' => $event->eid)); */ $result = db_query('SELECT DISTINCT nid, booking_firstname, booking_lastname, booking_state, booking_readinggroup, booking_country, booking_status FROM ( SELECT p.nid, p.booking_firstname, p.booking_lastname, p.booking_state, p.booking_country, p.booking_readinggroup, pay.booking_payment_date, p.booking_status FROM {booking_person} p, {booking_payment} pay WHERE p.booking_eventid = :eid and p.nid = pay.booking_person_nid and ( booking_status = 2 or booking_status = 4) ) AS booking ORDER BY booking_status, booking_payment_date', array(':eid' => $event->eid)); //watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE))); foreach ($result as $person) { $rows[] = array( t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))), //only for when we have readings groups //t('!group',array('!group' => $person->booking_readinggroup)), t('!state', array('!state' => $person->booking_country == 'Australia' ? $person->booking_state : $person->booking_country)), t($count++), ); } //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE))); //output the results //check there were people on the waiting list if (count($rows) > 0) { //include the pre-text $output .= token_replace(variable_get('booking_waitingpage_pre_text'), booking_define_tokens()); //theme the table of waiting list people $output .= theme('table', array('header' => $header, 'rows' => $rows)); } else { //no one on the waiting list $output .= token_replace(variable_get('booking_waitingpage_pre_nowaitlist_text'), booking_define_tokens()); } //include any post-text $output .= token_replace(variable_get('booking_waitingpage_post_text'), booking_define_tokens()); return $output; } function 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; } /** * Generate a CSV file as a report of all current registrations */ function booking_csv_report() { global $event; $name = 'bookings-' . format_date(time(), 'custom', 'Y-m-d-His'); $filename = file_directory_temp() . '/' . $name; $csv = ''; $delimiter = ','; $enclosure = '"'; $encloseAll = true; $nullToMysqlNull = true; $delimiter_esc = preg_quote($delimiter, '/'); $enclosure_esc = preg_quote($enclosure, '/'); //$readinggroup = "session" . variable_get('booking_readinggroup_id','7'); //calculate fields to ignore in the output csv file $builtin_fields_to_skip = array('booking_eventid'); $custom_fields_to_skip = explode(";", variable_get('booking_csv_exclude_fields', '')); $fields_to_skip = array_merge($builtin_fields_to_skip, $custom_fields_to_skip); //keep a list of any fields that we need to handle as dates $datetime_fields = array('booking_outflight_origin_ts', 'booking_outflight_destination_ts', 'booking_rtrnflight_origin_ts', 'booking_rtrnflight_destination_ts', 'booking_timestamp', 'booking_flight_datetime_inbound', 'booking_flight_datetime_outbound'); $number_only_fields = array('booking_postcode', 'booking_mobile', 'booking_phone'); //this isn't required since we already have the info directly as a field //so there is no need to rewrite the ID field with a user-friendly description //look up room location descriptions for presenting a friendly name rather than an ID //$room_query = db_query("SELECT * FROM {booking_room_locations} WHERE booking_roomlocation_active = 'Y'"); //$room_locations = $room_query->fetchAllAssoc('lid'); //look up the titles of the study groups and add to array for updating in the header $studygroup_descriptions = array(); $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); //update array for turning study group session IDs into the name for that group foreach ($studygroups as $studygroup) { //calculate the session references $sessionid = "session" . $studygroup->sid; $roleid = $sessionid . "_role"; $description = $studygroup->booking_studygroup_descrip; $studygroup_descriptions[$sessionid] = $description; $studygroup_descriptions[$roleid] = $description . " Role"; if ($studygroup->booking_is_readinggroup == 'Y') { $readinggroup_id = $sessionid; } } //pivot table based on http://anothermysqldba.blogspot.de/2013/06/pivot-tables-example-in-mysql.html $result = booking_load_query(NULL, TRUE); //watchdog('booking', "CSV raw data: @info", array('@info' => var_export($result, TRUE))); //write the header based on the first result $header_array = array(); foreach (reset($result) as $key => $value) { if (in_array($key, $fields_to_skip)) continue; /* //Replace headings for study group sessions and roles with the name of the study group rather than just sessionN and sessionN_role etc if (array_key_exists($key, $studygroup_descriptions)) { $header_array[] = $studygroup_descriptions[$key]; continue; } */ $header_array[] = $key; //add in a special column for a processed version of the date of birth if (strcmp($key,"booking_dob") == 0) $header_array[] = "booking_dob_processed"; //add in a calculated field for amount owing if (strcmp($key, "nid") == 0) { $header_array[] = "booking_amount_owing_gross"; $header_array[] = "booking_amount_owing_net"; } } $header = implode( $delimiter, $header_array ); //watchdog('booking', "CSV header: @info", array('@info' => var_export($header_array, TRUE))); //@fwrite($handle, $header . "\n"); $csv .= $header . "\n"; //each record foreach ($result as $record) { //watchdog('booking', "CSV raw data entry: @info", array('@info' => var_export($record, TRUE))); $output = array(); //each keypair in the record foreach ($record as $key => $value) { //fields to skip if (in_array($key, $fields_to_skip)) continue; //check for null if ($value === NULL && $nullToMysqlNull) { $output[] = 'NULL'; continue; } //capitalise street name and suburb name if ($key == 'booking_street' || $key == 'booking_suburb') $value = ucname($value); //handle dates if ($key == 'booking_dob') { $output[] = format_date($value, 'custom', 'd/m/Y'); $output[] = '"' . _booking_avg_age($value, 1, $event->booking_event_start) . '"'; continue; } if ($key == 'booking_passport_expiry_date') { $output[] = format_date($value, 'custom', 'd/m/Y'); continue; } //handle more exact dates if (in_array($key, $datetime_fields)) { $output[] = $value == 0 ? '0' : format_date($value, 'custom', 'd/m/Y H:i'); continue; } //handle numerical fields if (in_array($key, $number_only_fields)) { $output[] = $value . "\t"; continue; } //booking status if ($key == 'booking_status') { $output[] = _booking_status_generate($value); continue; } //studygroup ygroup session roles if (preg_match("/session\d+_role/", $key)) { $output[] = _booking_studygroup_role_lookup($value); continue; } /* //this is not required since node_load already has the room location description for each attendee //room location if ($key == 'booking_room_location_id') { $output[] = $room_locations[$value]->booking_roomlocation_descrip; continue; } */ //room bed type if ($key == 'booking_room_bedtype') { $output[] = _booking_room_bedtype_lookup($value); continue; } //reading group team colour if ($key == $readinggroup_id) { $output[] = _booking_readinggroup_colour_lookup($value); continue; } //add in the amount owing using the nid as the key if ($key == 'nid') { $output[] = $value; //add the amount owing firstly including paypal fees then excluding them //bit of a hack since this can never be excluded from the report $output[] = _booking_amount_owing($record, 0, TRUE); $output[] = _booking_amount_owing($record, 0, FALSE); continue; } // Enclose fields containing $delimiter, $enclosure or whitespace if ( $encloseAll || preg_match( "/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $value ) ) { $output[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $value) . $enclosure; } else { $output[] = $field; } } $row = implode($delimiter, $output) . "\n"; //@fwrite($handle, $row); $csv .= $row; //$index++; } //@fclose($handle); //see http://stackoverflow.com/questions/4348802/how-can-i-output-a-utf-8-csv-in-php-that-excel-will-read-properly // but none of these options seem to work drupal_add_http_header("Content-type", "application/octet-stream; charset=utf-8"); //drupal_add_http_header("Content-type", "application/octet-stream; charset=UTF-16LE"); //drupal_add_http_header("Content-Type: application/vnd.ms-excel"); drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv"); // @readfile($filename); //print chr(255) . chr(254); //print 'sep=,' . "\n"; print $csv; //print mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8'); //@unlink($filename); exit(0); }