? webform_optional_access_control.patch
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.124.2.88
diff -u -p -r1.124.2.88 webform.module
--- webform.module	19 Jan 2009 03:39:49 -0000	1.124.2.88
+++ webform.module	5 Feb 2009 20:43:19 -0000
@@ -681,23 +681,25 @@ function webform_form(&$node, &$param) {
   /* End Edit Form */
 
   /* Start per-role submission control */
-  $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>.'),
-  );
-  $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])),
-  );
+  if (variable_get('webform_use_access_control', 1)) {
+    $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>.'),
+    );
+    $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])),
+    );
+  }
   /* End per-role submission control */
 
   /* Start E-mail Settings Form */
@@ -1082,12 +1084,14 @@ function webform_view(&$node, $teaser = 
   }
 
   // Check if the user's role can submit this webform.
-  $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;
+  if (variable_get('webform_use_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;
+    }
   }
 
   // Check if the user can add another submission.
@@ -1171,18 +1175,20 @@ function theme_webform_view_messages($no
   $type = 'notice';
 
   // If not allowed to submit the form, give an explaination.
-  if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
-    if (empty($allowed_roles)) {
-      // No roles are allowed to submit the form.
-      $message = t('Submissions for this form are closed.');
-    }
-    elseif (isset($allowed_roles[2])) {
-      // The "authenticated user" role is allowed to submit and the user is currently logged-out.
-      $message = t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array('!login' => url('user/login'), '!register' => url('user/register')));
-    }
-    else {
-      // The user must be some other role to submit.
-      $message = t('You do not have permission to view this form.');
+  if (variable_get('webform_use_access_control', 1)) {
+    if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
+      if (empty($allowed_roles)) {
+        // No roles are allowed to submit the form.
+        $message = t('Submissions for this form are closed.');
+      }
+      elseif (isset($allowed_roles[2])) {
+        // The "authenticated user" role is allowed to submit and the user is currently logged-out.
+        $message = t('You must <a href="!login">login</a> or <a href="!register">register</a> to view this form.', array('!login' => url('user/login'), '!register' => url('user/register')));
+      }
+      else {
+        // The user must be some other role to submit.
+        $message = t('You do not have permission to view this form.');
+      }
     }
   }
 
@@ -1324,6 +1330,14 @@ function webform_admin_settings() {
     '#description' => t('Set to "Log submissions" to log all submissions in the watchdog. Set to "Full debug" to print debug info on submission.')
   );
 
+  $form['advanced']['webform_use_access_control']  = array(
+    '#type' => 'checkbox',
+    '#title' => t("Use Webform Access Control?"),
+    '#checked_value' => 1,
+    '#default_value' => variable_get("webform_use_access_control", 1),
+    '#description' => t('You may want to disable this if you are using a separate node access module to control access to webforms.')    
+  );
+  
   $form = system_settings_form($form);
   $form['#theme'] = 'webform_admin_settings';
 
