| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * Administration pages provided by Webform module. 6 */ 7 8 /** 9 * Menu callback for admin/settings/webform. 10 */ 11 function webform_admin_settings() { 12 module_load_include('inc', 'webform', 'includes/webform.export'); 13 14 $node_types = node_get_types('names'); 15 $form['node_types'] = array( 16 '#type' => 'checkboxes', 17 '#title' => t('Webform-enabled content types'), 18 '#description' => t('Webform allows you to enable the webform components for any content type. Choose the types on which you would like to associate webform components.'), 19 '#options' => $node_types, 20 '#default_value' => webform_variable_get('webform_node_types'), 21 ); 22 23 $form['components'] = array( 24 '#type' => 'fieldset', 25 '#title' => t('Available components'), 26 '#collapsible' => TRUE, 27 '#collapsed' => FALSE, 28 '#description' => t('These are the available field types for your installation of Webform. You may disable any of these components by unchecking its corresponding box. Only checked components will be available in existing or new webforms.'), 29 ); 30 31 // Add each component to the form: 32 $form['components'] = array('#tree' => TRUE); 33 $component_types = webform_components(TRUE); 34 foreach ($component_types as $key => $component) { 35 $form['components'][$key] = array( 36 '#title' => $component['label'], 37 '#description' => $component['description'], 38 '#type' => 'checkbox', 39 '#return_value' => 1, 40 '#default_value' => $component['enabled'], 41 ); 42 } 43 44 $form['email'] = array( 45 '#type' => 'fieldset', 46 '#title' => t('Default e-mail values'), 47 '#collapsible' => TRUE, 48 '#collapsed' => FALSE, 49 ); 50 51 $form['email']['webform_default_from_address'] = array( 52 '#type' => 'textfield', 53 '#title' => t('From address'), 54 '#default_value' => variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from'))), 55 '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'), 56 ); 57 58 $form['email']['webform_default_from_name'] = array( 59 '#type' => 'textfield', 60 '#title' => t('From name'), 61 '#default_value' => variable_get('webform_default_from_name', variable_get('site_name', '')), 62 '#description' => t('The default sender name which is used along with the default from address.'), 63 ); 64 65 $form['email']['webform_default_subject'] = array( 66 '#type' => 'textfield', 67 '#title' => t('Default subject'), 68 '#default_value' => variable_get('webform_default_subject', t('Form submission from: %title')), 69 '#description' => t('The default subject line of any e-mailed results.'), 70 ); 71 72 $form['email']['webform_default_format'] = array( 73 '#type' => 'radios', 74 '#title' => t('Format'), 75 '#options' => array( 76 0 => t('Plain text'), 77 1 => t('HTML'), 78 ), 79 '#default_value' => variable_get('webform_default_format', 0), 80 '#description' => t('The default format for new e-mail settings. Webform e-mail options take precedence over the settings for system-wide e-mails configured in MIME mail.'), 81 '#access' => webform_email_html_capable(), 82 ); 83 84 $form['email']['webform_format_override'] = array( 85 '#type' => 'radios', 86 '#title' => t('Format override'), 87 '#options' => array( 88 0 => t('Per-webform configuration of e-mail format'), 89 1 => t('Send all e-mails in the default format'), 90 ), 91 '#default_value' => variable_get('webform_format_override', 0), 92 '#description' => t('Force all webform e-mails to be sent in the default format.'), 93 '#access' => webform_email_html_capable(), 94 ); 95 96 $form['advanced'] = array( 97 '#type' => 'fieldset', 98 '#title' => t('Advanced options'), 99 '#collapsible' => TRUE, 100 '#collapsed' => TRUE, 101 ); 102 103 $form['advanced']['webform_use_cookies'] = array( 104 '#type' => 'checkbox', 105 '#checked_value' => 1, 106 '#title' => t('Allow cookies for tracking submissions'), 107 '#default_value' => variable_get('webform_use_cookies', 0), 108 '#description' => t('<a href="http://www.wikipedia.org/wiki/HTTP_cookie">Cookies</a> can be used to help prevent the same user from repeatedly submitting a webform. This feature is not needed for limiting submissions per user, though it can increase accuracy in some situations. Besides cookies, Webform also uses IP addresses and site usernames to prevent repeated submissions.'), 109 ); 110 111 $form['advanced']['webform_search_index'] = array( 112 '#type' => 'checkbox', 113 '#checked_value' => 1, 114 '#title' => t('Include webform forms in search index'), 115 '#default_value' => variable_get('webform_search_index', 1), 116 '#description' => t('When selected, all Webform nodes will have their form components indexed by the search engine.'), 117 '#access' => module_exists('search'), 118 ); 119 120 $form['advanced']['webform_email_address_format'] = array( 121 '#type' => 'radios', 122 '#title' => t('E-mail address format'), 123 '#options' => array( 124 'long' => t('Long format: "Example Name" <name@example.com>'), 125 'short' => t('Short format: name@example.com'), 126 ), 127 '#default_value' => variable_get('webform_email_address_format', 'long'), 128 '#description' => t('Most servers support the "long" format which will allow for more friendly From addresses in e-mails sent. However many Windows-based servers are unable to send in the long format. Change this option if experiencing problems sending e-mails with Webform.'), 129 ); 130 131 $form['advanced']['webform_export_format'] = array( 132 '#type' => 'radios', 133 '#title' => t('Default export format'), 134 '#options' => webform_export_list(), 135 '#default_value' => variable_get('webform_export_format', 'delimited'), 136 ); 137 138 $form['advanced']['webform_csv_delimiter'] = array( 139 '#type' => 'select', 140 '#title' => t('Default export delimiter'), 141 '#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.'), 142 '#default_value' => variable_get('webform_csv_delimiter', '\t'), 143 '#options' => array( 144 ',' => t('Comma (,)'), 145 '\t' => t('Tab (\t)'), 146 ';' => t('Semicolon (;)'), 147 ':' => t('Colon (:)'), 148 '|' => t('Pipe (|)'), 149 '.' => t('Period (.)'), 150 ' ' => t('Space ( )'), 151 ), 152 ); 153 154 $form['advanced']['webform_submission_access_control'] = array( 155 '#type' => 'radios', 156 '#title' => t('Submission access control'), 157 '#options' => array( 158 '1' => t('Select the user roles that may submit each individual webform'), 159 '0' => t('Disable Webform submission access control'), 160 ), 161 '#default_value' => variable_get('webform_submission_access_control', 1), 162 '#description' => t('By default, the configuration form for each webform allows the administrator to choose which roles may submit the form. You may want to allow users to always submit the form if you are using a separate node access module to control access to webform nodes themselves.'), 163 ); 164 165 $form = system_settings_form($form); 166 $form['#theme'] = 'webform_admin_settings'; 167 array_unshift($form['#submit'], 'webform_admin_settings_submit'); 168 169 return $form; 170 } 171 172 /** 173 * Submit handler for the webform_admin_settings() form. 174 */ 175 function webform_admin_settings_submit($form, &$form_state) { 176 $disabled_components = array(); 177 foreach ($form_state['values']['components'] as $name => $enabled) { 178 if (!$enabled) { 179 $disabled_components[] = $name; 180 } 181 } 182 // Update $form_state and let system_settings_form_submit() handle saving. 183 $form_state['values']['webform_disabled_components'] = $disabled_components; 184 unset($form_state['values']['components']); 185 186 // Change the name of the node type variable and clean it up. 187 $form_state['values']['webform_node_types'] = array_keys(array_filter($form_state['values']['node_types'])); 188 unset($form_state['values']['node_types']); 189 } 190 191 /** 192 * Theme the output of the webform_admin_settings() form. 193 */ 194 function theme_webform_admin_settings($form) { 195 // Format the components into a table. 196 foreach (element_children($form['components']) as $key) { 197 $row = array(); 198 $row[] = $form['components'][$key]['#title']; 199 $row[] = $form['components'][$key]['#description']; 200 $form['components'][$key]['#title'] = NULL; 201 $form['components'][$key]['#description'] = NULL; 202 $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center'); 203 $rows[] = $row; 204 } 205 $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => 'checkbox')); 206 207 // Create the table inside the form. 208 $form['components']['table'] = array( 209 '#value' => theme('table', $header, $rows) 210 ); 211 212 return drupal_render($form); 213 } 214 215 /** 216 * Menu callback for admin/content/webform. Displays all webforms on the site. 217 */ 218 function webform_admin_content() { 219 $webform_types = webform_variable_get('webform_node_types'); 220 221 $nodes = array(); 222 if ($webform_types) { 223 $placeholders = implode(', ', array_fill(0, count($webform_types), "'%s'")); 224 $result = db_query(db_rewrite_sql("SELECT n.*, r.* FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid WHERE n.type IN ($placeholders)", 'n', 'nid', $webform_types), $webform_types); 225 while ($node = db_fetch_object($result)) { 226 $nodes[] = $node; 227 } 228 } 229 230 return theme('webform_admin_content', $nodes); 231 } 232 233 /** 234 * Create a comma-separate list of content types that are webform enabled. 235 */ 236 function webform_admin_type_list() { 237 $webform_types = webform_variable_get('webform_node_types'); 238 $webform_type_list = ''; 239 $webform_type_count = count($webform_types); 240 foreach ($webform_types as $n => $type) { 241 $webform_type_list .= l(node_get_types('name', $type), 'node/add/' . $type); 242 if ($n + 1 < $webform_type_count) { 243 $webform_type_list .= $webform_type_count == 2 ? ' ' : ', '; 244 } 245 if ($n + 2 == $webform_type_count) { 246 $webform_type_list .= t('or') . ' '; 247 } 248 } 249 250 return $webform_type_list; 251 } 252 253 /** 254 * Generate a list of all webforms avaliable on this site. 255 */ 256 function theme_webform_admin_content($nodes) { 257 $header = array( 258 t('Title'), 259 array('data' => t('View'), 'colspan' => '4'), 260 array('data' => t('Operations'), 'colspan' => '2') 261 ); 262 263 $rows = array(); 264 foreach ($nodes as $node) { 265 $rows[] = array( 266 l($node->title, 'node/' . $node->nid), 267 l(t('Submissions'), 'node/' . $node->nid . '/webform-results'), 268 l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'), 269 l(t('Table'), 'node/' . $node->nid . '/webform-results/table'), 270 l(t('Download'), 'node/' . $node->nid . '/webform-results/download'), 271 node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '', 272 user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '', 273 ); 274 } 275 276 if (empty($rows)) { 277 $webform_types = webform_variable_get('webform_node_types'); 278 if (empty($webform_types)) { 279 $message = t('Webform is currently not enabled on any content types.') . ' ' . t('Visit the <a href="!url">Webform settings</a> page and enable Webform on at least one content type.', array('!url' => url('admin/settings/webform'))); 280 } 281 else { 282 $webform_type_list = webform_admin_type_list(); 283 $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list)); 284 } 285 286 $rows[] = array( 287 array('data' => $message, 'colspan' => 7), 288 ); 289 } 290 291 return theme('table', $header, $rows); 292 }
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 |