| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: textarea.inc,v 1.20.2.4 2010/09/28 22:43:55 quicksketch Exp $ 3 4 /** 5 * @file 6 * Webform module textarea component. 7 */ 8 9 /** 10 * Implementation of _webform_defaults_component(). 11 */ 12 function _webform_defaults_textarea() { 13 return array( 14 'name' => '', 15 'form_key' => NULL, 16 'pid' => 0, 17 'weight' => 0, 18 'value' => '', 19 'mandatory' => 0, 20 'email' => 1, 21 'extra' => array( 22 'cols' => '', 23 'rows' => '', 24 'title_display' => 0, 25 'resizable' => 1, 26 'disabled' => 0, 27 'description' => '', 28 'attributes' => array(), 29 ), 30 ); 31 } 32 33 34 /** 35 * Implementation of _webform_theme_component(). 36 */ 37 function _webform_theme_textarea() { 38 return array( 39 'webform_display_textarea' => array( 40 'arguments' => array('element' => NULL), 41 ), 42 ); 43 } 44 45 /** 46 * Implementation of _webform_edit_component(). 47 */ 48 function _webform_edit_textarea($component) { 49 $form = array(); 50 $form['value'] = array( 51 '#type' => 'textarea', 52 '#title' => t('Default value'), 53 '#default_value' => $component['value'], 54 '#description' => t('The default value of the field.') . theme('webform_token_help'), 55 '#cols' => 60, 56 '#rows' => 5, 57 '#weight' => 0, 58 ); 59 $form['display']['cols'] = array( 60 '#type' => 'textfield', 61 '#title' => t('Width'), 62 '#default_value' => $component['extra']['cols'], 63 '#description' => t('Width of the textarea.') . ' ' . t('Leaving blank will use the default size.'), 64 '#size' => 5, 65 '#maxlength' => 10, 66 '#parents' => array('extra', 'cols'), 67 ); 68 $form['display']['rows'] = array( 69 '#type' => 'textfield', 70 '#title' => t('Height'), 71 '#default_value' => $component['extra']['rows'], 72 '#description' => t('Height of the textarea.') . ' ' . t('Leaving blank will use the default size.'), 73 '#size' => 5, 74 '#maxlength' => 10, 75 '#parents' => array('extra', 'rows'), 76 ); 77 $form['display']['resizable'] = array( 78 '#type' => 'checkbox', 79 '#title' => t('Resizable'), 80 '#description' => t('Make this field resizable by the user.'), 81 '#weight' => 2, 82 '#default_value' => $component['extra']['resizable'], 83 '#parents' => array('extra', 'resizable'), 84 ); 85 $form['display']['disabled'] = array( 86 '#type' => 'checkbox', 87 '#title' => t('Disabled'), 88 '#return_value' => 1, 89 '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'), 90 '#weight' => 11, 91 '#default_value' => $component['extra']['disabled'], 92 '#parents' => array('extra', 'disabled'), 93 ); 94 return $form; 95 } 96 97 /** 98 * Implementation of _webform_render_component(). 99 */ 100 function _webform_render_textarea($component, $value = NULL, $filter = TRUE) { 101 $element = array( 102 '#type' => 'textarea', 103 '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], 104 '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL, 105 '#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'], 106 '#required' => $component['mandatory'], 107 '#weight' => $component['weight'], 108 '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'], 109 '#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5, 110 '#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60, 111 '#attributes' => $component['extra']['attributes'], 112 '#resizable' => (bool) $component['extra']['resizable'], // MUST be FALSE to disable. 113 '#prefix' => '<div class="webform-component webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">', 114 '#suffix' => '</div>', 115 '#pre_render' => array('webform_element_title_display'), 116 '#webform_component' => $component, 117 ); 118 119 if ($component['extra']['disabled']) { 120 $element['#attributes']['readonly'] = 'readonly'; 121 } 122 123 if (isset($value)) { 124 $element['#default_value'] = $value[0]; 125 } 126 127 return $element; 128 } 129 130 /** 131 * Implementation of _webform_display_component(). 132 */ 133 function _webform_display_textarea($component, $value, $format = 'html') { 134 return array( 135 '#title' => $component['name'], 136 '#weight' => $component['weight'], 137 '#theme' => 'webform_display_textarea', 138 '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'), 139 '#post_render' => array('webform_element_wrapper'), 140 '#format' => $format, 141 '#value' => isset($value[0]) ? $value[0] : '', 142 '#webform_component' => $component, 143 ); 144 } 145 146 /** 147 * Format the output of data for this component. 148 */ 149 function theme_webform_display_textarea($element) { 150 $output = $element['#format'] == 'html' ? str_replace("\n", '<br />', check_plain($element['#value'])) : $element['#value']; 151 if (strlen($output) > 80) { 152 $output = ($element['#format'] == 'html') ? '<div class="webform-long-answer">' . $output . '</div>' : $output; 153 } 154 return $output ? $output : ' '; 155 } 156 157 /** 158 * Implementation of _webform_analysis_component(). 159 */ 160 function _webform_analysis_textarea($component, $sids = array()) { 161 $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array(); 162 $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : ""; 163 $query = 'SELECT data ' . 164 ' FROM {webform_submitted_data} ' . 165 ' WHERE nid = %d ' . 166 ' AND cid = %d ' . $sidfilter; 167 $nonblanks = 0; 168 $submissions = 0; 169 $wordcount = 0; 170 171 $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); 172 while ($data = db_fetch_array($result)) { 173 if (drupal_strlen(trim($data['data'])) > 0) { 174 $nonblanks++; 175 $wordcount += str_word_count(trim($data['data'])); 176 } 177 $submissions++; 178 } 179 180 $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks)); 181 $rows[1] = array(t('User entered value'), $nonblanks); 182 $rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); 183 return $rows; 184 } 185 186 /** 187 * Implementation of _webform_table_component(). 188 */ 189 function _webform_table_textarea($component, $value) { 190 return empty($value[0]) ? '' : check_plain($value[0]); 191 } 192 193 /** 194 * Implementation of _webform_csv_headers_component(). 195 */ 196 function _webform_csv_headers_textarea($component, $export_options) { 197 $header = array(); 198 $header[0] = ''; 199 $header[1] = ''; 200 $header[2] = $component['name']; 201 return $header; 202 } 203 204 /** 205 * Implementation of _webform_csv_data_component(). 206 */ 207 function _webform_csv_data_textarea($component, $export_options, $value) { 208 return empty($value[0]) ? '' : $value[0]; 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |