| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: webform.admin.inc,v 1.4.2.4 2010/08/30 20:22:15 quicksketch Exp $ 3 4 /** 5 * @file 6 * Administration pages provided by Webform module. 7 */ 8 9 /** 10 * Menu callback for admin/settings/webform. 11 */ 12 function webform_admin_settings() { 13 module_load_include('inc', 'webform', 'includes/webform.export'); 14 15 $node_types = node_get_types('names'); 16 $form['node_types'] = array( 17 '#type' => 'checkboxes', 18 '#title' => t('Webform-enabled content types'), 19 '#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.'), 20 '#options' => $node_types, 21 '#default_value' => webform_variable_get('webform_node_types'), 22 ); 23 24 $form['components'] = array( 25 '#type' => 'fieldset', 26 '#title' => t('Available components'), 27 '#collapsible' => TRUE, 28 '#collapsed' => FALSE, 29 '#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.'), 30 ); 31 32 // Add each component to the form: 33 $form['components'] = array('#tree' => TRUE); 34 $component_types = webform_components(TRUE); 35 foreach ($component_types as $key => $component) { 36 $form['components'][$key] = array( 37 '#title' => $component['label'], 38 '#description' => $component['description'], 39 '#type' => 'checkbox', 40 '#return_value' => 1, 41 '#default_value' => $component['enabled'], 42 ); 43 } 44 45 $form['email'] = array( 46 '#type' => 'fieldset', 47 '#title' => t('Default e-mail values'), 48 '#collapsible' => TRUE, 49 '#collapsed' => FALSE, 50 ); 51 52 $form['email']['webform_default_from_address'] = array( 53 '#type' => 'textfield', 54 '#title' => t('From address'), 55 '#default_value' => variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from'))), 56 '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'), 57 ); 58 59 $form['email']['webform_default_from_name'] = array( 60 '#type' => 'textfield', 61 '#title' => t('From name'), 62 '#default_value' => variable_get('webform_default_from_name', variable_get('site_name', '')), 63 '#description' => t('The default sender name which is used along with the default from address.'), 64 ); 65 66 $form['email']['webform_default_subject'] = array( 67 '#type' => 'textfield', 68 '#title' => t('Default subject'), 69 '#default_value' => variable_get('webform_default_subject', t('Form submission from: %title')), 70 '#description' => t('The default subject line of any e-mailed results.'), 71 ); 72 73 $form['email']['webform_default_format'] = array( 74 '#type' => 'radios', 75 '#title' => t('Format'), 76 '#options' => array( 77 0 => t('Plain text'), 78 1 => t('HTML'), 79 ), 80 '#default_value' => variable_get('webform_default_format', 0), 81 '#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.'), 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 ); 94 95 $form['advanced'] = array( 96 '#type' => 'fieldset', 97 '#title' => t('Advanced options'), 98 '#collapsible' => TRUE, 99 '#collapsed' => TRUE, 100 ); 101 102 $form['advanced']['webform_use_cookies'] = array( 103 '#type' => 'checkbox', 104 '#checked_value' => 1, 105 '#title' => t('Allow cookies for tracking submissions'), 106 '#default_value' => variable_get('webform_use_cookies', 0), 107 '#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.'), 108 ); 109 110 $form['advanced']['webform_email_address_format'] = array( 111 '#type' => 'radios', 112 '#title' => t('E-mail address format'), 113 '#options' => array( 114 'long' => t('Long format: "Example Name" <name@example.com>'), 115 'short' => t('Short format: name@example.com'), 116 ), 117 '#default_value' => variable_get('webform_email_address_format', 'long'), 118 '#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.'), 119 ); 120 121 $form['advanced']['webform_export_format'] = array( 122 '#type' => 'radios', 123 '#title' => t('Default export format'), 124 '#options' => webform_export_list(), 125 '#default_value' => variable_get('webform_export_format', 'delimited'), 126 ); 127 128 $form['advanced']['webform_csv_delimiter'] = array( 129 '#type' => 'select', 130 '#title' => t('Default export delimiter'), 131 '#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.'), 132 '#default_value' => variable_get('webform_csv_delimiter', '\t'), 133 '#options' => array( 134 ',' => t('Comma (,)'), 135 '\t' => t('Tab (\t)'), 136 ';' => t('Semicolon (;)'), 137 ':' => t('Colon (:)'), 138 '|' => t('Pipe (|)'), 139 '.' => t('Period (.)'), 140 ' ' => t('Space ( )'), 141 ), 142 ); 143 144 $form['advanced']['webform_submission_access_control'] = array( 145 '#type' => 'radios', 146 '#title' => t('Submission access control'), 147 '#options' => array( 148 '1' => t('Select the user roles that may submit each individual webform'), 149 '0' => t('Disable Webform submission access control'), 150 ), 151 '#default_value' => variable_get('webform_submission_access_control', 1), 152 '#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.'), 153 ); 154 155 $form = system_settings_form($form); 156 $form['#theme'] = 'webform_admin_settings'; 157 $form['#submit'][] = 'webform_admin_settings_submit'; 158 159 return $form; 160 } 161 162 function webform_admin_settings_submit($form, &$form_state) { 163 $disabled_components = array(); 164 foreach ($form_state['values']['components'] as $name => $enabled) { 165 if (!$enabled) { 166 $disabled_components[] = $name; 167 } 168 } 169 variable_set('webform_disabled_components', $disabled_components); 170 171 $webform_types = array(); 172 foreach ($form_state['values']['node_types'] as $type) { 173 if ($type) { 174 $webform_types[] = $type; 175 } 176 } 177 variable_set('webform_node_types', $webform_types); 178 } 179 180 function theme_webform_admin_settings($form) { 181 // Format the components into a table. 182 foreach (element_children($form['components']) as $key) { 183 $row = array(); 184 $row[] = $form['components'][$key]['#title']; 185 $row[] = $form['components'][$key]['#description']; 186 $form['components'][$key]['#title'] = NULL; 187 $form['components'][$key]['#description'] = NULL; 188 $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center'); 189 $rows[] = $row; 190 } 191 $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => 'checkbox')); 192 193 // Create the table inside the form. 194 $form['components']['table'] = array( 195 '#value' => theme('table', $header, $rows) 196 ); 197 198 return drupal_render($form); 199 } 200 201 /** 202 * Menu callback for admin/content/webform. Displays all webforms on the site. 203 */ 204 function webform_admin_content() { 205 $webform_types = webform_variable_get('webform_node_types'); 206 207 $nodes = array(); 208 if ($webform_types) { 209 $placeholders = implode(', ', array_fill(0, count($webform_types), "'%s'")); 210 $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); 211 while ($node = db_fetch_object($result)) { 212 $nodes[] = $node; 213 } 214 } 215 216 return theme('webform_admin_content', $nodes); 217 } 218 219 /** 220 * Create a comma-separate list of content types that are webform enabled. 221 */ 222 function webform_admin_type_list() { 223 $webform_types = webform_variable_get('webform_node_types'); 224 $webform_type_list = ''; 225 $webform_type_count = count($webform_types); 226 foreach ($webform_types as $n => $type) { 227 $webform_type_list .= l(node_get_types('name', $type), 'node/add/' . $type); 228 if ($n + 1 < $webform_type_count) { 229 $webform_type_list .= $webform_type_count == 2 ? ' ' : ', '; 230 } 231 if ($n + 2 == $webform_type_count) { 232 $webform_type_list .= t('or') . ' '; 233 } 234 } 235 236 return $webform_type_list; 237 } 238 239 /** 240 * Generate a list of all webforms avaliable on this site. 241 */ 242 function theme_webform_admin_content($nodes) { 243 $header = array( 244 t('Title'), 245 array('data' => t('View'), 'colspan' => '4'), 246 array('data' => t('Operations'), 'colspan' => '2') 247 ); 248 249 $rows = array(); 250 foreach ($nodes as $node) { 251 $rows[] = array( 252 l($node->title, 'node/' . $node->nid), 253 l(t('Submissions'), 'node/' . $node->nid . '/webform-results'), 254 l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'), 255 l(t('Table'), 'node/' . $node->nid . '/webform-results/table'), 256 l(t('Download'), 'node/' . $node->nid . '/webform-results/download'), 257 node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '', 258 user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '', 259 ); 260 } 261 262 if (empty($rows)) { 263 $webform_types = webform_variable_get('webform_node_types'); 264 if (empty($webform_types)) { 265 $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'))); 266 } 267 else { 268 $webform_type_list = webform_admin_type_list(); 269 $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list)); 270 } 271 272 $rows[] = array( 273 array('data' => $message, 'colspan' => 7), 274 ); 275 } 276 277 return theme('table', $header, $rows); 278 }
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 |