| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: email.inc,v 1.28.2.5 2010/09/28 22:43:56 quicksketch Exp $ 3 4 /** 5 * @file 6 * Webform module email component. 7 */ 8 9 /** 10 * Implementation of _webform_defaults_component(). 11 */ 12 function _webform_defaults_email() { 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 'width' => '', 23 'unique' => 0, 24 'disabled' => 0, 25 'title_display' => 0, 26 'description' => '', 27 'attributes' => array(), 28 ), 29 ); 30 } 31 32 /** 33 * Implementation of _webform_theme_component(). 34 */ 35 function _webform_theme_email() { 36 return array( 37 'webform_display_email' => array( 38 'arguments' => array('component' => NULL, 'value' => NULL, 'format' => 'plain'), 39 ), 40 ); 41 } 42 43 /** 44 * Implementation of _webform_edit_component(). 45 */ 46 function _webform_edit_email($component) { 47 $form['value'] = array( 48 '#type' => 'textfield', 49 '#title' => t('Default value'), 50 '#default_value' => $component['value'], 51 '#description' => t('The default value of the field.') . theme('webform_token_help'), 52 '#size' => 60, 53 '#maxlength' => 127, 54 '#weight' => 0, 55 '#attributes' => ($component['value'] == '%useremail' && count(form_get_errors()) == 0) ? array('disabled' => TRUE) : array(), 56 '#id' => 'email-value', 57 ); 58 $form['user_email'] = array( 59 '#type' => 'checkbox', 60 '#title' => t('User email as default'), 61 '#default_value' => $component['value'] == '%useremail' ? 1 : 0, 62 '#description' => t('Set the default value of this field to the user email, if he/she is logged in.'), 63 '#attributes' => array('onclick' => 'getElementById("email-value").value = (this.checked ? "%useremail" : ""); getElementById("email-value").disabled = this.checked;'), 64 '#weight' => 0, 65 '#element_validate' => array('_webform_edit_email_validate'), 66 ); 67 $form['display']['width'] = array( 68 '#type' => 'textfield', 69 '#title' => t('Width'), 70 '#default_value' => $component['extra']['width'], 71 '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'), 72 '#size' => 5, 73 '#maxlength' => 10, 74 '#parents' => array('extra', 'width'), 75 ); 76 $form['display']['disabled'] = array( 77 '#type' => 'checkbox', 78 '#title' => t('Disabled'), 79 '#return_value' => 1, 80 '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'), 81 '#weight' => 11, 82 '#default_value' => $component['extra']['disabled'], 83 '#parents' => array('extra', 'disabled'), 84 ); 85 $form['validation']['unique'] = array( 86 '#type' => 'checkbox', 87 '#title' => t('Unique'), 88 '#return_value' => 1, 89 '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'), 90 '#weight' => 1, 91 '#default_value' => $component['extra']['unique'], 92 '#parents' => array('extra', 'unique'), 93 ); 94 return $form; 95 } 96 97 /** 98 * Element validation function for the email edit form. 99 */ 100 function _webform_edit_email_validate($element, &$form_state) { 101 if ($form_state['values']['user_email']) { 102 $form_state['values']['value'] = '%useremail'; 103 } 104 } 105 106 /** 107 * Implementation of _webform_render_component(). 108 */ 109 function _webform_render_email($component, $value = NULL, $filter = TRUE) { 110 global $user; 111 $element = array( 112 '#type' => 'textfield', 113 '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], 114 '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL, 115 '#default_value' => _webform_filter_values($component['value']), 116 '#required' => $component['mandatory'], 117 '#weight' => $component['weight'], 118 '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'], 119 '#attributes' => $component['extra']['attributes'], 120 '#prefix' => '<div class="webform-component webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">', 121 '#suffix' => '</div>', 122 '#element_validate' => array('_webform_validate_email'), 123 '#pre_render' => array('webform_element_title_display'), 124 '#webform_component' => $component, 125 ); 126 127 // Add an e-mail class for identifying the difference from normal textfields. 128 $element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' email' : 'email'; 129 130 // Enforce uniqueness. 131 if ($component['extra']['unique']) { 132 $element['#element_validate'][] = 'webform_validate_unique'; 133 } 134 135 if (isset($value)) { 136 $element['#default_value'] = $value[0]; 137 } 138 139 if ($component['extra']['disabled']) { 140 $element['#attributes']['readonly'] = 'readonly'; 141 } 142 143 // Change the 'width' option to the correct 'size' option. 144 if ($component['extra']['width'] > 0) { 145 $element['#size'] = $component['extra']['width']; 146 } 147 148 return $element; 149 } 150 151 /** 152 * A Drupal Form API Validation function. Validates the entered values from 153 * email components on the client-side form. 154 * 155 * @param $form_element 156 * The e-mail form element. 157 * @param $form_state 158 * The full form state for the webform. 159 * @return 160 * None. Calls a form_set_error if the e-mail is not valid. 161 */ 162 function _webform_validate_email($form_element, &$form_state) { 163 $component = $form_element['#webform_component']; 164 $value = trim($form_element['#value']); 165 if (!empty($value) && !valid_email_address($value)) { 166 form_error($form_element, t('%value is not a valid email address.', array('%value' => $value))); 167 } 168 else { 169 form_set_value($form_element, $value, $form_state); 170 } 171 } 172 173 /** 174 * Implementation of _webform_display_component(). 175 */ 176 function _webform_display_email($component, $value, $format = 'html') { 177 return array( 178 '#title' => $component['name'], 179 '#weight' => $component['weight'], 180 '#theme' => 'webform_display_email', 181 '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'), 182 '#post_render' => array('webform_element_wrapper'), 183 '#format' => $format, 184 '#value' => isset($value[0]) ? $value[0] : '', 185 '#webform_component' => $component, 186 ); 187 } 188 189 /** 190 * Format the text output for this component. 191 */ 192 function theme_webform_display_email($element) { 193 $element['#value'] = empty($element['#value']) ? ' ' : $element['#value']; 194 return $element['#format'] == 'html' ? check_plain($element['#value']) : $element['#value']; 195 } 196 197 /** 198 * Implementation of _webform_analysis_component(). 199 */ 200 function _webform_analysis_email($component, $sids = array()) { 201 $placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array(); 202 $sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : ""; 203 $query = 'SELECT data ' . 204 ' FROM {webform_submitted_data} ' . 205 ' WHERE nid = %d ' . 206 ' AND cid = %d ' . $sidfilter; 207 $nonblanks = 0; 208 $submissions = 0; 209 $wordcount = 0; 210 211 $result = db_query($query, array_merge(array($component['nid'], $component['cid']), $sids)); 212 while ($data = db_fetch_array($result)) { 213 if (drupal_strlen(trim($data['data'])) > 0) { 214 $nonblanks++; 215 $wordcount += str_word_count(trim($data['data'])); 216 } 217 $submissions++; 218 } 219 220 $rows[0] = array(t('Left Blank'), ($submissions - $nonblanks)); 221 $rows[1] = array(t('User entered value'), $nonblanks); 222 $rows[2] = array(t('Average submission length in words (ex blanks)'), ($nonblanks != 0 ? number_format($wordcount/$nonblanks, 2) : '0')); 223 return $rows; 224 } 225 226 /** 227 * Implementation of _webform_table_component(). 228 */ 229 function _webform_table_email($component, $value) { 230 return check_plain(empty($value[0]) ? '' : $value[0]); 231 } 232 233 234 /** 235 * Implementation of _webform_csv_headers_component(). 236 */ 237 function _webform_csv_headers_email($component, $export_options) { 238 $header = array(); 239 $header[0] = ''; 240 $header[1] = ''; 241 $header[2] = $component['name']; 242 return $header; 243 } 244 245 /** 246 * Implementation of _webform_csv_data_component(). 247 */ 248 function _webform_csv_data_email($component, $export_options, $value) { 249 return empty($value[0]) ? '' : $value[0]; 250 }
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 |