Index: webform_report.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform_report/Attic/webform_report.inc,v retrieving revision 1.1.2.27.2.8 diff -u -r1.1.2.27.2.8 webform_report.inc --- webform_report.inc 24 Sep 2010 15:18:07 -0000 1.1.2.27.2.8 +++ webform_report.inc 24 Sep 2010 20:00:32 -0000 @@ -76,6 +76,7 @@ 'type' => $components[$cid]['type'], 'format' => $node->columns[$i]['format'], 'cid' => $node->columns[$i]['cid'], + 'hidden' => $node->columns[$i]['hidden'], ); } } @@ -214,12 +215,14 @@ // set column headers foreach ($columns as $index => $col) { - // set report header - also save type for later - $headers[] = array( - 'data' => $col['name'], - 'field' => $col['cid'], - 'type' => $col['type'] - ); + if ($col['hidden'] != TRUE) { + // set report header - also save type for later + $headers[] = array( + 'data' => $col['name'], + 'field' => $col['cid'], + 'type' => $col['type'] + ); + } // fields by cid for quick lookup $fields[$col['cid']] = $col['name']; } @@ -290,7 +293,8 @@ // see if any rows are available if (count($rows) > 0) { // sort - _webform_report_sort($headers, $rows, $sorton); + _webform_report_sort($headers, $rows, $sorton, $columns); + // output in requested format if ($formatcsv) { // format as csv @@ -487,7 +491,7 @@ $raw = $data[$col['cid']]; // add column to output row - $row[] = _webform_report_format_data($raw, $col['cid'], $col['type'], $col['format']); + $row[] = _webform_report_format_data($raw, $col); } else { @@ -504,21 +508,17 @@ * * @param raw * array of raw submission data - * @param cid - * webform componenet id of data - * @param type - * webform type of data - * @param format - * desired data output format + * @param column + * the report column * @return * array of formatted table data */ -function _webform_report_format_data($raw, $cid, $type, $format = '') { +function _webform_report_format_data($raw, $column) { $out = ''; // handle file type - if ($type == 'file') { + if ($column['type'] == 'file') { $tmp = unserialize($raw[0]); $link = ' '; if (!empty($tmp['filename'])) { @@ -526,14 +526,14 @@ $tmp['filename'] . ' (' . (int) ($tmp['filesize'] / 1024) .' KB)' . ''; } - $out = array('data' => $link, 'field' => $cid, 'sort' => $tmp['filepath']); + $out = array('data' => $link, 'field' => $column['cid'], 'sort' => $tmp['filepath']); } // handle dates - else if ($type == 'date') { + else if ($column['type'] == 'date') { $ts = 0; // if report date - if ($cid > 0) { + if ($column['cid'] > 0) { // if date was selected if ($raw[0] && $raw[1]) { // make timestamp, dates are stored month, day, year @@ -546,19 +546,20 @@ } // if valid timestamp if ($ts > 0) { + $format = $column['format']; // set default format if none given if (empty($format)) { $format = 'Y-m-d'; } // format the date - $out = array('data' => date($format, $ts), 'field' => $cid, 'sort' => $ts); + $out = array('data' => date($format, $ts), 'field' => $column['cid'], 'sort' => $ts); } } // handle times - else if ($type == 'time') { + else if ($column['type'] == 'time') { $ts = 0; - if ($cid > 0) { + if ($column['cid'] > 0) { // if time was selected if ($raw[0] && $raw[1]) { // make timestamp, times are stored hh, mm, ampm @@ -571,12 +572,13 @@ } // if valid timestamp if ($ts > 0) { + $format = $column['format']; // default format if none given if (empty($format)) { $format = 'H:i'; } // format the time - $out = array('data' => date($format, $ts), 'field' => $cid, 'sort' => $ts); + $out = array('data' => date($format, $ts), 'field' => $column['cid'], 'sort' => $ts); } } @@ -590,7 +592,7 @@ if (function_exists('_accents_remove_accents')) { $sort = _accents_remove_accents($sort); } - $out = array('data' => $tmp, 'field' => $cid, 'sort' => $sort); + $out = array('data' => $tmp, 'field' => $column['cid'], 'sort' => $sort); // add links if (valid_email_address($out['data'])) { @@ -602,6 +604,11 @@ } } } + + // pass hidden attribute to output + if ($column['hidden'] == TRUE) { + $out['hidden'] = TRUE; + } // return formatted data return $out; @@ -620,7 +627,7 @@ * @param sorton * list of default sort parameters */ -function _webform_report_sort(&$headers, &$rows, $sorton) { +function _webform_report_sort(&$headers, &$rows, $sorton, $columns) { // will be empty if user has not clicked on a header $init = !isset($_GET['order']); @@ -632,42 +639,46 @@ // if inital display (no column header has been clicked) if ($init) { - // and no sort parameters - if (count($sorton) == 0) { - // we must sort on first column, that is what theme_table defaults to - $headers[0]['sort'] = 'asc'; - $code = 'return ' . _webform_report_sort_column(0, FALSE, $headers[0]['type']) . ';'; - } - // otherwise setup initial sort, if specified - else { + + // if sort parameters given + if (count($sorton) > 0) { + + // init variables $a = array(); - + $cid = 0; + $ord = ''; + // loop through sorts - foreach ($sorton as $index => $sort) { - // find the header - foreach ($headers as $hindex => $header) { - - if ($header['field'] == $sort['cid']) { - - // mark the first sort header - if (count($a) == 0) { + foreach ($sorton as $sort) { + // find column to be sorted + foreach($columns as $index => $col) { + if ($sort['cid'] == $col['cid']) { + // save first sort column + if ($cid == 0) { + $cid = $sort['cid']; if ($sort['order'] == SORT_ASC) { - $headers[$hindex]['sort'] = 'asc'; + $ord = 'asc'; } else { - $headers[$hindex]['sort'] = 'desc'; + $ord = 'desc'; } - } // end - if (count($a) == 0)... - + } // add the sort function - $a[] = _webform_report_sort_column($hindex, ($sort['order'] == SORT_DESC), $sort['type']); + $a[] = _webform_report_sort_column($index, ($sort['order'] == SORT_DESC), $sort['type']); break; - - } // end - if ($header['field'])... - } // end - foreach ($headers as... + } + } } // end - foreach ($sorton... - // format the complete sort function + // flag the header with the first sort column + foreach ($headers as $index => $header) { + // mark the first sort header + if ($header['field'] == $cid) { + $headers[$index]['sort'] = $ord; + break; + } // end - if ($header['field'])... + } // end - foreach ($headers as... + if (count($a) == 0) { // probably no columns $code = 'return 0;'; @@ -696,10 +707,10 @@ } // user has clicked on a column header - must sort that column else { - foreach ($headers as $hindex => $header) { + foreach ($headers as $index => $header) { if ($header['field'] == $ts['sql']) { - $headers[$hindex]['sort'] = $ts_order; - $code = 'return ' . _webform_report_sort_column($hindex, ($ts_order == 'desc'), $header['type']) . ';'; + $headers[$index]['sort'] = $ts_order; + $code = 'return ' . _webform_report_sort_column($index, ($ts_order == 'desc'), $header['type']) . ';'; break; } } @@ -797,14 +808,24 @@ // Grab the 'page' query parameter. // Taken from pager_query() in pager.inc $page = isset($_GET['page']) ? $_GET['page'] : ''; - // Convert comma-separated $page to an array, used by other functions. - // Taken from pager_query() in pager.inc $pager_page_array = explode(',', $page); - - // format the table with the current page if ($page == '') $page = 0; - $output = theme_table($headers, $pages[$page], array('class' => 'webform_report')); + + // filter out hidden columns + $out = array(); + foreach ($pages[$page] as $row) { + $outrow = array(); + foreach ($row as $cell) { + if ($cell['hidden'] != TRUE) { + $outrow[] = $cell; + } + } + $out[] = $outrow; + } + + // format the table with the current page + $output = theme_table($headers, $out, array('class' => 'webform_report')); // Put some magic in the two global variables // Based on code in pager_query() in pager.inc @@ -863,7 +884,10 @@ foreach($rows as $row) { $tmp = array(); foreach($row as $cell) { - $tmp[] = _webform_report_format_csv_column(strip_tags($cell['data'])); + // output cell if not hidden + if (!array_key_exists('hidden', $cell)) { + $tmp[] = _webform_report_format_csv_column(strip_tags($cell['data'])); + } } $output .= implode(',', $tmp) . "\n"; } Index: webform_report_criteria.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform_report/Attic/webform_report_criteria.inc,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 webform_report_criteria.inc --- webform_report_criteria.inc 18 Jun 2010 20:33:06 -0000 1.1.2.2 +++ webform_report_criteria.inc 24 Sep 2010 20:09:13 -0000 @@ -76,8 +76,9 @@ '#type' => 'markup', '#value' => $columns[$i]['name'] ); + $form['columns'][$i]['type'] = array( - '#type' => 'markup', + '#type' => 'markup', '#value' => $columns[$i]['type'] ); @@ -96,6 +97,11 @@ ); } + $form['columns'][$i]['hidden'] = array( + '#type' => 'checkbox', + '#default_value' => $columns[$i]['hidden'] + ); + webform_report_criteria_form_list_buttons($form, $img_path, 'columns', $cid, $i, $cc); } @@ -221,9 +227,16 @@ webform_report_criteria_form_list_buttons($form, $img_path, 'sorton', $cid, $i, $cc); } + // only allow sorts on report columns + $options = array(); + $options[0] = t('Select a field'); + foreach ($columns as $index => $col) { + $options[$col['cid']] = $col['name']; + } + $form['sorton']['addcomp'] = array( '#type' => 'select', - '#options' => $comp_options, + '#options' => $options, '#required' => FALSE ); @@ -376,6 +389,7 @@ t('Name'), t('Type'), t('Format'), + t('Hidden'), array('data' => t('Operations'), 'colspan' => '5') ); @@ -387,6 +401,7 @@ drupal_render($form['columns'][$index]['name']), drupal_render($form['columns'][$index]['type']), drupal_render($form['columns'][$index]['format']), + drupal_render($form['columns'][$index]['hidden']), drupal_render($form['columns'][$index]['delete']), drupal_render($form['columns'][$index]['top']), drupal_render($form['columns'][$index]['up']), @@ -552,7 +567,8 @@ if ($list == 'columns') { $node->columns[] = array( 'cid' => $cid, - 'format' => '' + 'format' => '', + 'hidden' => FALSE ); $upd = TRUE; } @@ -576,6 +592,16 @@ else if ($op == 'delete' && $index >= 0) { if ($list == 'columns') { + // remove any sort columns that are based on deleted column + $list = array(); + foreach($node->sorton as $si => $sort) { + if ($sort['cid'] == $node->columns[$index]['cid']) { + $list[$si] = $si; + } + } + if (count($list) > 0) { + $node->sorton = array_values(array_diff_key($node->sorton, $list)); + } $node->columns = array_values(array_diff_key($node->columns, array($index => $index))); $upd = TRUE; } @@ -677,10 +703,11 @@ // update lists foreach (element_children($form_state['values']['columns']) as $index) { if (is_numeric($index)) { - if (isset($form_state['values']['columns'][$index]['format'])) { - if (array_key_exists($index, $node->columns)) { + if (array_key_exists($index, $node->columns)) { + if (isset($form_state['values']['columns'][$index]['format'])) { $node->columns[$index]['format'] = $form_state['values']['columns'][$index]['format']; } + $node->columns[$index]['hidden'] = $form_state['values']['columns'][$index]['hidden']; } } }