View source
<?php
function webform_help($section = 'admin/help#webform', $arg = NULL) {
$output = '';
switch ($section) {
case 'admin/settings/webform':
$output = t('Webforms are forms and questionnaires. To add one, select <a href="!url">Create content -> Webform</a>.', array(
'!url' => url('node/add/webform'),
));
break;
case 'admin/help#webform':
$output = t("<p>This module lets you create forms or questionnaires and define their content. Submissions from these forms are stored in the database and optionally also sent by e-mail to a predefined address.</p>\n <p>Here is how to create one:</p>\n <ul>\n <li>Go to Create Content and add a webform</li>\n <li>Add a description to be displayed as a teaser and above the actual form.</li>\n <li>Add a confirmation message or redirect node that is to be displayed after successful submission.</li>\n <li>Add one or more components to your form.</li>\n <li>Optionally add an e-mail address to which submissions will be sent. If no email address is specified, no e-mail will be sent when submissions are made through the form.</li>\n <li>Optionally select an e-mail (or hidden) component that will be used to populate the return e-mail address on any sent e-mail.</li>\n <li>Optionally select a textfield (or hidden) component that will be used to populate the subject e-mail field on any sent e-mail.</li>\n </ul>\n <p>Help on adding and configuring the components will be shown after you add your first component.</p>\n <p>The content of submitted forms is stored in the database table <i>webform_submitted_data</i> as key-value pairs.</p>\n ");
break;
case 'node/add#webform':
$output = t('A webform can be a questionnaires, contact or request forms. It can be used to let visitors make contact, register for a event or to enable a complex survey.');
break;
case 'node/%/edit/components':
$output .= '<p>' . t('This page displays all the components currently configured for this webform node. You may add any number of components to the form, even multiple of the same type. To add a new component, fill in a name and select a type from the fields at the bottom of the table. Submit the form to create the new component or update any changed form values.') . '</p>';
$output .= '<p>' . t('Click on any existing component\'s name to edit its settings.') . '</p>';
break;
}
if (strstr($section, 'admin/settings/webform#')) {
$components = webform_load_components(TRUE);
foreach ($components as $key => $component) {
$help_function = '_webform_help_' . $key;
if (function_exists($help_function)) {
$output .= $help_function($section);
}
}
}
return $output;
}
function webform_menu() {
$items = array();
$items['admin/content/webform'] = array(
'title' => 'Webforms',
'page callback' => 'webform_admin_content',
'access callback' => 'user_access',
'access arguments' => array(
'access webform results',
),
'description' => 'View and edit all the available webforms on your site.',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/webform'] = array(
'title' => 'Webform',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_admin_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer site configuration',
),
'description' => 'Global configuration of webform functionality.',
'type' => MENU_NORMAL_ITEM,
);
$items['node/%webform_menu/done'] = array(
'title' => 'Webform confirmation',
'page callback' => '_webform_confirmation',
'page arguments' => array(
1,
),
'access callback' => 'node_access',
'access arguments' => array(
'view',
1,
),
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/edit/configuration'] = array(
'title' => 'Configuration',
'page callback' => 'node_page_edit',
'page arguments' => array(
1,
),
'access callback' => 'node_access',
'access arguments' => array(
'update',
1,
),
'weight' => 1,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/edit/components'] = array(
'title' => 'Form components',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_components_form',
1,
),
'access callback' => 'node_access',
'access arguments' => array(
'update',
1,
),
'file' => 'webform_components.inc',
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/edit/components/%webform_menu_component'] = array(
'load arguments' => array(
1,
5,
),
'page arguments' => array(
'webform_component_edit_form',
1,
4,
FALSE,
),
'access callback' => 'node_access',
'access arguments' => array(
'update',
1,
),
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/edit/components/%webform_menu_component/clone'] = array(
'load arguments' => array(
1,
5,
),
'page arguments' => array(
'webform_component_edit_form',
1,
4,
TRUE,
),
'access callback' => 'node_access',
'access arguments' => array(
'update',
1,
),
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/edit/components/%webform_menu_component/delete'] = array(
'load arguments' => array(
1,
5,
),
'page arguments' => array(
'webform_component_delete_form',
1,
4,
),
'access callback' => 'node_access',
'access arguments' => array(
'update',
1,
),
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results'] = array(
'title' => 'Results',
'page callback' => 'webform_results_submissions',
'page arguments' => array(
1,
FALSE,
'50',
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'access webform results',
),
'file' => 'webform_report.inc',
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/submissions'] = array(
'title' => 'Submissions',
'page callback' => 'webform_results_submissions',
'page arguments' => array(
1,
FALSE,
'50',
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'access webform results',
),
'file' => 'webform_report.inc',
'weight' => 4,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/analysis'] = array(
'title' => 'Analysis',
'page callback' => 'webform_results_analysis',
'page arguments' => array(
1,
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'access webform results',
),
'file' => 'webform_report.inc',
'weight' => 5,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/table'] = array(
'title' => 'Table',
'page callback' => 'webform_results_table',
'page arguments' => array(
1,
'50',
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'access webform results',
),
'file' => 'webform_report.inc',
'weight' => 6,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/download'] = array(
'title' => 'Download',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_results_download_form',
1,
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'access webform results',
),
'file' => 'webform_report.inc',
'weight' => 7,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/clear'] = array(
'title' => 'Clear',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_results_clear_form',
1,
),
'access callback' => 'webform_results_access',
'access arguments' => array(
1,
'clear webform results',
),
'file' => 'webform_report.inc',
'weight' => 8,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/submissions'] = array(
'title' => 'Submissions',
'page callback' => 'webform_results_submissions',
'page arguments' => array(
1,
TRUE,
'50',
),
'access callback' => 'webform_submission_access',
'access arguments' => array(
1,
NULL,
'list',
),
'file' => 'webform_report.inc',
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/submission/%webform_menu_submission'] = array(
'title' => 'Webform submission',
'load arguments' => array(
1,
),
'page callback' => 'webform_client_form_load',
'page arguments' => array(
1,
3,
FALSE,
FALSE,
),
'access callback' => 'webform_submission_access',
'access arguments' => array(
1,
3,
'view',
),
'type' => MENU_CALLBACK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/view'] = array(
'title' => 'View',
'load arguments' => array(
1,
),
'page callback' => 'webform_client_form_load',
'page arguments' => array(
1,
3,
FALSE,
FALSE,
),
'access callback' => 'webform_submission_access',
'access arguments' => array(
1,
3,
'view',
),
'weight' => 0,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/edit'] = array(
'title' => 'Edit',
'load arguments' => array(
1,
),
'page callback' => 'webform_client_form_load',
'page arguments' => array(
1,
3,
TRUE,
FALSE,
),
'access callback' => 'webform_submission_access',
'access arguments' => array(
1,
3,
'edit',
),
'weight' => 1,
'type' => MENU_LOCAL_TASK,
);
$items['node/%webform_menu/submission/%webform_menu_submission/delete'] = array(
'title' => 'Delete',
'load arguments' => array(
1,
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'webform_submission_delete_form',
1,
3,
),
'access callback' => 'webform_submission_access',
'access arguments' => array(
1,
3,
'delete',
),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function webform_menu_load($nid) {
if (!is_numeric($nid)) {
return FALSE;
}
$node = node_load($nid);
if (!isset($node->type) || $node->type != 'webform') {
return FALSE;
}
return $node;
}
function webform_menu_submission_load($sid, $nid) {
module_load_include('inc', 'webform', 'webform_submissions');
$submission = webform_get_submission($nid, $sid);
return empty($submission) ? FALSE : $submission;
}
function webform_menu_component_load($cid, $nid, $type) {
module_load_include('inc', 'webform', 'webform_components');
if ($cid == 'new') {
$components = webform_load_components();
$component = in_array($type, array_keys($components)) ? array(
'type' => $type,
'name' => $_GET['name'],
'mandatory' => $_GET['mandatory'],
'email' => $_GET['email'],
'pid' => $_GET['pid'],
'weight' => $_GET['weight'],
) : FALSE;
}
else {
$node = node_load($nid);
$component = isset($node->webform['components'][$cid]) ? $node->webform['components'][$cid] : FALSE;
}
webform_component_defaults($component);
return $component;
}
function webform_submission_access($node, $submission, $op = 'view', $account = NULL) {
global $user;
$account = isset($account) ? $account : $user;
switch ($op) {
case 'view':
return user_access('access webform results') || user_access('access own webform submissions') && $account->uid == $submission->uid;
case 'edit':
return user_access('edit webform submissions') || user_access('edit own webform submissions') && $account->uid == $submission->uid;
case 'delete':
return user_access('edit webform submissions') || user_access('edit own webform submissions') && $account->uid == $submission->uid || user_access('clear webform results');
case 'list':
return user_access('access webform results') || user_access('access webform submissions') || user_access('access own webform submissions') && $user->uid;
}
}
function webform_results_access($node, $perm) {
return node_access('view', $node) && user_access($perm);
}
function webform_perm() {
return array(
'create webforms',
'edit own webforms',
'edit webforms',
'access webform results',
'clear webform results',
'access own webform submissions',
'edit own webform submissions',
'edit webform submissions',
'use PHP for additional processing',
);
}
function webform_theme() {
$theme = array(
'webform_view' => array(
'arguments' => array(
'node' => NULL,
'teaser' => NULL,
'page' => NULL,
'form' => NULL,
'enabled' => NULL,
),
),
'webform_view_messages' => array(
'arguments' => array(
'node' => NULL,
'teaser' => NULL,
'page' => NULL,
'submission_count' => NULL,
'limit_exceeded' => NULL,
'allowed_roles' => NULL,
),
),
'webform_form' => array(
'arguments' => array(
'form' => NULL,
),
'template' => 'webform-form',
'pattern' => 'webform_form_[0-9]+',
),
'webform_mail_components_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'webform_mail_settings_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'webform_advanced_submit_limit_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'webform_admin_settings' => array(
'arguments' => array(
'form' => NULL,
),
),
'webform_confirmation' => array(
'arguments' => array(
'node' => NULL,
'sid' => NULL,
),
'template' => 'webform-confirmation',
'pattern' => 'webform_confirmation_[0-9]+',
),
'webform_mail_message' => array(
'arguments' => array(
'form_values' => NULL,
'node' => NULL,
'sid' => NULL,
'cid' => NULL,
),
'template' => 'webform-mail',
'pattern' => 'webform_mail(_[0-9]+)?',
),
'webform_mail_fields' => array(
'arguments' => array(
'cid' => NULL,
'value' => NULL,
'node' => NULL,
'indent' => NULL,
),
),
'webform_mail_headers' => array(
'arguments' => array(
'form_values' => NULL,
'node' => NULL,
'sid' => NULL,
'cid' => NULL,
),
'pattern' => 'webform_mail_headers_[0-9]+',
),
'webform_admin_content' => array(
'arguments' => array(
'nodes' => NULL,
),
),
'webform_token_help' => array(
'arguments' => array(),
),
'webform_components_form' => array(
'arguments' => array(
'form' => NULL,
),
),
'webform_results_per_page' => array(
'arguments' => array(
'total_count' => NULL,
'pager_count' => NULL,
),
),
'webform_results_submissions_header' => array(
'arguments' => array(
'node' => NULL,
),
),
'webform_results_submissions' => array(
'arguments' => array(
'node' => NULL,
'submissions' => NULL,
'total_count' => NULL,
'pager_count' => NULL,
),
),
'webform_results_table_header' => array(
'arguments' => array(
'node' => NULL,
),
),
'webform_results_table' => array(
'arguments' => array(
'node' => NULL,
'components' => NULL,
'submissions' => NULL,
'node' => NULL,
'total_count' => NULL,
'pager_count' => NULL,
),
),
);
$components = webform_load_components(TRUE);
foreach ($components as $key => $component) {
$theme_hook = '_webform_theme_' . $key;
if (function_exists($theme_hook)) {
$theme = array_merge($theme, $theme_hook());
}
}
return $theme;
}
function webform_node_info() {
return array(
'webform' => array(
'name' => t('Webform'),
'module' => 'webform',
'description' => t('Create a new form or questionnaire accessible to users. Submission results and statistics are recorded and accessible to privileged users.'),
),
);
}
function webform_access($op, $node, $account) {
switch ($op) {
case 'create':
return user_access('create webforms', $account);
case 'update':
case 'delete':
if (user_access('edit webforms', $account) || user_access('edit own webforms', $account) && $account->uid == $node->uid) {
return TRUE;
}
}
}
function webform_forms($form_id) {
$forms = array();
if (strpos($form_id, 'webform_client_form_') === 0) {
$forms[$form_id]['callback'] = 'webform_client_form';
}
return $forms;
}
function webform_file_download($file) {
$file = file_check_location(file_directory_path() . '/' . $file, file_directory_path() . '/webform/');
if ($file && user_access('access webform results')) {
$info = image_get_info(file_create_path($file));
if (isset($info['mime_type'])) {
$headers = array(
'Content-type: ' . $info['mime_type'],
);
}
else {
$headers = array(
'Content-type: force-download',
'Content-disposition: attachment',
);
}
return $headers;
}
}
function webform_insert($node) {
module_load_include('inc', 'webform', 'webform_components');
if (isset($node->op) && $node->op == $node->submit) {
webform_submit($node);
}
db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit']);
if (isset($node->webform['components']) && !empty($node->webform['components'])) {
foreach ($node->webform['components'] as $cid => $component) {
$component['nid'] = $node->nid;
webform_component_insert($component);
}
}
foreach ($node->webform['roles'] as $rid) {
db_query('INSERT INTO {webform_roles} (nid, rid) VALUES (%d, %d)', $node->nid, $rid);
}
}
function webform_update($node) {
db_query('DELETE FROM {webform} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_component} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_roles} WHERE nid = %d', $node->nid);
webform_insert($node);
}
function webform_delete(&$node) {
module_load_include('inc', 'webform', 'webform_components');
foreach ($node->webform['components'] as $cid => $component) {
webform_component_delete($node->nid, $cid);
}
db_query('DELETE FROM {webform} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_component} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_roles} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_submissions} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_submitted_data} WHERE nid = %d', $node->nid);
}
function webform_load($node) {
module_load_include('inc', 'webform', 'webform_components');
$additions = new stdClass();
if ($webform = db_fetch_array(db_query('SELECT * FROM {webform} WHERE nid = %d', $node->nid))) {
$additions->webform = $webform;
$additions->webform['roles'] = array();
$result = db_query('SELECT rid FROM {webform_roles} WHERE nid = %d', $node->nid);
while ($role = db_fetch_object($result)) {
$additions->webform['roles'][] = $role->rid;
}
}
else {
$additions->webform = array(
'confirmation' => '',
'teaser' => 0,
'submit_text' => '',
'submit_limit' => -1,
'submit_interval' => -1,
'email' => '',
'email_from_name' => 'default',
'email_from_address' => 'default',
'email_subject' => 'default',
'additional_validate' => '',
'additional_submit' => '',
'roles' => array(
1,
2,
),
);
}
$additions->webform['components'] = array();
$additions->webform['additional_emails'] = array();
$result = db_query('SELECT * FROM {webform_component} WHERE nid = %d ORDER BY weight, name', $node->nid);
while ($c = db_fetch_array($result)) {
$component =& $additions->webform['components'][$c['cid']];
$component['nid'] = $node->nid;
$component['cid'] = $c['cid'];
$component['form_key'] = $c['form_key'] ? $c['form_key'] : $c['cid'];
$component['name'] = t($c['name']);
$component['type'] = $c['type'];
$component['value'] = $c['value'];
$component['extra'] = unserialize($c['extra']);
$component['mandatory'] = $c['mandatory'];
$component['email'] = $c['email'];
$component['pid'] = $c['pid'];
$component['weight'] = $c['weight'];
if (isset($component['extra']['email']) && $component['extra']['email']) {
$additions->webform['additional_emails'][$c['cid']] = $c['cid'];
}
webform_component_defaults($component);
}
if (!empty($additions->webform['components'])) {
$component_tree = array();
$page_count = 1;
_webform_components_tree_build($additions->webform['components'], $component_tree, 0, $page_count);
$additions->webform['components'] = _webform_components_tree_flatten($component_tree['children']);
}
return $additions;
}
function webform_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if (isset($node->type) && $node->type === 'webform') {
if ($teaser && !$node->webform['teaser']) {
$links['webform_goto'] = array(
'title' => t('Go to form'),
'href' => 'node/' . $node->nid,
'attributes' => array(
'title' => t('View this form.'),
'class' => 'read-more',
),
);
}
}
return $links;
}
function webform_form(&$node, &$param) {
$form['webform'] = array(
'#type' => 'markup',
'#tree' => TRUE,
);
if (!isset($node->nid) && !isset($node->webform)) {
$node->nid = 0;
$additions = webform_load($node);
$node->webform = $additions->webform;
$node->nid = NULL;
}
if (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW && $node->webform['enforce_limit'] == 'no') {
$node->webform['submit_limit'] = -1;
}
$form['webform']['components'] = array(
'#type' => 'value',
'#value' => $node->webform['components'],
);
$form['webform']['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Webform Settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -4,
'#parents' => array(
'webform',
),
);
$form['webform']['settings']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $node->title,
'#maxlength' => 128,
'#required' => TRUE,
'#tree' => FALSE,
);
$form['webform']['settings']['body'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('Text to be shown as teaser and before the form.'),
'#default_value' => $node->body,
'#cols' => 40,
'#rows' => 10,
'#tree' => FALSE,
);
$form['webform']['settings']['confirmation'] = array(
'#type' => 'textarea',
'#title' => t('Confirmation message or redirect URL'),
'#description' => t('Message to be shown upon successful submission or a path to a redirect page. Preface message with <em>message:</em> for a simple message that does not require a page refresh. Redirect pages must start with <em>http://</em> for external sites or <em>internal:</em> for an internal path. i.e. <em>http://www.example.com</em> or <em>internal:node/10</em>'),
'#default_value' => $node->webform['confirmation'],
'#cols' => 40,
'#rows' => 10,
);
$form['webform']['settings']['format'] = filter_form($node->format);
$form['webform']['role_control'] = array(
'#type' => 'fieldset',
'#title' => t('Webform access control'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -3,
'#parents' => array(
'webform',
),
'#description' => t('These permissions affect which roles can submit this webform. It does not prevent access to the webform page. If needing to prevent access to the webform page entirely, use a content access module such as <a href="http://drupal.org/project/taxonomy_access">Taxonomy Access</a> or <a href="http://drupal.org/project/node_privacy_byrole">Node Privacy by Role</a>.'),
'#access' => variable_get('webform_submission_access_control', 1),
);
$user_roles = user_roles();
$form['webform']['role_control']['roles'] = array(
'#default_value' => $node->webform['roles'],
'#options' => $user_roles,
'#type' => 'checkboxes',
'#title' => t('Roles that can submit this webform'),
'#description' => t('Uncheck all roles to prevent new submissions. The %authenticated role applies to any user signed into the site, regardless of other assigned roles.', array(
'%authenticated' => $user_roles[2],
)),
);
$form['webform']['mail_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Webform mail settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -2,
'#parents' => array(
'webform',
),
'#theme' => 'webform_mail_settings_form',
);
$form['webform']['mail_settings']['email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail to address'),
'#maxlength' => 255,
'#default_value' => $node->webform['email'],
'#description' => t('Form submissions will be e-mailed to this address. Leave blank for none. Multiple e-mail addresses may be separated by commas.'),
);
$form['webform']['mail_settings']['email_components'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#theme' => 'webform_mail_components_form',
'#title' => t('Conditional e-mail recipients'),
'#description' => t('The settings below allow you to send e-mails to multiple recipients based off the value of a component.'),
'#node' => $node,
);
$options = _webform_component_options($node->webform['components'], 'email');
$default_value = array();
if (is_array($node->webform['components'])) {
foreach ($node->webform['components'] as $cid => $component) {
if (isset($component['extra']['email']) && $component['extra']['email']) {
$default_value[] = $cid;
}
}
}
$form['webform']['mail_settings']['email_components']['email_components'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
'#parents' => array(
'webform',
'email_components',
),
);
foreach (array(
'from_name',
'from_address',
'subject',
) as $field) {
switch ($field) {
case 'from_name':
$default_value = webform_variable_get('webform_default_from_name');
$title = t('E-mail from name');
$description = t('After adding components to this form any email, select, or hidden form element may be selected as the sender\'s name for e-mails.');
break;
case 'from_address':
$default_value = webform_variable_get('webform_default_from_address');
$title = t('E-mail from address');
$description = t('After adding components to this form any textfield, select, or hidden form element may be selected as the sender\'s e-mail address.');
break;
case 'subject':
$default_value = webform_variable_get('webform_default_subject');
$title = t('E-mail subject');
$description = t('After adding components to this form any textfield, select, or hidden form element may be selected as the subject for e-mails.');
break;
}
$form['webform']['mail_settings']['email_' . $field . '_option'] = array(
'#title' => $title,
'#type' => 'radios',
'#default_value' => is_numeric($node->webform['email_' . $field]) ? 'component' : (empty($default_value) || $node->webform['email_' . $field] != 'default' && isset($node->webform['email_' . $field]) ? 'custom' : 'default'),
'#description' => $description,
);
if (!empty($default_value)) {
$form['webform']['mail_settings']['email_' . $field . '_option']['#options']['default'] = $default_value;
}
$form['webform']['mail_settings']['email_' . $field . '_option']['#options']['custom'] = 'custom';
$form['webform']['mail_settings']['email_' . $field . '_option']['#options']['component'] = 'component';
$form['webform']['mail_settings']['email_' . $field . '_custom'] = array(
'#type' => 'textfield',
'#size' => 40,
'#default_value' => !is_numeric($node->webform['email_' . $field]) && $node->webform['email_' . $field] != 'default' ? $node->webform['email_' . $field] : NULL,
);
$options = _webform_component_options($node->webform['components'], $field == 'from_address' ? 'email' : 'string');
$form['webform']['mail_settings']['email_' . $field . '_component'] = array(
'#type' => 'select',
'#default_value' => is_numeric($node->webform['email_' . $field]) ? $node->webform['email_' . $field] : NULL,
'#options' => empty($options) ? array(
'' => t('No available components'),
) : $options,
'#disabled' => empty($options) ? TRUE : FALSE,
'#weight' => 6,
);
}
$form['webform']['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Webform advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -1,
'#parents' => array(
'webform',
),
);
$form['webform']['advanced']['teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Show complete form in teaser'),
'#default_value' => $node->webform['teaser'],
'#description' => t('Display the entire form in the teaser display of this node.'),
);
$form['webform']['advanced']['submit_limit'] = array(
'#type' => 'fieldset',
'#title' => t('Limit the number of submissions a user may send within a specified time period'),
'#theme' => 'webform_advanced_submit_limit_form',
);
$form['webform']['advanced']['submit_limit']['enforce_limit'] = array(
'#type' => 'radios',
'#options' => array(
'no' => t('Unlimited'),
'yes' => 'Limit to !count submission(s) !timespan',
),
'#default_value' => $node->webform['submit_limit'] == -1 ? 'no' : 'yes',
'#parents' => array(
'webform',
'enforce_limit',
),
);
$form['webform']['advanced']['submit_limit']['submit_limit'] = array(
'#type' => 'textfield',
'#maxlength' => 2,
'#size' => 2,
'#default_value' => $node->webform['submit_limit'] != -1 ? $node->webform['submit_limit'] : '',
'#parents' => array(
'webform',
'submit_limit',
),
);
$form['webform']['advanced']['submit_limit']['submit_interval'] = array(
'#type' => 'select',
'#options' => array(
'-1' => t('ever'),
'3600' => t('every hour'),
'86400' => t('every day'),
'604800' => t('every week'),
),
'#default_value' => $node->webform['submit_interval'],
'#parents' => array(
'webform',
'submit_interval',
),
);
$form['webform']['advanced']['submit_text'] = array(
'#type' => 'textfield',
'#title' => t('Submit button text'),
'#default_value' => $node->webform['submit_text'],
'#description' => t('By default the submit button on this form will have the label <em>Submit</em>. Enter a new title here to override the default.'),
);
if (user_access('use PHP for additional processing')) {
$form['webform']['advanced']['additional_validate'] = array(
'#type' => 'textarea',
'#title' => t('Additional Validation'),
'#description' => t('Enter PHP code to perform additional validation for this form. Include the <?php ?> tags. $form and $form_state are available variables. If validation fails, use the form_set_error function to prevent the form from being submitted. Use the same syntax as a _validate function used in the <a href="http://api.drupal.org/api/file/developer/topics/forms_api.html">Forms API</a>.'),
'#default_value' => $node->webform['additional_validate'],
'#cols' => 40,
'#rows' => 10,
);
$form['webform']['advanced']['additional_submit'] = array(
'#type' => 'textarea',
'#title' => t('Additional Processing'),
'#description' => t('Enter PHP code to perform additional processing for this form (after the validation). Include the <?php ?> tags. $form and $form_state are available variables, use the same syntax as a _submit function used in the <a href="http://api.drupal.org/api/file/developer/topics/forms_api.html">Forms API</a>.'),
'#default_value' => $node->webform['additional_submit'],
'#cols' => 40,
'#rows' => 10,
);
}
else {
$form['webform']['advanced']['additional_validate'] = array(
'#type' => 'value',
'#value' => $node->webform['additional_validate'],
);
$form['webform']['advanced']['additional_submit'] = array(
'#type' => 'value',
'#value' => $node->webform['additional_submit'],
);
}
return $form;
}
function webform_content_extra_fields($type_name) {
$extra = array();
if ($type_name == 'webform') {
$extra['webform'] = array(
'label' => t('Webform'),
'description' => t('Webform settings and display.'),
'weight' => 1,
);
}
return $extra;
}
function theme_webform_mail_components_form($form) {
drupal_add_css(drupal_get_path('module', 'webform') . '/webform.css');
$node = $form['#node'];
$header = array(
array(
'data' => t('To'),
'class' => 'webform-checkbox',
),
t('Name'),
t('Type'),
);
$rows = array();
foreach (element_children($form['email_components']) as $cid) {
$title = $form['email_components'][$cid]['#title'];
unset($form['email_components'][$cid]['#title']);
$rows[] = array(
array(
'data' => drupal_render($form['email_components'][$cid]),
'class' => 'webform-checkbox',
),
$title,
$node->webform['components'][$cid]['type'],
);
}
if (empty($rows)) {
$rows[] = array(
array(
'colspan' => 5,
'data' => t('No components yet in this webform.'),
),
);
}
$form['#children'] = theme('table', $header, $rows);
return drupal_render($form);
}
function theme_webform_mail_settings_form($form) {
drupal_add_js(drupal_get_path('module', 'webform') . '/webform.js');
foreach (array(
'from_name',
'from_address',
'subject',
) as $field) {
foreach (array(
'custom' => t('Custom'),
'component' => t('Component'),
) as $option => $title) {
$form['email_' . $field . '_' . $option]['#attributes']['class'] = 'webform-set-active';
$form['email_' . $field . '_option'][$option]['#title'] = $title . ': ' . drupal_render($form['email_' . $field . '_' . $option]);
}
foreach (element_children($form['email_' . $field . '_option']) as $option) {
$form['email_' . $field . '_option'][$option]['#prefix'] = '<div class="container-inline">';
$form['email_' . $field . '_option'][$option]['#suffix'] = '</div>';
}
if (isset($form['email_' . $field . '_option']['#options']['default'])) {
$form['email_' . $field . '_option']['default']['#title'] = t('Default') . ': ' . theme('placeholder', $form['email_' . $field . '_option']['default']['#title']);
}
}
return drupal_render($form);
}
function theme_webform_advanced_submit_limit_form($form) {
$form['submit_limit']['#attributes']['class'] = 'webform-set-active';
$form['submit_interval']['#attributes']['class'] = 'webform-set-active';
$replacements = array(
'!count' => drupal_render($form['submit_limit']),
'!timespan' => drupal_render($form['submit_interval']),
);
$form['enforce_limit']['no']['#prefix'] = '<div class="container-inline">';
$form['enforce_limit']['no']['#suffix'] = '</div>';
$form['enforce_limit']['yes']['#prefix'] = '<div class="container-inline">';
$form['enforce_limit']['yes']['#suffix'] = '</div>';
$form['enforce_limit']['yes']['#title'] = t('Limit to !count submission(s) !timespan', $replacements);
return drupal_render($form);
}
function webform_validate(&$node) {
if (!empty($node->webform['email'])) {
$emails = explode(',', $node->webform['email']);
foreach ($emails as $email) {
if (!valid_email_address(trim($email))) {
form_set_error('webform][email', t('The entered email address %address is not a valid address.', array(
'%address' => $email,
)));
break;
}
}
}
if ($node->webform['email_from_address_option'] == 'custom') {
if (!valid_email_address($node->webform['email_from_address_custom'])) {
form_set_error('webform][email_from_address_custom', t('The entered email address %address is not a valid address.', array(
'%address' => $node->webform['email_from_address_custom'],
)));
}
}
}
function webform_submit(&$node) {
if (empty($node->is_new)) {
$original_node = node_load($node->nid);
foreach ($original_node->webform['components'] as $cid => $component) {
if (!isset($node->webform['components'][$cid])) {
$node->webform['components'][$cid] = $component;
}
if (isset($node->webform['email_components'][$cid])) {
$node->webform['components'][$cid]['extra']['email'] = $node->webform['email_components'][$cid];
}
}
}
unset($node->webform['email_components']);
foreach (array(
'from_name',
'from_address',
'subject',
) as $field) {
$option = $node->webform['email_' . $field . '_option'];
if ($option == 'default') {
$node->webform['email_' . $field] = 'default';
}
else {
$node->webform['email_' . $field] = $node->webform['email_' . $field . '_' . $option];
}
unset($node->webform['email_' . $field . '_option']);
unset($node->webform['email_' . $field . '_component']);
unset($node->webform['email_' . $field . '_custom']);
}
if ($node->webform['enforce_limit'] == 'no') {
$node->webform['submit_limit'] = -1;
$node->webform['submit_interval'] = -1;
}
unset($node->webform['enforce_limit']);
$node->webform['roles'] = array_keys(array_filter($node->webform['roles']));
}
function webform_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'webform_node_form' && empty($form['nid']['#value'])) {
$form['buttons']['submit']['#submit'][] = 'webform_form_submit';
if (user_access('administer nodes')) {
$form['options']['status']['#default_value'] = FALSE;
}
else {
$form['status']['#value'] = FALSE;
}
}
}
function webform_form_submit($form, &$form_state) {
$nid = $form_state['nid'];
unset($_SESSION['messages']['status']);
drupal_set_message(t('The new webform %title has been created. Add new fields to your webform with the form below.', array(
'%title' => $form_state['values']['title'],
)));
if (!$form_state['values']['status']) {
drupal_set_message(t('This webform is currently unpublished. After finishing your changes to the webform, use the <em>Publish</em> button below.'));
}
$form_state['redirect'] = 'node/' . $nid . '/edit/components';
}
function webform_view(&$node, $teaser = 0, $page = 0) {
global $user;
if ($teaser && !$node->webform['teaser']) {
$node->content['teaser'] = array(
'#value' => check_markup($node->teaser, $node->format, FALSE),
);
return $node;
}
$submission = array();
$submission_count = 0;
$enabled = TRUE;
$preview = FALSE;
$logging_in = FALSE;
$limit_exceeded = FALSE;
if ($node->build_mode == NODE_BUILD_PREVIEW) {
$preview = TRUE;
$additions = webform_load($node);
$node->webform['components'] = $additions->webform['components'];
}
if (isset($_POST['op']) && isset($_POST['name']) && isset($_POST['pass'])) {
$logging_in = TRUE;
}
if (variable_get('webform_submission_access_control', 1)) {
$allowed_roles = array();
foreach ($node->webform['roles'] as $rid) {
$allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
}
if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
$enabled = FALSE;
}
}
else {
$allowed_roles = array_keys(user_roles());
}
if ($node->webform['submit_limit'] != -1) {
module_load_include('inc', 'webform', 'webform_submissions');
if (($limit_exceeded = _webform_submission_limit_check($node)) && ($user->uid != 0 || variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED)) {
$enabled = FALSE;
}
}
if ($user->uid && (user_access('access own webform submissions') || user_access('access webform results') || user_access('access webform submissions'))) {
$submission_count = db_result(db_query('SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
}
$form = drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $enabled, $preview);
$output = theme('webform_view', $node, $teaser, $page, $form, $enabled);
if ($preview) {
$output = preg_replace('/<\\/?form[^>]*>/', '', $output);
}
if ($node->build_mode != NODE_BUILD_PREVIEW && !$logging_in && ($user->uid != 0 || !variable_get('cache', CACHE_DISABLED))) {
theme('webform_view_messages', $node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles);
}
$node = node_prepare($node, $teaser);
if (isset($output)) {
$node->content['webform'] = array(
'#value' => $output,
'#weight' => 1,
);
}
return $node;
}
function theme_webform_view($node, $teaser, $page, $form, $enabled) {
if ($enabled) {
return $form;
}
}
function theme_webform_view_messages($node, $teaser, $page, $submission_count, $limit_exceeded, $allowed_roles) {
global $user;
$type = 'notice';
if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
if (empty($allowed_roles)) {
$message = t('Submissions for this form are closed.');
}
elseif (isset($allowed_roles[2])) {
$login = url('user/login', array(
'query' => drupal_get_destination(),
));
$register = url('user/register', array(
'query' => drupal_get_destination(),
));
if (variable_get('user_register', 1) == 0) {
$message = t('You must <a href="!login">login</a> to view this form.', array(
'!login' => $login,
));
}
else {
$message = t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array(
'!login' => $login,
'!register' => $register,
));
}
}
else {
$message = t('You do not have permission to view this form.');
}
}
elseif ($limit_exceeded) {
if ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] > 1) {
$message = t('You have submitted this form the maximum number of times (@count).', array(
'@count' => $node->webform['submit_limit'],
));
}
elseif ($node->webform['submit_interval'] == -1 && $node->webform['submit_limit'] == 1) {
$message = t('You have already submitted this form.');
}
else {
$message = t('You may not submit another entry at this time.');
}
$type = 'error';
}
if ($submission_count > 0) {
if (empty($message)) {
$message = t('You have already submitted this form.') . ' ' . t('<a href="!url">View your previous submissions</a>.', array(
'!url' => url('node/' . $node->nid . '/submissions'),
));
}
else {
$message .= ' ' . t('<a href="!url">View your previous submissions</a>.', array(
'!url' => url('node/' . $node->nid . '/submissions'),
));
}
}
if ($page && isset($message)) {
drupal_set_message($message, $type);
}
}
function webform_mail($key, &$message, $params) {
$message['headers'] = array_merge($message['headers'], $params['headers']);
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
}
function webform_admin_settings() {
module_load_include('inc', 'webform', 'webform_export');
$form['components'] = array(
'#type' => 'fieldset',
'#title' => t('Available components'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#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.'),
);
$component_types = webform_load_components(TRUE);
foreach ($component_types as $key => $component) {
$form['components']['webform_enable_' . $key] = array(
'#title' => $component,
'#description' => module_invoke('webform', 'help', 'admin/settings/webform#' . $key . '_description'),
'#type' => 'checkbox',
'#checked_value' => 1,
'#default_value' => variable_get('webform_enable_' . $key, 1),
);
}
$form['email'] = array(
'#type' => 'fieldset',
'#title' => t('Default e-mail values'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['email']['webform_default_from_address'] = array(
'#type' => 'textfield',
'#title' => t('From address'),
'#default_value' => variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from'))),
'#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
);
$form['email']['webform_default_from_name'] = array(
'#type' => 'textfield',
'#title' => t('From name'),
'#default_value' => variable_get('webform_default_from_name', variable_get('site_name', '')),
'#description' => t('The default sender name which is used along with the default from address.'),
);
$form['email']['webform_default_subject'] = array(
'#type' => 'textfield',
'#title' => t('Default subject'),
'#default_value' => variable_get('webform_default_subject', t('Form submission from: %title')),
'#description' => t('The default subject line of any e-mailed results.'),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['webform_use_cookies'] = array(
'#type' => 'checkbox',
'#checked_value' => 1,
'#title' => t('Allow cookies for tracking submissions'),
'#default_value' => variable_get('webform_use_cookies', 0),
'#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.'),
);
$form['advanced']['webform_export_format'] = array(
'#type' => 'radios',
'#title' => t('Default export format'),
'#options' => webform_export_list(),
'#default_value' => variable_get('webform_export_format', 'delimited'),
);
$form['advanced']['webform_csv_delimiter'] = array(
'#type' => 'select',
'#title' => t('Default export delimiter'),
'#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.'),
'#default_value' => variable_get('webform_csv_delimiter', '\\t'),
'#options' => array(
',' => t('Comma (,)'),
'\\t' => t('Tab (\\t)'),
';' => t('Semicolon (;)'),
':' => t('Colon (:)'),
'|' => t('Pipe (|)'),
'.' => t('Period (.)'),
' ' => t('Space ( )'),
),
);
$form['advanced']['webform_submission_access_control'] = array(
'#type' => 'radios',
'#title' => t('Submission access control'),
'#options' => array(
'1' => t('Select the user roles that may submit each individual webform'),
'0' => t('Disable Webform submission access control'),
),
'#default_value' => variable_get('webform_submission_access_control', 1),
'#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.'),
);
$form['advanced']['webform_debug'] = array(
'#type' => 'select',
'#title' => t('Webforms debug'),
'#default_value' => variable_get('webform_debug', 0),
'#options' => array(
0 => t('Off'),
1 => t('Log submissions'),
2 => t('Full debug'),
),
'#description' => t('Set to "Log submissions" to log all submissions in the watchdog. Set to "Full debug" to print debug info on submission.'),
);
$form = system_settings_form($form);
$form['#theme'] = 'webform_admin_settings';
return $form;
}
function theme_webform_admin_settings($form) {
foreach (element_children($form['components']) as $key) {
$row = array();
$row[] = $form['components'][$key]['#title'];
$row[] = $form['components'][$key]['#description'];
unset($form['components'][$key]['#title']);
unset($form['components'][$key]['#description']);
$row[] = array(
'data' => drupal_render($form['components'][$key]),
'align' => 'center',
);
$rows[] = $row;
}
$header = array(
t('Name'),
t('Description'),
t('Enabled'),
);
$form['components']['table'] = array(
'#value' => theme('table', $header, $rows),
);
$output = drupal_render($form);
return $output;
}
function webform_client_form_load($node, $submission, $enabled, $preview) {
return drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $enabled, $preview);
}
function webform_client_form(&$form_state, $node, $submission, $enabled = FALSE, $preview = FALSE) {
module_load_include('inc', 'webform', 'webform_components');
webform_load_components();
if (isset($submission->sid)) {
drupal_set_title(t('Submission #@sid', array(
'@sid' => $submission->sid,
)));
}
if ($submission && user_access('access webform results')) {
drupal_add_css(drupal_get_path('module', 'webform') . '/webform.css', 'module', 'all', FALSE);
$previous = db_result(db_query('SELECT MAX(sid) FROM {webform_submissions} WHERE nid = %d AND sid < %d', array(
$node->nid,
$submission->sid,
)));
$next = db_result(db_query('SELECT MIN(sid) FROM {webform_submissions} WHERE nid = %d AND sid > %d', array(
$node->nid,
$submission->sid,
)));
$form['submission'] = array(
'#type' => 'value',
'#value' => $submission,
);
$form['navigation'] = array(
'#prefix' => '<div class="webform-submission-navigation">',
'#suffix' => '</div>',
);
$form['navigation']['previous'] = array(
'#value' => $previous ? l(t('Previous submission'), 'node/' . $node->nid . '/submission/' . $previous . ($enabled ? '/edit' : ''), array(
'attributes' => array(
'class' => 'webform-submission-previous',
),
'query' => $enabled ? 'destination=node/' . $node->nid . '/submission/' . $previous . '/edit' : NULL,
)) : '<span class="webform-submission-previous">' . t('Previous submission') . '</span>',
);
$form['navigation']['next'] = array(
'#value' => $next ? l(t('Next submission'), 'node/' . $node->nid . '/submission/' . $next . ($enabled ? '/edit' : ''), array(
'attributes' => array(
'class' => 'webform-submission-next',
),
'query' => $enabled ? 'destination=node/' . $node->nid . '/submission/' . $next . '/edit' : NULL,
)) : '<span class="webform-submission-next">' . t('Next submission') . '</span>',
);
$form['submission_info'] = array(
'#title' => t('Submission Information'),
'#type' => 'fieldset',
'#collapsible' => FALSE,
);
$account = user_load(array(
'uid' => $submission->uid,
));
$form['submission_info']['user_picture'] = array(
'#value' => theme('user_picture', $account),
);
$form['submission_info']['form'] = array(
'#value' => '<div>' . t('Form: !form', array(
'!form' => l($node->title, 'node/' . $node->nid),
)) . '</div>',
);
$form['submission_info']['submitted'] = array(
'#value' => '<div>' . t('Submitted by !name', array(
'!name' => theme('username', $account),
)) . '</div>',
);
$form['submission_info']['time'] = array(
'#value' => '<div>' . format_date($submission->submitted, 'large') . '</div>',
);
$form['submission_info']['ip_address'] = array(
'#value' => '<div>' . $submission->remote_addr . '</div>',
);
}
$form['#theme'] = array(
'webform_form_' . $node->nid,
'webform_form',
);
$form['#attributes'] = array(
'class' => 'webform-client-form',
);
$form['#attributes']['enctype'] = 'multipart/form-data';
if (empty($submission)) {
$form['#action'] = url('node/' . $node->nid);
}
$form['#submit'][] = 'webform_client_form_submit';
$form['#validate'][] = 'webform_client_form_validate';
if (is_array($node->webform['components']) && !empty($node->webform['components'])) {
$form['submitted'] = array(
'#tree' => TRUE,
);
$form['details'] = array(
'#tree' => TRUE,
);
$component_tree = array();
$page_count = 1;
$page_num = 1;
_webform_components_tree_build($node->webform['components'], $component_tree, 0, $page_count);
if (!$preview && $enabled) {
if ($page_count > 1) {
$next_page = t('Next Page >');
$prev_page = t('< Previous Page');
if (!empty($form_state['storage']['submitted'])) {
$page_num = $form_state['values']['details']['page_num'];
$errors = form_get_errors();
if (empty($errors)) {
if ($form_state['values']['op'] == $prev_page && $page_num > 1) {
$page_num--;
}
elseif ($form_state['values']['op'] == $next_page && $page_num < $page_count) {
$page_num++;
}
}
}
else {
$page_num = 1;
}
$form['details']['page_num'] = array(
'#type' => 'hidden',
'#value' => $page_num,
);
$form['details']['page_count'] = array(
'#type' => 'hidden',
'#value' => $page_count,
);
if ($page_num > 1) {
$form['previous'] = array(
'#type' => 'submit',
'#value' => $prev_page,
'#weight' => 1000,
);
}
if ($page_num == $page_count) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => empty($node->webform['submit_text']) ? t('Submit') : $node->webform['submit_text'],
'#weight' => 1001,
);
}
elseif ($page_num < $page_count) {
$form['next'] = array(
'#type' => 'submit',
'#value' => $next_page,
'#weight' => 1001,
);
}
}
else {
$page_num = 1;
$form['submit'] = array(
'#type' => 'submit',
'#value' => empty($node->webform['submit_text']) ? t('Submit') : $node->webform['submit_text'],
'#weight' => 1000,
);
}
}
$microweight = 0.001;
foreach ($component_tree['children'] as $cid => $component) {
$component_value = isset($form_state['values']['submitted'][$component['form_key']]) ? $form_state['values']['submitted'][$component['form_key']] : NULL;
_webform_client_form_add_component($cid, $component, $component_value, $form['submitted'], $form, $submission, $page_num, $enabled);
if (isset($form['submitted'][$component['form_key']])) {
$form['submitted'][$component['form_key']]['#weight'] += $microweight;
$microweight += 0.001;
}
}
if (!$preview && $enabled) {
$form['details']['email_subject'] = array(
'#type' => 'hidden',
'#value' => $node->webform['email_subject'],
);
$form['details']['email_from_name'] = array(
'#type' => 'hidden',
'#value' => $node->webform['email_from_name'],
);
$form['details']['email_from_address'] = array(
'#type' => 'hidden',
'#value' => $node->webform['email_from_address'],
);
$form['details']['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
if (isset($submission->sid)) {
$form['details']['sid'] = array(
'#type' => 'hidden',
'#value' => $submission->sid,
);
}
}
}
return $form;
}
function _webform_client_form_add_component($cid, $component, $component_value, &$parent_fieldset, &$form, $submission, $page_num, $enabled = FALSE) {
if (!$enabled) {
$display_function = '_webform_submission_display_' . $component['type'];
if (function_exists($display_function)) {
$parent_fieldset[$component['form_key']] = $display_function(empty($submission->data[$cid]) ? NULL : $submission->data[$cid], $component, $enabled);
}
}
elseif ($component['page_num'] == $page_num) {
if (isset($submission->data)) {
$display_function = '_webform_submission_display_' . $component['type'];
if (function_exists($display_function)) {
$data = isset($submission->data[$cid]) ? $submission->data[$cid] : NULL;
$parent_fieldset[$component['form_key']] = $display_function($data, $component, $enabled);
}
}
else {
$render_function = '_webform_render_' . $component['type'];
if (function_exists($render_function)) {
$parent_fieldset[$component['form_key']] = $render_function($component);
if (isset($component_value)) {
if (is_array($component_value)) {
foreach ($component_value as $key => $value) {
$parent_fieldset[$component['form_key']][$key]['#default_value'] = $value;
}
}
else {
$parent_fieldset[$component['form_key']]['#default_value'] = $component_value;
}
}
}
else {
drupal_set_message(t('The webform component @type is not able to be displayed', array(
'@type' => $component['type'],
)));
}
}
}
if (isset($component['children']) && is_array($component['children'])) {
$microweight = 0.001;
foreach ($component['children'] as $scid => $subcomponent) {
$subcomponent_value = isset($component_value[$subcomponent['form_key']]) ? $component_value[$subcomponent['form_key']] : NULL;
_webform_client_form_add_component($scid, $subcomponent, $subcomponent_value, $parent_fieldset[$component['form_key']], $form, $submission, $page_num, $enabled);
$parent_fieldset[$component['form_key']][$subcomponent['form_key']]['#weight'] += $microweight;
$microweight += 0.001;
}
}
}
function webform_client_form_validate($form, $form_state) {
$node = node_load($form_state['values']['details']['nid']);
$sid = $form_state['values']['details']['sid'];
if ($node->webform['submit_limit'] != -1) {
module_load_include('inc', 'webform', 'webform_submissions');
if (empty($sid) && ($limit_exceeded = _webform_submission_limit_check($node))) {
$error = theme('webform_view_messages', $node, 0, 1, 0, $limit_exceeded, array_keys(user_roles()));
form_set_error('', $error);
return;
}
}
$form_state['values']['submitted_tree'] = $form_state['values']['submitted'];
$form_state['values']['submitted'] = _webform_client_form_submit_flatten($node, $form_state['values']['submitted']);
if (trim($node->webform['additional_validate'])) {
$form_values =& $form_state['values'];
eval('?>' . $node->webform['additional_validate']);
}
}
function webform_client_form_submit($form, &$form_state) {
global $user, $base_url;
module_load_include('inc', 'webform', 'webform_submissions');
webform_load_components();
$node = node_load(array(
'nid' => $form_state['values']['details']['nid'],
));
$submit_op = empty($node->webform['submit_text']) ? t('Submit') : $node->webform['submit_text'];
if ($form_state['values']['op'] != $submit_op) {
_webform_client_form_submit_process($node, $form_state['values']['submitted'], array(
'select',
'grid',
));
if (is_array($form_state['values']['submitted'])) {
foreach ($form_state['values']['submitted'] as $key => $val) {
$form_state['storage']['submitted'][$key] = $val;
}
}
if (is_array($form_state['storage']['submitted'])) {
foreach ($form_state['storage']['submitted'] as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
}
$form_state['rebuild'] = TRUE;
return;
}
if (isset($form_state['storage']['submitted'])) {
$original_values = is_array($form_state['values']['submitted']) ? $form_state['values']['submitted'] : array();
unset($form_state['values']['submitted']);
foreach ($form_state['storage']['submitted'] as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
foreach ($original_values as $key => $val) {
$form_state['values']['submitted'][$key] = $val;
}
unset($form_state['rebuild']);
unset($form_state['storage']);
unset($original_values);
}
_webform_client_form_submit_process($node, $form_state['values']['submitted']);
$form_state['values']['submitted_tree'] = $form_state['values']['submitted'];
$form_state['values']['submitted'] = _webform_client_form_submit_flatten($node, $form_state['values']['submitted']);
foreach ($node->webform['additional_emails'] as $cid => $value) {
if (is_array($form_state['values']['submitted'][$cid])) {
$node->webform['additional_emails'][$cid] = array();
foreach ($form_state['values']['submitted'][$cid] as $submitted_value) {
if ($submitted_value) {
$node->webform['additional_emails'][$cid][] = $submitted_value;
}
}
}
else {
$node->webform['additional_emails'][$cid] = $form_state['values']['submitted'][$cid];
}
if (empty($node->webform['additional_emails'][$cid])) {
unset($node->webform['additional_emails'][$cid]);
}
}
if (trim($node->webform['additional_submit'])) {
$form_values =& $form_state['values'];
eval('?>' . $node->webform['additional_submit']);
}
if (empty($form_state['values']['details']['sid'])) {
$form_state['values']['details']['sid'] = webform_submission_insert($node, $form_state['values']['submitted']);
$form_state['values']['details']['is_new'] = TRUE;
if (variable_get('webform_use_cookies', 0)) {
$cookie_name = 'webform-' . $node->nid;
$time = time();
setcookie($cookie_name . '[' . $time . ']', $time, $time + $node->webform['submit_interval'] + 86400);
}
}
else {
webform_submission_update($node, $form_state['values']['details']['sid'], $form_state['values']['submitted']);
$form_state['values']['details']['is_new'] = FALSE;
}
$sid = $form_state['values']['details']['sid'];
if ((!empty($node->webform['email']) || !empty($node->webform['additional_emails'])) && $form_state['values']['details']['is_new']) {
$email_from_name = $node->webform['email_from_name'];
$email_from_address = $node->webform['email_from_address'];
$email_subject = $node->webform['email_subject'];
foreach (array(
'from_name',
'from_address',
'subject',
) as $field) {
if ($node->webform['email_' . $field] == 'default') {
${'email_' . $field} = _webform_filter_values(webform_variable_get('webform_default_' . $field), $node, $form_state['values']['submitted'], FALSE, TRUE);
}
elseif (is_numeric($node->webform['email_' . $field])) {
if (is_array($form_state['values']['submitted'][${'email_' . $field}])) {
$values = array();
foreach ($form_state['values']['submitted'][${'email_' . $field}] as $key => $value) {
$values[] = _webform_filter_values($value, $node, $form_state['values']['submitted'], FALSE, TRUE);
}
${'email_' . $field} = implode(', ', $values);
}
else {
${'email_' . $field} = _webform_filter_values($form_state['values']['submitted'][${'email_' . $field}], $node, $form_state['values']['submitted'], FALSE, TRUE);
}
}
else {
${'email_' . $field} = _webform_filter_values(${'email_' . $field}, $node, $form_state['values']['submitted'], FALSE, TRUE);
}
}
$emails = $node->webform['additional_emails'];
if ($node->webform['email']) {
$emails['default'] = $node->webform['email'];
}
$messages = array();
$headers = array();
$froms = array();
$subjects = array();
foreach ($emails as $cid => $email) {
$messages[$cid] = theme(array(
'webform_mail_' . $node->nid,
'webform_mail',
'webform_mail_message',
), $form_state['values'], $node, $sid, $cid);
$headers[$cid] = theme(array(
'webform_mail_headers_' . $node->nid,
'webform_mail_headers',
), $form_state['values'], $node, $sid, $cid);
if (isset($headers[$cid]['From'])) {
$froms[$cid] = $headers[$cid]['From'];
unset($headers[$cid]['From']);
}
elseif (drupal_strlen($email_from_name) > 0) {
$froms[$cid] = '"' . mime_header_encode($email_from_name) . '" <' . $email_from_address . '>';
}
else {
$froms[$cid] = $email_from_address;
}
if (isset($headers[$cid]['Subject'])) {
$subjects[$cid] = $headers[$cid]['Subject'];
unset($headers[$cid]['Subject']);
}
else {
$subjects[$cid] = $email_subject;
}
if (isset($headers[$cid]['To'])) {
$emails[$cid] = $headers[$cid]['To'];
unset($headers[$cid]['To']);
}
}
if (_webform_submission_spam_check($emails['default'], $subjects['default'], $froms['default'], $headers['default'])) {
watchdog('webform', 'Possible spam attempt from @remote_addr' . "<br />\n" . nl2br(htmlentities($messages['default'])), array(
'@remote_add' => ip_address(),
));
drupal_set_message(t('Illegal information. Data not submitted.'), 'error');
return FALSE;
}
foreach ($emails as $cid => $address) {
if (is_array($address)) {
foreach ($address as $single_address) {
drupal_mail('webform', 'submission', $single_address, user_preferred_language($user), array(
'message' => $messages[$cid],
'subject' => $subjects[$cid],
'headers' => $headers[$cid],
), $froms[$cid]);
if (variable_get('webform_debug', 0) >= 2) {
drupal_set_message('E-mail Headers: <pre>' . htmlentities(print_r($headers[$cid], TRUE)) . '</pre>To: ' . $single_address . '<br />From: ' . htmlentities($froms[$cid]) . '<br />Subject: ' . $subjects[$cid] . '<br />E-mail Body: <pre>' . $messages[$cid] . '</pre>');
}
}
}
else {
drupal_mail('webform', 'submission', $address, user_preferred_language($user), array(
'message' => $messages[$cid],
'subject' => $subjects[$cid],
'headers' => $headers[$cid],
), $froms[$cid]);
if (variable_get('webform_debug', 0) >= 2) {
drupal_set_message('E-mail Headers: <pre>' . htmlentities(print_r($headers[$cid], TRUE)) . '</pre>To: ' . $address . '<br />From: ' . htmlentities($froms[$cid]) . '<br />Subject: ' . $subjects[$cid] . '<br />E-mail Body: <pre>' . $messages[$cid] . '</pre>');
}
}
}
}
if (variable_get('webform_debug', 0) >= 2) {
drupal_set_message('$form_state is: <pre>' . htmlentities(print_r($form_state, TRUE)) . '</pre>');
drupal_set_message('$_SERVER is: <pre>' . htmlentities(print_r($_SERVER, TRUE)) . '</pre>');
drupal_set_message('$_POST is: <pre>' . htmlentities(print_r($_POST, TRUE)) . '</pre>');
}
if (variable_get('webform_debug', 0) >= 1) {
watchdog('webform', 'Submission posted to %title. <a href="!url">Results</a>. !details', array(
'%title' => $node->title,
'!url' => url('node/' . $node->nid . '/submission/' . $sid),
'!results' => "<br />\n<pre>" . htmlentities(print_r($form_state['values'], TRUE)) . '</pre>',
));
}
if (isset($form_state['values']['submission'])) {
drupal_set_message(t('Submission updated.'));
$redirect = NULL;
}
elseif (valid_url(trim($node->webform['confirmation']), TRUE)) {
$redirect = trim($node->webform['confirmation']);
}
elseif (preg_match('/^internal:/', trim(strip_tags($node->webform['confirmation'])))) {
$path = preg_replace('/^internal:/', '', trim(strip_tags($node->webform['confirmation'])));
$redirect = array(
trim($path),
'sid=' . $sid,
);
}
elseif (preg_match('/^message:/', $node->webform['confirmation'])) {
$message = preg_replace('/^message:/', '', $node->webform['confirmation']);
drupal_set_message($message);
$redirect = NULL;
}
else {
$redirect = array(
'node/' . $node->nid . '/done',
'sid=' . $sid,
);
}
$form_state['redirect'] = $redirect;
}
function _webform_client_form_submit_process($node, &$form_values, $types = NULL, $parent = 0) {
if (is_array($form_values)) {
foreach ($form_values as $form_key => $value) {
$cid = webform_get_cid($node, $form_key, $parent);
if (is_array($value) && isset($node->webform['components'][$cid]['type']) && $node->webform['components'][$cid]['type'] == 'fieldset') {
_webform_client_form_submit_process($node, $form_values[$form_key], $types, $cid);
}
if (isset($node->webform['components'][$cid])) {
$component = $node->webform['components'][$cid];
$submit_function = '_webform_submit_' . $component['type'];
if (function_exists($submit_function) && (!isset($types) || in_array($component['type'], $types))) {
$submit_function($form_values[$component['form_key']], $component);
}
}
}
}
}
function _webform_client_form_submit_flatten($node, $fieldset, $parent = 0) {
$values = array();
if (is_array($fieldset)) {
foreach ($fieldset as $form_key => $value) {
$cid = webform_get_cid($node, $form_key, $parent);
if (is_array($value) && $node->webform['components'][$cid]['type'] == 'fieldset') {
$values += _webform_client_form_submit_flatten($node, $value, $cid);
}
else {
$values[$cid] = $value;
}
}
}
return $values;
}
function _webform_confirmation($node) {
drupal_set_title(check_plain($node->title));
if (empty($output)) {
$output = theme(array(
'webform_confirmation_' . $node->nid,
'webform_confirmation',
), $node, $_GET['sid']);
}
return $output;
}
function template_preprocess_webform_form(&$vars) {
if (isset($vars['form']['details']['nid']['#value'])) {
$vars['nid'] = $vars['form']['details']['nid']['#value'];
}
elseif (isset($vars['form']['submission']['#value'])) {
$vars['nid'] = $vars['form']['submission']['#value']->nid;
}
}
function template_preprocess_webform_confirmation(&$vars) {
if (empty($vars['node']->webform['confirmation'])) {
drupal_set_message(t('Thank you, your submission has been received.'));
drupal_goto('node/' . $vars['node']->nid);
}
$vars['confirmation_message'] = check_markup($vars['node']->webform['confirmation'], $vars['node']->format, FALSE);
}
function template_preprocess_webform_mail_message(&$vars) {
global $user;
$vars['user'] = $user;
$vars['ip_address'] = ip_address();
}
function theme_webform_mail_fields($cid, $value, $node, $indent = "") {
$component = $cid ? $node->webform['components'][$cid] : null;
if ($cid && !$component['email'] && !in_array($component['type'], array(
'markup',
'fieldset',
'pagebreak',
))) {
return '';
}
$themed_output = theme('webform_mail_' . $component['type'], $value, $component);
$message = '';
if ($themed_output) {
$message .= $indent;
$themed_output = rtrim($themed_output, "\n");
$message .= str_replace("\n", "\n" . $indent, $themed_output);
$message .= "\n";
}
elseif (!is_array($value)) {
if ($component['name']) {
$long = drupal_strlen($indent . $component['name'] . $value) > 60;
$message .= $indent . $component['name'] . ':' . (empty($value) ? "\n" : ($long ? "\n{$value}\n\n" : " {$value}\n"));
}
}
else {
if ($cid != 0) {
$message .= $indent . $component['name'] . ":\n";
}
foreach ($value as $k => $v) {
foreach ($node->webform['components'] as $local_key => $local_value) {
if ($local_value['form_key'] == $k && $local_value['pid'] == $cid) {
$form_key = $local_key;
break;
}
}
$message .= theme('webform_mail_fields', $form_key, $v, $node, $indent . ' ');
}
}
return $message;
}
function theme_webform_mail_headers($form_values, $node, $sid, $cid) {
$headers = array(
'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')',
);
return $headers;
}
function _webform_filter_values($string, $node = NULL, $submission = NULL, $strict = TRUE, $allow_anonymous = FALSE) {
global $user;
static $replacements;
if (!isset($replacements)) {
$replacements['unsafe'] = array();
$replacements['safe']['%site'] = variable_get('site_name', 'drupal');
$replacements['safe']['%date'] = format_date(time(), 'large');
}
if (isset($node) && !array_key_exists('%title', $replacements)) {
$replacements['safe']['%title'] = $node->title;
}
if (isset($submission) && !array_key_exists('%email_values', $replacements)) {
foreach ($submission as $cid => $value) {
$replacements['unsafe']['%cid[' . $cid . ']'] = (string) $value;
}
}
$special_tokens = array(
'safe' => array(
'%get' => $_GET,
),
'unsafe' => array(
'%cookie' => $_COOKIE,
'%session' => $_SESSION,
'%post' => $_POST,
'%request' => $_REQUEST,
),
);
if (!array_key_exists('%username', $replacements['unsafe'])) {
$replacements['unsafe']['%username'] = isset($user->name) ? $user->name : '';
$replacements['unsafe']['%useremail'] = isset($user->mail) ? $user->mail : '';
$replacements['unsafe']['%ip_address'] = ip_address();
$special_tokens['unsafe']['%server'] = $_SERVER;
}
if (!isset($replacements['unsafe']['%profile[uid]'])) {
if ($user->uid && module_exists('profile')) {
profile_load_profile($user);
}
$special_tokens['unsafe']['%profile'] = $user;
}
foreach ($special_tokens as $safe_state => $tokens) {
foreach ($tokens as $token => $variable) {
if (strpos($string, $token) !== FALSE) {
foreach ($variable as $key => $value) {
if ($token == '%profile' && is_array($value) && isset($value['year'])) {
$replacement = format_date(strtotime($value['month'] . '/' . $value['day'] . '/' . $value['year']), 'custom', 'F j, Y', '0');
}
else {
$replacement = (string) $value;
}
$replacements[$safe_state][$token . '[' . $key . ']'] = $replacement;
}
}
}
}
$safe_replacements = $replacements['safe'];
if ($user->uid || $allow_anonymous) {
$safe_replacements += $replacements['unsafe'];
}
else {
foreach ($replacements['unsafe'] as $key => $value) {
$safe_replacements[$key] = '';
}
}
$find = array_keys($safe_replacements);
$replace = array_values($safe_replacements);
$string = str_replace($find, $replace, $string);
foreach ($special_tokens as $safe_state => $tokens) {
foreach (array_keys($tokens) as $token) {
$string = preg_replace('/\\' . $token . '\\[\\w+\\]/', '', $string);
}
}
return $strict ? filter_xss($string) : $string;
}
function _webform_filter_descriptions($string, $node = NULL, $submission = NULL, $strict = TRUE) {
return check_markup(_webform_filter_values($string, $node, $submission, $strict));
}
function webform_admin_content() {
$result = db_query(db_rewrite_sql("SELECT n.* FROM {node} n WHERE n.type = 'webform'"));
$nodes = array();
while ($node = db_fetch_object($result)) {
$nodes[] = $node;
}
return theme('webform_admin_content', $nodes);
}
function theme_webform_admin_content($nodes) {
$header = array(
t('Title'),
array(
'data' => t('View'),
'colspan' => '4',
),
array(
'data' => t('Operations'),
'colspan' => '2',
),
);
$rows = array();
foreach ($nodes as $node) {
$rows[] = array(
l($node->title, 'node/' . $node->nid),
l(t('Submissions'), 'node/' . $node->nid . '/webform-results'),
l(t('Analysis'), 'node/' . $node->nid . '/webform-results/analysis'),
l(t('Table'), 'node/' . $node->nid . '/webform-results/table'),
l(t('Download'), 'node/' . $node->nid . '/webform-results/download'),
node_access('update', $node) ? l(t('Edit'), 'node/' . $node->nid . '/edit') : '',
user_access('clear webform results') ? l(t('Clear'), 'node/' . $node->nid . '/webform-results/clear') : '',
);
}
return theme('table', $header, $rows);
}
function webform_get_cid(&$node, $form_key, $pid) {
foreach ($node->webform['components'] as $cid => $component) {
if ($component['form_key'] == $form_key && $component['pid'] == $pid) {
return $cid;
}
}
}
function webform_variable_get($variable) {
switch ($variable) {
case 'webform_default_from_name':
$result = variable_get('webform_default_from_name', variable_get('site_name', ''));
break;
case 'webform_default_from_address':
$result = variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from')));
break;
case 'webform_default_subject':
$result = variable_get('webform_default_subject', t('Form submission from: %title'));
break;
}
return $result;
}
function theme_webform_token_help() {
$tokens = array(
'%username',
'%useremail',
'%session[' . t('key') . ']',
'%post[' . t('key') . ']',
'%request[' . t('key') . ']',
'%cookie[' . t('key') . ']',
'%server[' . t('key') . ']',
);
if (module_exists('profile')) {
$tokens[] = '%profile[' . t('key') . ']';
}
$anonymous_tokens = array(
'%site',
'%date',
'%get[' . t('key') . ']',
);
$output = '';
$output .= t('You may use special tokens in this field that will be replaced with dynamic values.');
$output .= theme('item_list', $anonymous_tokens, t('all users:'));
$output .= theme('item_list', $tokens, t('authorized users only:'));
$output .= t('You can use %server[key] to add any of the special PHP <a href="http://www.php.net/reserved.variables#reserved.variables.server">$_SERVER</a> variables, %session[key] to add any of the special PHP <a href="http://www.php.net/reserved.variables#reserved.variables.session">$_SESSION</a> variables and %get[key] to create prefilled forms from the <a href="http://www.php.net/reserved.variables#reserved.variables.get">URL</a>. %cookie, %request and %post also work with their respective PHP variables. For example %server[HTTP_USER_AGENT], %session[id], or %get[q].');
if (module_exists('profile')) {
$output .= ' ' . t('If you are using the profiles module, you can also access all profile data using the syntax %profile[form_name]. If you for example have a profile value named profile_city, add the variable %profile[profile_city].');
}
$fieldset = array(
'#title' => t('Token values'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#children' => '<div>' . $output . '</div>',
);
return theme('fieldset', $fieldset);
}
function _webform_safe_name($name) {
$new = trim($name);
if (function_exists('transliteration_get')) {
$new = transliteration_get($new, '');
$new = str_replace(array(
' ',
'-',
), array(
'_',
'_',
), $new);
}
else {
$new = str_replace(array(
' ',
'-',
'€',
'ƒ',
'Š',
'Ž',
'š',
'ž',
'Ÿ',
'¢',
'¥',
'µ',
'À',
'Á',
'Â',
'Ã',
'Ä',
'Å',
'Ç',
'È',
'É',
'Ê',
'Ë',
'Ì',
'Í',
'Î',
'Ï',
'Ñ',
'Ò',
'Ó',
'Ô',
'Õ',
'Ö',
'Ø',
'Ù',
'Ú',
'Û',
'Ü',
'Ý',
'à',
'á',
'â',
'ã',
'ä',
'å',
'ç',
'è',
'é',
'ê',
'ë',
'ì',
'í',
'î',
'ï',
'ñ',
'ò',
'ó',
'ô',
'õ',
'ö',
'ø',
'ù',
'ú',
'û',
'ü',
'ý',
'ÿ',
'Œ',
'œ',
'Æ',
'Ð',
'Þ',
'ß',
'æ',
'ð',
'þ',
), array(
'_',
'_',
'E',
'f',
'S',
'Z',
's',
'z',
'Y',
'c',
'Y',
'u',
'A',
'A',
'A',
'A',
'A',
'A',
'C',
'E',
'E',
'E',
'E',
'I',
'I',
'I',
'I',
'N',
'O',
'O',
'O',
'O',
'O',
'O',
'U',
'U',
'U',
'U',
'Y',
'a',
'a',
'a',
'a',
'a',
'a',
'c',
'e',
'e',
'e',
'e',
'i',
'i',
'i',
'i',
'n',
'o',
'o',
'o',
'o',
'o',
'o',
'u',
'u',
'u',
'u',
'y',
'y',
'OE',
'oe',
'AE',
'DH',
'TH',
'ss',
'ae',
'dh',
'th',
), $new);
}
$new = drupal_strtolower($new);
$new = preg_replace('/[^a-z0-9_]/', '', $new);
return $new;
}
function _webform_component_options($components, $type) {
$acceptable_types = $type == 'email' ? array(
'email',
'select',
'hidden',
) : array(
'textfield',
'select',
'hidden',
);
$options = array();
foreach ((array) $components as $cid => $component) {
if (in_array($component['type'], $acceptable_types)) {
$options[$cid] = $component['name'];
}
}
return $options;
}
function _webform_components_tree_build($src, &$tree, $parent, &$page_count) {
foreach ($src as $cid => $component) {
if ($component['pid'] == $parent) {
_webform_components_tree_build($src, $component, $cid, $page_count);
$tree['children'][$cid] = $component;
$tree['children'][$cid]['page_num'] = $page_count;
if ($component['type'] == 'pagebreak') {
$page_count++;
}
}
}
return $tree;
}
function _webform_components_tree_flatten($tree) {
$components = array();
foreach ($tree as $cid => $component) {
if (isset($component['children'])) {
unset($component['children']);
$components[$cid] = $component;
$children = _webform_components_tree_flatten($tree[$cid]['children']);
foreach ($children as $ccid => $ccomponent) {
$components[$ccid] = $ccomponent;
}
}
else {
$components[$cid] = $component;
}
}
return $components;
}
function _webform_components_sort($a, $b) {
if ($a['weight'] == $b['weight']) {
return strcasecmp($a['name'], $b['name']);
}
return $a['weight'] < $b['weight'] ? -1 : 1;
}
function _webform_components_tree_sort($tree) {
if (isset($tree['children']) && is_array($tree['children'])) {
$children = array();
uasort($tree['children'], '_webform_components_sort');
foreach ($tree['children'] as $cid => $component) {
$children[$cid] = _webform_components_tree_sort($component);
}
$tree['children'] = $children;
}
return $tree;
}
function webform_load_components($return_all = FALSE, $reset = FALSE) {
static $component_list, $enabled_list;
if (!isset($component_list) || $reset) {
$component_list = array();
$enabled_list = array();
$path = drupal_get_path('module', 'webform') . '/components';
$files = file_scan_directory($path, '^.*\\.inc$');
foreach ($files as $filename => $file) {
$enabled = variable_get('webform_enable_' . $file->name, 1);
if ($return_all || $enabled) {
module_load_include('inc', 'webform', 'components/' . $file->name);
$component_list[$file->name] = t($file->name);
}
if ($enabled) {
$enabled_list[$file->name] = t($file->name);
}
}
}
return $return_all ? $component_list : array_intersect_assoc($component_list, $enabled_list);
}