[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/webform/components/ -> hidden.inc (source)

   1  <?php
   2  // $Id: hidden.inc,v 1.21.2.4 2010/09/28 22:43:55 quicksketch Exp $
   3  
   4  /**
   5   * @file
   6   * Webform module hidden component.
   7   */
   8  
   9  /**
  10   * Implementation of _webform_defaults_component().
  11   */
  12  function _webform_defaults_hidden() {
  13    return array(
  14      'name' => '',
  15      'form_key' => NULL,
  16      'pid' => 0,
  17      'weight' => 0,
  18      'value' => '',
  19      'extra' => array(
  20      ),
  21    );
  22  }
  23  
  24  /**
  25   * Implementation of _webform_theme_component().
  26   */
  27  function _webform_theme_hidden() {
  28    return array(
  29      'webform_display_hidden' => array(
  30        'arguments' => array('element' => NULL),
  31      ),
  32    );
  33  }
  34  
  35  /**
  36   * Implementation of _webform_edit_component().
  37   */
  38  function _webform_edit_hidden($component) {
  39    $form = array();
  40    $form['value'] = array(
  41      '#type' => 'textarea',
  42      '#title' => t('Default value'),
  43      '#default_value' => $component['value'],
  44      '#description' => t('The default value of the field.') . theme('webform_token_help'),
  45      '#cols' => 60,
  46      '#rows' => 5,
  47      '#weight' => 0,
  48    );
  49    $form['extra']['description'] = array(); // Hide the description box.
  50    $form['display'] = array('#type' => 'markup'); // Hide the display options.
  51    $form['display']['title_display'] = array();
  52    return $form;
  53  }
  54  
  55  /**
  56   * Implementation of _webform_render_component().
  57   */
  58  function _webform_render_hidden($component, $value = NULL, $filter = TRUE) {
  59    $element = array(
  60      '#type' => 'hidden',
  61      '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
  62      '#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'],
  63      '#weight' => $component['weight'],
  64    );
  65  
  66    if (isset($value[0])) {
  67      $element['#default_value'] = $value[0];
  68    }
  69  
  70    return $element;
  71  }
  72  
  73  /**
  74   * Implementation of _webform_display_component().
  75   */
  76  function _webform_display_hidden($component, $value, $format = 'html') {
  77    $element = array(
  78      '#title' => t('!name (hidden)', array('!name' => $component['name'])),
  79      '#value' => isset($value[0]) ? $value[0] : NULL,
  80      '#weight' => $component['weight'],
  81      '#theme' => 'webform_display_hidden',
  82      '#format' => $format,
  83      '#theme' => 'webform_display_hidden',
  84      '#theme_wrappers' => $format == 'text' ? array('webform_element_text') : array('webform_element'),
  85      '#post_render' => array('webform_element_wrapper'),
  86      '#webform_component' => $component,
  87    );
  88  
  89    // TODO: This check is unusual. It shows hidden fields in e-mails but not
  90    // when viewing in the browser unless you're an administrator. This should be
  91    // a more logical check. See these related issues:
  92    // http://drupal.org/node/313639
  93    // http://drupal.org/node/781786
  94    if ($format == 'html') {
  95      $element['#access'] = user_access('edit all webform submissions') || user_access('access all webform results');
  96    }
  97  
  98    return $element;
  99  }
 100  
 101  function theme_webform_display_hidden($element) {
 102    return $element['#format'] == 'html' ? check_plain($element['#value']) : $element['#value'];
 103  }
 104  
 105  /**
 106   * Implementation of _webform_analysis_component().
 107   */
 108  function _webform_analysis_hidden($component, $sids = array()) {
 109    $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
 110    $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
 111    $query = 'SELECT data ' .
 112      ' FROM {webform_submitted_data} ' .
 113      ' WHERE nid = %d ' .
 114      ' AND cid = %d ' . $sidfilter;
 115    $nonblanks = 0;
 116    $submissions = 0;
 117    $wordcount = 0;
 118  
 119    $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids));
 120    while ($data = db_fetch_array($result)) {
 121      if ( strlen(trim($data['data'])) > 0 ) {
 122        $nonblanks++;
 123        $wordcount += str_word_count(trim($data['data']));
 124      }
 125      $submissions++;
 126    }
 127  
 128    $rows[0] = array( t('Empty'), ($submissions - $nonblanks));
 129    $rows[1] = array( t('Non-empty'), $nonblanks);
 130    $rows[2] = array( t('Average submission length in words (ex blanks)'),
 131                      ($nonblanks !=0 ? number_format($wordcount/$nonblanks, 2) : '0'));
 132    return $rows;
 133  }
 134  
 135  /**
 136   * Implementation of _webform_csv_data_component().
 137   */
 138  function _webform_table_hidden($component, $value) {
 139    return check_plain(empty($value[0]) ? '' : $value[0]);
 140  }
 141  
 142  /**
 143   * Implementation of _webform_csv_data_component().
 144   */
 145  function _webform_csv_headers_hidden($component, $export_options) {
 146    $header = array();
 147    $header[0] = '';
 148    $header[1] = '';
 149    $header[2] = $component['name'];
 150    return $header;
 151  }
 152  
 153  /**
 154   * Implementation of _webform_csv_data_component().
 155   */
 156  function _webform_csv_data_hidden($component, $export_options, $value) {
 157    return empty($value[0]) ? '' : $value[0];
 158  }


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