[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/webform/includes/ -> webform.report.inc (source)

   1  <?php
   2  // $Id: webform.report.inc,v 1.16.2.10 2010/09/29 18:38:19 quicksketch Exp $
   3  
   4  /**
   5   * @file
   6   * This file includes helper functions for creating reports for webform.module
   7   *
   8   * @author Nathan Haug <nate@lullabot.com>
   9   */
  10  
  11  // All functions within this file need the webform.submissions.inc.
  12  module_load_include('inc', 'webform', 'includes/webform.submissions');
  13  
  14  /**
  15   * Retrieve lists of submissions for a given webform.
  16   */
  17  function webform_results_submissions($node, $user_filter, $pager_count) {
  18    global $user;
  19  
  20    if (isset($_GET['results']) && is_numeric($_GET['results'])) {
  21      $pager_count = $_GET['results'];
  22    }
  23  
  24    $header = theme('webform_results_submissions_header', $node);
  25    if ($user_filter) {
  26      if ($user->uid) {
  27        drupal_set_title(t('Submissions for %user', array('%user' => $user->name)));
  28      }
  29      else {
  30        drupal_set_title(t('Your submissions'));
  31        webform_disable_page_cache();
  32      }
  33      webform_set_breadcrumb($node);
  34      $submissions = webform_get_submissions(array('nid' => $node->nid, 'uid' => $user->uid), $header, $pager_count);
  35      $count = webform_get_submission_count($node->nid, $user->uid);
  36    }
  37    else {
  38      $submissions = webform_get_submissions($node->nid, $header, $pager_count);
  39      $count = webform_get_submission_count($node->nid);
  40    }
  41  
  42    $operation_column = end($header);
  43    $operation_total = $operation_column['colspan'];
  44  
  45    $rows = array();
  46    foreach ($submissions as $sid => $submission) {
  47      $row = array(
  48        $submission->is_draft ? t('@sid (draft)', array('@sid' => $sid)) : $sid,
  49        format_date($submission->submitted, 'small'),
  50      );
  51      if (webform_results_access($node, $user)) {
  52        $row[] = theme('username', $submission);
  53        $row[] = $submission->remote_addr;
  54      }
  55      $row[] = l(t('View'), "node/$node->nid/submission/$sid");
  56      $operation_count = 1;
  57      if (module_exists('print_pdf') && user_access('access PDF version')) {
  58        $row[] = l(t('PDF'), "printpdf/$node->nid/submission/$sid", array('query' => drupal_get_destination()));
  59        $operation_count++;
  60      }
  61      if (module_exists('print') && user_access('access print')) {
  62        $row[] = l(t('Print'), "print/$node->nid/submission/$sid");
  63        $operation_count++;
  64      }
  65      if (webform_submission_access($node, $submission, 'edit', $user)) {
  66        $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit", array('query' => drupal_get_destination()));
  67        $operation_count++;
  68      }
  69      if (webform_submission_access($node, $submission, 'delete', $user)) {
  70        $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete", array('query' => drupal_get_destination()));
  71        $operation_count++;
  72      }
  73      if ($operation_count < $operation_total) {
  74        $row[count($row) - 1] = array('data' => $row[count($row) - 1], 'colspan' => $operation_total - $operation_count + 1);
  75      }
  76      $rows[] = $row;
  77    }
  78  
  79    $element['#theme'] = 'webform_results_submissions';
  80    $element['#node'] = $node;
  81    $element['#submissions'] = $submissions;
  82    $element['#total_count'] = $count;
  83    $element['#pager_count'] = $pager_count;
  84  
  85    $element['table']['#theme'] = 'table';
  86    $element['table']['#header'] = $header;
  87    $element['table']['#rows'] = $rows;
  88    $element['table']['#operation_total'] = $operation_total;
  89  
  90    return drupal_render($element);
  91  }
  92  
  93  /**
  94   * Theme the list of links for selecting the number of results per page.
  95   *
  96   * @param $total_count
  97   *   The total number of results available.
  98   * @param $pager_count
  99   *   The current number of results displayed per page.
 100   */
 101  function theme_webform_results_per_page($total_count, $pager_count) {
 102    $output = '';
 103  
 104    // Create a list of results-per-page options.
 105    $counts = array(
 106      '20' => '20',
 107      '50' => '50',
 108      '100' => '100',
 109      '200' => '200',
 110      '500' => '500',
 111      '1000' => '1000',
 112      '0' => t('All'),
 113    );
 114  
 115    $count_links = array();
 116  
 117    foreach ($counts as $number => $text) {
 118      if ($number < $total_count) {
 119        $count_links[] = l($text, $_GET['q'], array('query' => 'results=' . $number, 'attributes' => array('class' => $pager_count == $number ? 'selected' : '')));
 120      }
 121    }
 122  
 123    $output .= '<div class="webform-results-per-page">';
 124    if (count($count_links) > 1) {
 125      $output .= t('Show !count results per page.', array('!count' => implode(' | ', $count_links)));
 126    }
 127    else {
 128      $output .= t('Showing all results.');
 129    }
 130    if ($total_count > 1) {
 131      $output .= ' ' . t('@total results total.', array('@total' => $total_count));
 132    }
 133    $output .= '</div>';
 134  
 135    return $output;
 136  }
 137  
 138  /**
 139   * Theme the header of the submissions table.
 140   *
 141   * This is done in it's own function so that webform can retrieve the header and
 142   * use it for sorting the results.
 143   */
 144  function theme_webform_results_submissions_header($node) {
 145    $columns = array(
 146      array('data' => t('#'), 'field' => 'sid', 'sort' => 'asc'),
 147      array('data' => t('Submitted'), 'field' => 'submitted'),
 148    );
 149    if (webform_results_access($node)) {
 150      $columns[] = array('data' => t('User'), 'field' => 'name');
 151      $columns[] = array('data' => t('IP Address'), 'field' => 'remote_addr');
 152    }
 153    $columns[] = array('data' => t('Operations'), 'colspan' => module_exists('print') ? 5 : 3);
 154  
 155    return $columns;
 156  }
 157  
 158  /**
 159   * Preprocess function for webform-results-submissions.tpl.php
 160   */
 161  function template_preprocess_webform_results_submissions(&$vars) {
 162    $vars['node'] = $vars['element']['#node'];
 163    $vars['submissions'] = $vars['element']['#submissions'];
 164    $vars['table'] = $vars['element']['table'];
 165    $vars['total_count'] = $vars['element']['#total_count'];
 166    $vars['pager_count'] = $vars['element']['#pager_count'];
 167    $vars['is_submissions'] = (arg(2) == 'submissions')? 1 : 0;
 168  
 169    unset($vars['element']);
 170  }
 171  
 172  /**
 173   * Create a table containing all submitted values for a webform node.
 174   */
 175  function webform_results_table($node, $pager_count = 0) {
 176    if (isset($_GET['results']) && is_numeric($_GET['results'])) {
 177      $pager_count = $_GET['results'];
 178    }
 179  
 180    // Get all the submissions for the node.
 181    $header = theme('webform_results_table_header', $node);
 182    $submissions = webform_get_submissions($node->nid, $header, $pager_count);
 183    $total_count = webform_get_submission_count($node->nid);
 184  
 185    $output = theme('webform_results_table', $node, $node->webform['components'], $submissions, $total_count, $pager_count);
 186    if ($pager_count) {
 187      $output .= theme('pager', NULL, $pager_count, 0);
 188    }
 189    return $output;
 190  }
 191  
 192  function theme_webform_results_table_header($node) {
 193    return array(
 194      array('data' => t('#'), 'field' => 'sid', 'sort' => 'asc'),
 195      array('data' => t('Submitted'), 'field' => 'submitted'),
 196      array('data' => t('User'), 'field' => 'name'),
 197      array('data' => t('IP Address'), 'field' => 'remote_addr'),
 198    );
 199  }
 200  
 201  /**
 202   * Theme the results table displaying all the submissions for a particular node.
 203   *
 204   * @param $node
 205   *   The node whose results are being displayed.
 206   * @param $components
 207   *   An associative array of the components for this webform.
 208   * @param $submissions
 209   *   An array of all submissions for this webform.
 210   * @param $total_count
 211   *   The total number of submissions to this webform.
 212   * @param $pager_count
 213   *   The number of results to be shown per page.
 214   */
 215  function theme_webform_results_table($node, $components, $submissions, $total_count, $pager_count) {
 216    drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE);
 217  
 218    $header = array();
 219    $rows = array();
 220    $cell = array();
 221  
 222    // This header has to be generated seperately so we can add the SQL necessary.
 223    // to sort the results.
 224    $header = theme('webform_results_table_header', $node);
 225  
 226    // Generate a row for each submission.
 227    foreach ($submissions as $sid => $submission) {
 228      $cell[] = l($sid, 'node/' . $node->nid . '/submission/' . $sid);
 229      $cell[] = format_date($submission->submitted, 'small');
 230      $cell[] = theme('username', $submission);
 231      $cell[] = $submission->remote_addr;
 232      $component_headers = array();
 233  
 234      // Generate a cell for each component.
 235      foreach ($node->webform['components'] as $component) {
 236        $data = isset($submission->data[$component['cid']]['value']) ? $submission->data[$component['cid']]['value'] : NULL;
 237        $submission_output = webform_component_invoke($component['type'], 'table', $component, $data);
 238        if ($submission_output !== NULL) {
 239          $component_headers[] = $component['name'];
 240          $cell[] = $submission_output;
 241        }
 242      }
 243  
 244      $rows[] = $cell;
 245      unset($cell);
 246    }
 247    if (!empty($component_headers)) {
 248      $header = array_merge($header, $component_headers);
 249    }
 250  
 251    if (count($rows) == 0) {
 252      $rows[] = array(array('data' => t('There are no submissions for this form. <a href="!url">View this form</a>.', array('!url' => url('node/' . $node->nid))), 'colspan' => 4));
 253    }
 254  
 255  
 256    $output = '';
 257    $output .= theme('webform_results_per_page', $total_count, $pager_count);
 258    $output .= theme('table', $header, $rows);
 259    return $output;
 260  }
 261  
 262  /**
 263   * Delete all submissions for a node.
 264   *
 265   * @param $nid
 266   *   The node id whose submissions will be deleted.
 267   */
 268  function webform_results_clear($nid) {
 269    $node = node_load($nid);
 270    $submissions = webform_get_submissions($nid);
 271    foreach ($submissions as $submission) {
 272      webform_submission_delete($node, $submission);
 273    }
 274  }
 275  
 276  /**
 277   * Confirmation form to delete all submissions for a node.
 278   *
 279   * @param $nid
 280   *   ID of node for which to clear submissions.
 281   */
 282  function webform_results_clear_form($form_state, $node) {
 283    drupal_set_title(t('Clear Form Submissions'));
 284  
 285    $form = array();
 286    $form['nid'] = array('#type' => 'value', '#value' => $node->nid);
 287    $question = t('Are you sure you want to delete all submissions for this form?');
 288  
 289    return confirm_form($form, $question, 'node/' . $node->nid . '/webform-results', NULL, t('Clear'), t('Cancel'));
 290  }
 291  
 292  function webform_results_clear_form_submit($form, &$form_state) {
 293    webform_results_clear($form_state['values']['nid']);
 294    $node = node_load($form_state['values']['nid']);
 295    $title = $node->title;
 296  
 297    $message = t('Webform %title entries cleared.', array('%title' => $title));
 298    drupal_set_message($message);
 299    watchdog('webform', $message);
 300    $form_state['redirect'] = 'node/' . $form_state['values']['nid'] . '/webform-results';
 301  }
 302  
 303  /**
 304   * Form to configure the download of CSV files.
 305   */
 306  function webform_results_download_form(&$form_state, $node) {
 307    module_load_include('inc', 'webform', 'includes/webform.export');
 308    module_load_include('inc', 'webform', 'includes/webform.components');
 309  
 310    $form = array();
 311  
 312    $form['node'] = array(
 313      '#type' => 'value',
 314      '#value' => $node,
 315    );
 316  
 317    $form['format'] = array(
 318      '#type' => 'radios',
 319      '#title' => t('Export format'),
 320      '#options' => webform_export_list(),
 321      '#default_value' => variable_get('webform_export_format', 'delimited'),
 322    );
 323  
 324    $form['delimiter'] = array(
 325      '#type' => 'select',
 326      '#title' => t('Delimited text format'),
 327      '#description' => t('This is the delimiter used in the CSV/TSV file when downloading Webform results. Using tabs in the export is the most reliable method for preserving non-latin characters. You may want to change this to another character depending on the program with which you anticipate importing results.'),
 328      '#default_value' => variable_get('webform_csv_delimiter', '\t'),
 329      '#options' => array(
 330        ','  => t('Comma (,)'),
 331        '\t' => t('Tab (\t)'),
 332        ';'  => t('Semicolon (;)'),
 333        ':'  => t('Colon (:)'),
 334        '|'  => t('Pipe (|)'),
 335        '.'  => t('Period (.)'),
 336        ' '  => t('Space ( )'),
 337      ),
 338    );
 339  
 340    $form['select_options'] = array(
 341      '#type' => 'fieldset',
 342      '#title' => t('Select list options'),
 343      '#collapsible' => TRUE,
 344      '#collapsed' => TRUE,
 345    );
 346  
 347    $form['select_options']['select_keys'] = array(
 348      '#type' => 'radios',
 349      '#title' => t('Select keys'),
 350      '#options' => array(
 351        0 => t('Full, human-readable options (values)'),
 352        1 => t('Short, raw options (keys)'),
 353      ),
 354      '#default_value' => 0,
 355      '#description' => t('Choose which part of options should be displayed from key|value pairs.'),
 356    );
 357  
 358    $form['select_options']['select_format'] = array(
 359      '#type' => 'radios',
 360      '#title' => t('Select list format'),
 361      '#options' => array(
 362        'separate' => t('Separate'),
 363        'compact' => t('Compact'),
 364      ),
 365      '#default_value' => 'separate',
 366      '#attributes' => array('class' => 'webform-select-list-format'),
 367      '#theme' => 'webform_results_download_select_format',
 368    );
 369  
 370    $csv_components = array(
 371      'info' => t('Submission information'),
 372      'serial' => '-' . t('Submission Number'),
 373      'sid' => '-' . t('Submission ID'),
 374      'time' => '-' . t('Time'),
 375      'draft' => '-' . t('Draft'),
 376      'ip_address' => '-' . t('IP Address'),
 377      'uid' => '-' . t('User ID'),
 378      'username' => '-' . t('Username'),
 379    );
 380    $csv_components += webform_component_list($node, 'csv', TRUE);
 381  
 382    $form['components'] = array(
 383      '#type' => 'select',
 384      '#title' => t('Included export components'),
 385      '#options' => $csv_components,
 386      '#default_value' => array_keys($csv_components),
 387      '#multiple' => TRUE,
 388      '#size' => 10,
 389      '#description' => t('The selected components will be included in the export.'),
 390      '#process' => array('webform_component_select'),
 391    );
 392  
 393    $form['submit'] = array(
 394      '#type' => 'submit',
 395      '#value' => t('Download'),
 396    );
 397  
 398    return $form;
 399  }
 400  
 401  function webform_results_download_form_submit(&$form, &$form_state) {
 402    $options = array(
 403      'delimiter' => $form_state['values']['delimiter'],
 404      'components' => array_keys(array_filter($form_state['values']['components'])),
 405      'select_keys' => $form_state['values']['select_keys'],
 406      'select_format' => $form_state['values']['select_format'],
 407    );
 408    webform_results_download($form_state['values']['node'], $form_state['values']['format'], $options);
 409  }
 410  
 411  /**
 412   * Theme the output of the export form.
 413   */
 414  function theme_webform_results_download_form($form) {
 415    drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE);
 416  
 417    return drupal_render($form);
 418  }
 419  
 420  /**
 421   * Theme the output of the select list format radio buttons.
 422   */
 423  function theme_webform_results_download_select_format($element) {
 424    drupal_add_css(drupal_get_path('module', 'webform') . '/css/webform-admin.css', 'theme', 'all', FALSE);
 425  
 426    $output = '';
 427  
 428    // Build an example table for the separate option.
 429    $header = array(t('Option A'), t('Option B'), t('Option C'));
 430    $rows = array(
 431      array('X', '', ''),
 432      array('X', '', 'X'),
 433      array('', 'X', 'X'),
 434    );
 435  
 436    $element['separate']['#attributes']['class'] = '';
 437    $element['separate']['#description'] = theme('table', $header, $rows);
 438    $element['separate']['#description'] .= t('Separate options are more suitable for building reports, graphs, and statistics in a spreadsheet application.');
 439    $output .= drupal_render($element['separate']);
 440  
 441    // Build an example table for the compact option.
 442    $header = array(t('My select list'));
 443    $rows = array(
 444      array('Option A'),
 445      array('Option A,Option C'),
 446      array('Option B,Option C'),
 447    );
 448  
 449    $element['separate']['#attributes']['class'] = '';
 450    $element['compact']['#description'] = theme('table', $header, $rows);
 451    $element['compact']['#description'] .= t('Compact options are more suitable for importing data into other systems.');
 452    $output .= drupal_render($element['compact']);
 453  
 454    return $output;
 455  }
 456  
 457  /**
 458   * Generate a Excel-readable CSV file containing all submissions for a Webform.
 459   *
 460   * The CSV requires that the data be presented in a flat file.  In order
 461   * to maximize usability to the Excel community and minimize subsequent
 462   * stats or spreadsheet programming this program extracts data from the
 463   * various records for a given session and presents them as a single file
 464   * where each row represents a single record.
 465   * The structure of the file is:
 466   *   Heading Line 1: Gives group overviews padded by empty cells to the
 467   *                   next group.  A group may be a question and corresponds
 468   *                   to a component in the webform philosophy. Each group
 469   *                   overview will have a fixed number of columns beneath it.
 470   *   Heading line 2: gives column headings
 471   *   Data line 1 .....
 472   *   Data line 2 .....
 473   *
 474   * An example of this format is given below.  Note the columns have had spaces
 475   * added so the columns line up.  This is not the case with actual file where
 476   * a column may be null.  Note also, that multiple choice questions as produced
 477   * by checkboxes or radio buttons have been presented as "yes" or "no" and the
 478   * actual choice text is retained only in the header line 2.
 479   * Data from text boxes and input fields are written out in the body of the table.
 480   *
 481   *   Submission Details,    ,   ,      ,Question 1,        ,        ,..,        ,Question 2,        ,        ,..,        ,Question n
 482   *   timestamp         ,time,SID,userid,Choice 1  ,Choice 2,Choice 3,..,Choice n,Choice 1  ,Choice 2,Choice 3,..,Choice n,Comment
 483   *   21 Feb 2005       ,1835,23 ,34    ,X         ,        ,        ,..,       ,X          ,X       ,X       ,..,X       ,My comment
 484   *   23 Feb 2005       ,1125,24 ,89    ,X         ,X       ,        ,..,       ,X          ,X       ,X       ,..,X       ,Hello
 485   *   .................................................................................................................................
 486   *   27 Feb 2005       ,1035,56 ,212   ,X         ,        ,        ,..,       ,X          ,X       ,X       ,..,X       ,How is this?
 487   *
 488   */
 489  function webform_results_download($node, $format = 'delimiter', $options = array()) {
 490    module_load_include('inc', 'webform', 'includes/webform.export');
 491    module_load_include('inc', 'webform', 'includes/webform.components');
 492  
 493    $submission_information = array(
 494      'serial' => t('Serial'),
 495      'sid' => t('SID'),
 496      'time' => t('Time'),
 497      'draft' => t('Draft'),
 498      'ip_address' => t('IP Address'),
 499      'uid' => t('UID'),
 500      'username' => t('Username'),
 501    );
 502  
 503    if (empty($options)) {
 504      $options = array(
 505        'delimiter' => variable_get('webform_csv_delimiter', '\t'),
 506        'components' => array_keys($submission_information) + array_keys(webform_component_list($node, 'csv', TRUE)),
 507        'select_display' => 'value',
 508        'select_format' => 'separate',
 509      );
 510    }
 511    else {
 512      foreach ($submission_information as $key => $label) {
 513        if (!in_array($key, $options['components'])) {
 514          unset($submission_information[$key]);
 515        }
 516      }
 517    }
 518  
 519    // Open a new Webform exporter object.
 520    $exporter = webform_export_create_handler($format, $options);
 521  
 522    $file_name = tempnam(variable_get('file_directory_temp', file_directory_temp()), 'webform');
 523    $handle = @fopen($file_name, 'w'); // The @ suppresses errors.
 524    $exporter->bof($handle);
 525  
 526    // Fill in the header for the submission information (if any).
 527    $header[2] = $header[1] = $header[0] = count($submission_information) ? array_fill(0, count($submission_information), '') : array();
 528    if (count($submission_information)) {
 529      $header[0][0] = $node->title;
 530      $header[1][0] = t('Submission Details');
 531      foreach (array_values($submission_information) as $column => $label) {
 532        $header[2][$column] = $label;
 533      }
 534    }
 535  
 536    // Compile header information for components.
 537    foreach ($options['components'] as $cid) {
 538      if (isset($node->webform['components'][$cid])) {
 539        $component = $node->webform['components'][$cid];
 540  
 541        // Let each component determine its headers.
 542        if (webform_component_feature($component['type'], 'csv')) {
 543          $component_header = (array) webform_component_invoke($component['type'], 'csv_headers', $component, $options);
 544          $header[0] = array_merge($header[0], (array) $component_header[0]);
 545          $header[1] = array_merge($header[1], (array) $component_header[1]);
 546          $header[2] = array_merge($header[2], (array) $component_header[2]);
 547        }
 548      }
 549    }
 550  
 551    // Add headers to the file.
 552    foreach ($header as $row) {
 553      $exporter->add_row($handle, $row);
 554    }
 555  
 556    // Get all the submissions for the node.
 557    $submissions = webform_get_submissions($node->nid);
 558  
 559    // Generate a row for each submission.
 560    $row_count = 0;
 561    foreach ($submissions as $sid => $submission) {
 562      $row_count++;
 563  
 564      $row = array();
 565      if (isset($submission_information['serial'])) {
 566        $row[] = $row_count;
 567      }
 568      if (isset($submission_information['sid'])) {
 569        $row[] = $sid;
 570      }
 571      if (isset($submission_information['time'])) {
 572        $row[] = format_date($submission->submitted, 'small');
 573      }
 574      if (isset($submission_information['draft'])) {
 575        $row[] = $submission->is_draft;
 576      }
 577      if (isset($submission_information['ip_address'])) {
 578        $row[] =  $submission->remote_addr;
 579      }
 580      if (isset($submission_information['uid'])) {
 581        $row[] = $submission->uid;
 582      }
 583      if (isset($submission_information['username'])) {
 584        $row[] = $submission->name;
 585      }
 586  
 587      foreach ($options['components'] as $cid) {
 588        if (isset($node->webform['components'][$cid])) {
 589          $component = $node->webform['components'][$cid];
 590          // Let each component add its data.
 591          $raw_data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL;
 592          if (webform_component_feature($component['type'], 'csv')) {
 593            $data = webform_component_invoke($component['type'], 'csv_data', $component, $options, $raw_data);
 594            if (is_array($data)) {
 595              $row = array_merge($row, array_values($data));
 596            }
 597            else {
 598              $row[] = empty($data) ? '' : $data;
 599            }
 600          }
 601        }
 602      }
 603  
 604      // Write data from submissions.
 605      $data = $exporter->add_row($handle, $row);
 606    }
 607  
 608    // Add the closing bytes.
 609    $exporter->eof($handle);
 610  
 611    // Close the file.
 612    @fclose($handle);
 613  
 614    $export_name = _webform_safe_name($node->title);
 615    $exporter->set_headers($export_name);
 616    @readfile($file_name);  // The @ makes it silent.
 617    @unlink($file_name);  // Clean up, the @ makes it silent.
 618    exit();
 619  }
 620  
 621  /**
 622   * Provides a simple analysis of all submissions to a webform.
 623   *
 624   * @param $node
 625   *   The webform node on which to generate the analysis.
 626   * @param $sids
 627   *   An array of submission IDs to which this analysis may be filtered. May be
 628   *   used to generate results that are per-user or other groups of submissions.
 629   * @param $analysis_component
 630   *   A webform component. If passed in, additional information may be returned
 631   *   relating specifically to that component's analysis, such as a list of
 632   *   "Other" values within a select list.
 633   */
 634  function webform_results_analysis($node, $sids = array(), $analysis_component = NULL) {
 635    if (!is_array($sids)) {
 636      $sids = array();
 637    }
 638  
 639    // If showing a component's details, we don't want to loose the menu tabs.
 640    if ($analysis_component) {
 641      $item = menu_get_item('node/' . $node->nid . '/webform-results/analysis');
 642      menu_set_item(NULL, $item);
 643    }
 644  
 645    $components = isset($analysis_component) ? array($analysis_component['cid'] => $analysis_component) : $node->webform['components'];
 646    $data = array();
 647    foreach ($components as $cid => $component) {
 648      // Do component specific call.
 649      if ($row_data = webform_component_invoke($component['type'], 'analysis', $component, $sids, isset($analysis_component))) {
 650        $data[$cid] = $row_data;
 651      }
 652    }
 653  
 654    return theme('webform_results_analysis', $node, $data, $sids, $analysis_component);
 655  }
 656  
 657  /**
 658   * Output the content of the Analysis page.
 659   *
 660   * @see webform_results_analysis()
 661   */
 662  function theme_webform_results_analysis($node, $data, $sids = array(), $analysis_component = NULL) {
 663  
 664    $rows = array();
 665    $question_number = 0;
 666    $single = isset($analysis_component);
 667  
 668    $header = array(
 669      $single ? $analysis_component['name'] : t('Q'),
 670      array('data' => $single ? '&nbsp' : t('responses'), 'colspan' => '10')
 671    );
 672  
 673    foreach ($data as $cid => $row_data) {
 674      $question_number++;
 675  
 676      if (is_array($row_data)) {
 677        $row = array();
 678        if (!$single) {
 679          $row[] = array('data' => '<strong>' . $question_number . '</strong>', 'rowspan' => count($row_data) + 1, 'valign' => 'top');
 680          $row[] = array('data' => '<strong>' . check_plain($node->webform['components'][$cid]['name']) . '</strong>', 'colspan' => '10');
 681        }
 682        $rows = array_merge($rows, array_merge(array($row), $row_data));
 683      }
 684    }
 685  
 686    if (count($rows) == 0) {
 687      $rows[] = array(array('data' => t('There are no submissions for this form. <a href="!url">View this form</a>.', array('!url' => url('node/' . $node->nid))), 'colspan' => 20));
 688    }
 689  
 690    return theme('table', $header, $rows);
 691  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7