$selectAllStyle = 'float:right;display:inline-block;color:#777;margin:5px 0;font-weight:normal;font-size:12px;';
$selectAllStyle .= LR_SHOW_QUICK_ADD_ALL_PROJECT_FIELDS ? '' : 'visibility:hidden;';
// Validate checked_fields, if is not empty
$checked_fields = explode(",", $_POST['checked_fields']);
foreach ($checked_fields as $key => $this_field) {
    $this_field = LongitudinalReports::getFieldFromEventField($this_field);
    // remvoe square brackets and event ref
    if (!isset($Proj->metadata[$this_field])) {
        unset($checked_fields[$key]);
    }
}
// Set fields as keys in array
$checked_fields = array_flip(array_unique($checked_fields));
// Loop through all fields and build HTML table (exclude Descriptive fields)
$t = "";
$rc_field_dropdown_options = LongitudinalReports::getFieldDropdownOptions();
//Form::getFieldDropdownOptions();
$select = RCView::a(array('href' => 'javascript:;', 'style' => 'font-size:11px;margin:0 3px;text-decoration:underline;font-weight:normal;', 'onclick' => "reportQuickAddForm('all',true);"), $lang['data_export_tool_52']);
$deselect = RCView::a(array('href' => 'javascript:;', 'style' => 'font-size:11px;margin:0 3px;text-decoration:underline;font-weight:normal;', 'onclick' => "reportQuickAddForm('all',false);"), $lang['data_export_tool_53']);
$t .= RCView::tr(array(), RCView::td(array('class' => 'header', 'valign' => 'bottom', 'style' => 'color:#800000;font-size:14px;'), RCView::div(array('style' => 'font-weight:bold;font-style:italic;'), "Events / Fields") . RCView::div(array('style' => $selectAllStyle), " ({$select}/{$deselect})")));
//$rc_field_dropdown_options = $indexCompleted;
$accordion = "";
foreach ($rc_field_dropdown_options as $eventFieldGroup => $eventFields) {
    if ($eventFieldGroup !== '') {
        // Only show Select All / Deselect All if count of fields in group is less than threshold
        $selectAllInGroupStyle = 'color:#777;margin:5px 0;font-weight:normal;font-size:11px;';
        if (count($eventFields) < 2 || count($eventFields) > LR_SHOW_QUICK_ADD_ALL_GROUP_THRESHOLD) {
            $selectAllInGroupStyle .= 'visibility:hidden;';
        }
        $eventFieldRef = preg_replace("/[^a-z0-9_]/", "", strtolower($eventFieldGroup));
        $select = RCView::a(array('href' => 'javascript:;', 'style' => 'display:inline-block;text-decoration:underline;font-weight:normal;padding:0 3px;', 'onclick' => "reportQuickAddForm('{$eventFieldRef}',true);"), $lang['data_export_tool_52']);