| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Webform module hidden component. 6 */ 7 8 /** 9 * Implements _webform_defaults_component(). 10 */ 11 function _webform_defaults_hidden() { 12 return array( 13 'name' => '', 14 'form_key' => NULL, 15 'pid' => 0, 16 'weight' => 0, 17 'value' => '', 18 'extra' => array( 19 'private' => FALSE, 20 'hidden_type' => 'value', 21 ), 22 ); 23 } 24 25 /** 26 * Implements _webform_theme_component(). 27 */ 28 function _webform_theme_hidden() { 29 return array( 30 'webform_display_hidden' => array( 31 'arguments' => array('element' => NULL), 32 'file' => 'components/hidden.inc', 33 ), 34 ); 35 } 36 37 /** 38 * Implements _webform_edit_component(). 39 */ 40 function _webform_edit_hidden($component) { 41 $form = array(); 42 $form['value'] = array( 43 '#type' => 'textarea', 44 '#title' => t('Default value'), 45 '#default_value' => $component['value'], 46 '#description' => t('The default value of the field.') . theme('webform_token_help'), 47 '#cols' => 60, 48 '#rows' => 5, 49 '#weight' => 0, 50 ); 51 52 $form['display']['hidden_type'] = array( 53 '#type' => 'radios', 54 '#options' => array( 55 'value' => t('Secure value (allows use of all tokens)'), 56 'hidden' => t('Hidden element (less secure, changeable via JavaScript)'), 57 ), 58 '#title' => t('Hidden type'), 59 '#description' => t('Both types of hidden fields are not shown to end-users. Using a <em>Secure value</em> allows the use of <em>all tokens</em>, even for anonymous users.'), 60 '#default_value' => $component['extra']['hidden_type'], 61 '#parents' => array('extra', 'hidden_type'), 62 ); 63 64 return $form; 65 } 66 67 /** 68 * Implements _webform_render_component(). 69 */ 70 function _webform_render_hidden($component, $value = NULL, $filter = TRUE) { 71 $node = isset($component['nid']) ? node_load($component['nid']) : NULL; 72 73 // Set filtering options for "value" types, which are not displayed to the 74 // end user so they do not need to be sanitized. 75 $strict = $component['extra']['hidden_type'] != 'value'; 76 $allow_anonymous = $component['extra']['hidden_type'] == 'value'; 77 $default_value = $filter ? _webform_filter_values($component['value'], $node, NULL, NULL, $strict, $allow_anonymous) : $component['value']; 78 if (isset($value[0])) { 79 $default_value = $value[0]; 80 } 81 82 $element = array( 83 '#type' => 'hidden', 84 '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], 85 '#weight' => $component['weight'], 86 '#translatable' => array('title'), 87 ); 88 89 if ($component['extra']['hidden_type'] == 'value') { 90 $element['#type'] = 'value'; 91 $element['#value'] = $default_value; 92 } 93 else { 94 $element['#type'] = 'hidden'; 95 $element['#default_value'] = $default_value; 96 } 97 98 return $element; 99 } 100 101 /** 102 * Implements _webform_display_component(). 103 */ 104 function _webform_display_hidden($component, $value, $format = 'html') { 105 $element = array( 106 '#title' => $component['name'], 107 '#value' => isset($value[0]) ? $value[0] : NULL, 108 '#weight' => $component['weight'], 109 '#format' => $format, 110 '#theme' => 'webform_display_hidden', 111 '#theme_wrappers' => $format == 'html' ? array('webform_element', 'webform_element_wrapper') : array('webform_element_text'), 112 '#post_render' => array('webform_element_wrapper'), 113 '#translatable' => array('title'), 114 ); 115 116 return $element; 117 } 118 119 function theme_webform_display_hidden($element) { 120 return $element['#format'] == 'html' ? check_plain($element['#value']) : $element['#value']; 121 } 122 123 /** 124 * Implements _webform_analysis_component(). 125 */ 126 function _webform_analysis_hidden($component, $sids = array()) { 127 $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array(); 128 $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : ""; 129 $query = 'SELECT data ' . 130 ' FROM {webform_submitted_data} ' . 131 ' WHERE nid = %d ' . 132 ' AND cid = %d ' . $sidfilter; 133 $nonblanks = 0; 134 $submissions = 0; 135 $wordcount = 0; 136 137 $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); 138 while ($data = db_fetch_array($result)) { 139 if (strlen(trim($data['data'])) > 0) { 140 $nonblanks++; 141 $wordcount += str_word_count(trim($data['data'])); 142 } 143 $submissions++; 144 } 145 146 $rows[0] = array( t('Empty'), ($submissions - $nonblanks)); 147 $rows[1] = array( t('Non-empty'), $nonblanks); 148 $rows[2] = array( t('Average submission length in words (ex blanks)'), 149 ($nonblanks !=0 ? number_format($wordcount/$nonblanks, 2) : '0')); 150 return $rows; 151 } 152 153 /** 154 * Implements _webform_csv_data_component(). 155 */ 156 function _webform_table_hidden($component, $value) { 157 return check_plain(empty($value[0]) ? '' : $value[0]); 158 } 159 160 /** 161 * Implements _webform_csv_data_component(). 162 */ 163 function _webform_csv_headers_hidden($component, $export_options) { 164 $header = array(); 165 $header[0] = ''; 166 $header[1] = ''; 167 $header[2] = $component['name']; 168 return $header; 169 } 170 171 /** 172 * Implements _webform_csv_data_component(). 173 */ 174 function _webform_csv_data_hidden($component, $export_options, $value) { 175 return isset($value[0]) ? $value[0] : ''; 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |