webform.admin.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. /**
  3. * @file
  4. * Administration pages provided by Webform module.
  5. */
  6. /**
  7. * Menu callback for admin/config/content/webform.
  8. */
  9. function webform_admin_settings() {
  10. module_load_include('inc', 'webform', 'includes/webform.export');
  11. $form['components'] = array(
  12. '#type' => 'fieldset',
  13. '#title' => t('Available components'),
  14. '#collapsible' => TRUE,
  15. '#collapsed' => FALSE,
  16. '#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.'),
  17. );
  18. // Add each component to the form:
  19. $form['components'] += array('#tree' => TRUE);
  20. $component_types = webform_components(TRUE);
  21. foreach ($component_types as $key => $component) {
  22. $form['components'][$key] = array(
  23. '#title' => $component['label'],
  24. '#description' => $component['description'],
  25. '#type' => 'checkbox',
  26. '#return_value' => 1,
  27. '#default_value' => $component['enabled'],
  28. );
  29. }
  30. $form['email'] = array(
  31. '#type' => 'fieldset',
  32. '#title' => t('Default e-mail values'),
  33. '#collapsible' => TRUE,
  34. '#collapsed' => FALSE,
  35. );
  36. $form['email']['webform_default_from_address'] = array(
  37. '#type' => 'textfield',
  38. '#title' => t('From address'),
  39. '#default_value' => webform_variable_get('webform_default_from_address'),
  40. '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
  41. );
  42. $form['email']['webform_default_from_name'] = array(
  43. '#type' => 'textfield',
  44. '#title' => t('From name'),
  45. '#default_value' => webform_variable_get('webform_default_from_name'),
  46. '#description' => t('The default sender name which is used along with the default from address.'),
  47. );
  48. $form['email']['webform_default_subject'] = array(
  49. '#type' => 'textfield',
  50. '#title' => t('Default subject'),
  51. '#default_value' => webform_variable_get('webform_default_subject'),
  52. '#description' => t('The default subject line of any e-mailed results.'),
  53. );
  54. $form['email']['webform_email_replyto'] = array(
  55. '#type' => 'checkbox',
  56. '#title' => t('Use Reply-To header'),
  57. '#default_value' => webform_variable_get('webform_email_replyto'),
  58. '#description' => t('If the default from name and address are set above, send all e-mail from the default address set the "Reply-To" header to the actual sender. This helps prevent e-mail from being flagged as spam.'),
  59. );
  60. $form['email']['webform_email_html_capable'] = array(
  61. '#type' => 'checkbox',
  62. '#title' => t('HTML mail system'),
  63. '#default_value' => webform_variable_get('webform_email_html_capable'),
  64. '#description' => t('Whether the mail system configured for webform is capable of sending mail in HTML format.'),
  65. );
  66. $form['email']['webform_default_format'] = array(
  67. '#type' => 'radios',
  68. '#title' => t('Format'),
  69. '#options' => array(
  70. 0 => t('Plain text'),
  71. 1 => t('HTML'),
  72. ),
  73. '#default_value' => webform_variable_get('webform_default_format'),
  74. '#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.'),
  75. '#states' => array(
  76. 'visible' => array(
  77. ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
  78. ),
  79. ),
  80. );
  81. $form['email']['webform_format_override'] = array(
  82. '#type' => 'radios',
  83. '#title' => t('Format override'),
  84. '#options' => array(
  85. 0 => t('Per-webform configuration of e-mail format'),
  86. 1 => t('Send all e-mails in the default format'),
  87. ),
  88. '#default_value' => webform_variable_get('webform_format_override'),
  89. '#description' => t('Force all webform e-mails to be sent in the default format.'),
  90. '#states' => array(
  91. 'visible' => array(
  92. ':input[name="webform_email_html_capable"]' => array('checked' => TRUE),
  93. ),
  94. ),
  95. );
  96. $form['progressbar'] = array(
  97. '#type' => 'fieldset',
  98. '#title' => t('Progress bar'),
  99. '#collapsible' => TRUE,
  100. '#collapsed' => TRUE,
  101. );
  102. $form['progressbar']['webform_progressbar_style'] = array(
  103. '#type' => 'checkboxes',
  104. '#title' => t('Progress bar style'),
  105. '#options' => array(
  106. 'progressbar_bar' => t('Show progress bar'),
  107. 'progressbar_page_number' => t('Show page number as number of completed (i.e. Page 1 of 10)'),
  108. 'progressbar_percent' => t('Show percentage completed (i.e. 10%)'),
  109. 'progressbar_pagebreak_labels' => t('Show page labels from page break components'),
  110. 'progressbar_include_confirmation' => t('Include confirmation page in progress bar'),
  111. ),
  112. '#default_value' => webform_variable_get('webform_progressbar_style'),
  113. '#description' => t('Choose how the progress bar should be displayed for multi-page forms.'),
  114. );
  115. $form['progressbar']['webform_progressbar_label_first'] = array(
  116. '#type' => 'textfield',
  117. '#title' => t('First page label'),
  118. '#default_value' => webform_variable_get('webform_progressbar_label_first'),
  119. '#maxlength' => 255,
  120. );
  121. $form['progressbar']['webform_progressbar_label_confirmation'] = array(
  122. '#type' => 'textfield',
  123. '#title' => t('Confirmation page label'),
  124. '#default_value' => webform_variable_get('webform_progressbar_label_confirmation'),
  125. '#maxlength' => 255,
  126. );
  127. $form['advanced'] = array(
  128. '#type' => 'fieldset',
  129. '#title' => t('Advanced options'),
  130. '#collapsible' => TRUE,
  131. '#collapsed' => TRUE,
  132. '#weight' => 20,
  133. );
  134. $form['advanced']['webform_tracking_mode'] = array(
  135. '#type' => 'radios',
  136. '#title' => t('Track anonymous users by:'),
  137. '#options' => array(
  138. 'cookie' => t('Cookie only (least strict)'),
  139. 'ip_address' => t('IP address only'),
  140. 'strict' => t('Both cookie and IP address (most strict)'),
  141. ),
  142. '#default_value' => webform_variable_get('webform_tracking_mode'),
  143. '#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. Limiting by IP address is more effective against repeated submissions, but may result in unintentional blocking of users sharing the same address. Confidential submissions are tracked by cookie only. Logged-in users are always tracked by their user ID and are not affected by this option.'),
  144. );
  145. $form['advanced']['webform_email_address_format'] = array(
  146. '#type' => 'radios',
  147. '#title' => t('E-mail address format'),
  148. '#options' => array(
  149. 'long' => t('Long format: "Example Name" &lt;name@example.com&gt;'),
  150. 'short' => t('Short format: name@example.com'),
  151. ),
  152. '#default_value' => webform_variable_get('webform_email_address_format'),
  153. '#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.'),
  154. );
  155. $form['advanced']['webform_email_address_individual'] = array(
  156. '#type' => 'radios',
  157. '#title' => t('E-mailing multiple recipients'),
  158. '#options' => array(
  159. '0' => t('Send a single e-mail to all recipients'),
  160. '1' => t('Send individual e-mails to each recipient'),
  161. ),
  162. '#default_value' => webform_variable_get('webform_email_address_individual'),
  163. '#description' => t('Individual e-mails increases privacy by not revealing the addresses of other recipients. A single e-mail to all recipients lets them use "Reply All" to communicate.'),
  164. );
  165. $date_format_options = array();
  166. foreach (system_get_date_types() as $type => $type_info) {
  167. $date_format_options[$type] = t('@title — @sample', array('@title' => $type_info['title'], '@sample' => format_date(REQUEST_TIME, 'custom', webform_date_format($type))));
  168. }
  169. $form['advanced']['webform_date_type'] = array(
  170. '#type' => 'select',
  171. '#title' => t('Date format'),
  172. '#options' => $date_format_options,
  173. '#default_value' => webform_variable_get('webform_date_type'),
  174. '#description' => t('Choose the format for the display of date components. Only the date portion of the format is used. Reporting and export use the short format.'),
  175. );
  176. $form['advanced']['webform_export_format'] = array(
  177. '#type' => 'radios',
  178. '#title' => t('Default export format'),
  179. '#options' => webform_export_list(),
  180. '#default_value' => webform_variable_get('webform_export_format'),
  181. );
  182. $form['advanced']['webform_csv_delimiter'] = array(
  183. '#type' => 'select',
  184. '#title' => t('Default export delimiter'),
  185. '#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.'),
  186. '#default_value' => webform_variable_get('webform_csv_delimiter'),
  187. '#options' => array(
  188. ',' => t('Comma (,)'),
  189. '\t' => t('Tab (\t)'),
  190. ';' => t('Semicolon (;)'),
  191. ':' => t('Colon (:)'),
  192. '|' => t('Pipe (|)'),
  193. '.' => t('Period (.)'),
  194. ' ' => t('Space ( )'),
  195. ),
  196. );
  197. $form['advanced']['webform_export_wordwrap'] = array(
  198. '#type' => 'radios',
  199. '#title' => t('Export word-wrap'),
  200. '#options' => array(
  201. '0' => t('Only text containing return characters'),
  202. '1' => t('All text'),
  203. ),
  204. '#default_value' => webform_variable_get('webform_export_wordwrap'),
  205. '#description' => t('Some export formats, such as Microsoft Excel, support word-wrapped text cells.'),
  206. );
  207. $form['advanced']['webform_submission_access_control'] = array(
  208. '#type' => 'radios',
  209. '#title' => t('Submission access control'),
  210. '#options' => array(
  211. '1' => t('Select the user roles that may submit each individual webform'),
  212. '0' => t('Disable Webform submission access control'),
  213. ),
  214. '#default_value' => webform_variable_get('webform_submission_access_control'),
  215. '#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.'),
  216. );
  217. $form['advanced']['webform_token_access'] = array(
  218. '#type' => 'radios',
  219. '#title' => t('Token access'),
  220. '#options' => array(
  221. '1' => t('Allow tokens to be used in Webforms.'),
  222. '0' => t('Disable tokens in Webforms'),
  223. ),
  224. '#default_value' => webform_variable_get('webform_token_access'),
  225. '#description' => t('Tokens can be used to reveal sensitive information. Allow tokens if Webform creators are trusted.'),
  226. );
  227. $form['advanced']['webform_email_select_max'] = array(
  228. '#type' => 'textfield',
  229. '#title' => t("Select email mapping limit"),
  230. '#default_value' => webform_variable_get('webform_email_select_max'),
  231. '#description' => t('When mapping emails addresses to a select component, limit the choice to components with less than the amount of options indicated. This is to avoid flooding the email settings form.'),
  232. );
  233. $form['advanced']['webform_fieldset_wrap'] = array(
  234. '#type' => 'checkbox',
  235. '#title' => t('Use fieldsets for grouped components'),
  236. '#default_value' => webform_variable_get('webform_fieldset_wrap'),
  237. '#description' => t('Components containing multiple fields, such as checkboxes and radio buttons, will be wrapped in fieldsets. This improves the accessibility of webforms and helps them conform to web standards, but may require updates to the CSS of the active theme.'),
  238. );
  239. $form = system_settings_form($form);
  240. $form['#theme'] = 'webform_admin_settings';
  241. array_unshift($form['#submit'], 'webform_admin_settings_submit');
  242. return $form;
  243. }
  244. /**
  245. * Submit handler for the webform_admin_settings() form.
  246. */
  247. function webform_admin_settings_submit($form, &$form_state) {
  248. $disabled_components = array();
  249. foreach ($form_state['values']['components'] as $name => $enabled) {
  250. if (!$enabled) {
  251. $disabled_components[] = $name;
  252. }
  253. }
  254. // Update $form_state and let system_settings_form_submit() handle saving.
  255. $form_state['values']['webform_disabled_components'] = $disabled_components;
  256. unset($form_state['values']['components']);
  257. // Trim out empty options in the progress bar options.
  258. $form_state['values']['webform_progressbar_style'] = array_keys(array_filter($form_state['values']['webform_progressbar_style']));
  259. }
  260. /**
  261. * Theme the output of the webform_admin_settings() form.
  262. */
  263. function theme_webform_admin_settings($variables) {
  264. $form = $variables['form'];
  265. // Format the components into a table.
  266. foreach (element_children($form['components']) as $key) {
  267. $row = array();
  268. $row[] = $form['components'][$key]['#title'];
  269. $row[] = $form['components'][$key]['#description'];
  270. $form['components'][$key]['#title'] = NULL;
  271. $form['components'][$key]['#description'] = NULL;
  272. $row[] = array('data' => drupal_render($form['components'][$key]), 'align' => 'center');
  273. $rows[] = $row;
  274. }
  275. $header = array(t('Name'), t('Description'), array('data' => t('Enabled'), 'class' => array('checkbox')));
  276. // Create the table inside the form.
  277. $form['components']['table'] = array(
  278. '#theme' => 'table',
  279. '#header' => $header,
  280. '#rows' => $rows,
  281. );
  282. return drupal_render_children($form);
  283. }
  284. /**
  285. * Menu callback for admin/content/webform. Displays all webforms on the site.
  286. */
  287. function webform_admin_content() {
  288. // Determine whether views or hard-coded tables should be used for the
  289. // webforms table.
  290. if (!webform_variable_get('webform_table')) {
  291. $view = views_get_view('webform_webforms');
  292. return $view->preview('default');
  293. }
  294. $query = db_select('webform', 'w');
  295. $query->join('node', 'n', 'w.nid = n.nid');
  296. $query->fields('n');
  297. $nodes = $query->execute()->fetchAllAssoc('nid');
  298. return theme('webform_admin_content', array('nodes' => $nodes));
  299. }
  300. /**
  301. * Create a comma-separate list of content types that are webform enabled.
  302. */
  303. function webform_admin_type_list() {
  304. $webform_types = webform_node_types();
  305. $webform_type_list = '';
  306. $webform_type_count = count($webform_types);
  307. foreach ($webform_types as $n => $type) {
  308. $webform_type_list .= l(node_type_get_name($type), 'node/add/' . str_replace('_', '-', $type));
  309. if ($n + 1 < $webform_type_count) {
  310. $webform_type_list .= $webform_type_count == 2 ? ' ' : ', ';
  311. }
  312. if ($n + 2 == $webform_type_count) {
  313. $webform_type_list .= t('or') . ' ';
  314. }
  315. }
  316. return $webform_type_list;
  317. }
  318. /**
  319. * Generate a list of all webforms available on this site.
  320. */
  321. function theme_webform_admin_content($variables) {
  322. $nodes = $variables['nodes'];
  323. $header = array(
  324. t('Title'),
  325. array('data' => t('View'), 'colspan' => '4'),
  326. array('data' => t('Operations'), 'colspan' => '3'),
  327. );
  328. $rows = array();
  329. foreach ($nodes as $node) {
  330. $rows[] = array(
  331. l($node->title, 'node/' . $node->nid),
  332. l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
  333. l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
  334. l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
  335. l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
  336. node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
  337. node_access('update', $node) ? l(t('Components'), 'node/' . $node->nid . '/webform') : '',
  338. user_access('delete all webform submissions') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
  339. );
  340. }
  341. if (empty($rows)) {
  342. $webform_types = webform_node_types();
  343. if (empty($webform_types)) {
  344. $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/config/content/webform')));
  345. }
  346. else {
  347. $webform_type_list = webform_admin_type_list();
  348. $message = t('There are currently no webforms on your site. Create a !types piece of content.', array('!types' => $webform_type_list));
  349. }
  350. $rows[] = array(
  351. array('data' => $message, 'colspan' => 7),
  352. );
  353. }
  354. return theme('table', array('header' => $header, 'rows' => $rows));
  355. }