Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.69
diff -u -p -r1.196.2.69 webform.module
--- webform.module	5 Nov 2010 01:05:50 -0000	1.196.2.69
+++ webform.module	30 Nov 2010 20:05:40 -0000
@@ -482,6 +482,7 @@ function webform_perm() {
     'access own webform submissions',
     'edit own webform submissions',
     'delete own webform submissions',
+    'change submission author',
   );
 }
 
@@ -1652,6 +1653,64 @@ function webform_client_form(&$form_stat
         '#weight' => 10,
       );
     }
+    // Check if the form already submitted and there are already author and date values.
+    if (isset($submission->name) && !empty($submission->name)) {
+      $default_user = $submission->name;
+    }
+    else {
+      $default_user = $user->name;
+    }
+    if (isset($submission->submitted) && !empty($submission->submitted)) {
+      $default_date = $submission->submitted;
+    }
+    else {
+      $default_date = time();
+    }
+	
+	// Create the admin fieldset only if editing an already existing submission, or on the last page of a new submission.
+    if (isset($submission->sid) || $page_num == $page_count) {
+      // Check if the current page is a submission page and that user has 'change submission author' or 'administer users' permissions.
+      if (arg(2) == 'submission' && (user_access('change submission author') || user_access('administer users'))) {
+        $form['admin'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Administration'),
+        '#collapsible' => 1,
+        '#collapsed' => 1,
+        '#weight' => -200,
+        );
+        // Add Authored by textfield to the form.
+        $form['admin']['author'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Authored by'),
+          '#size' => 30,
+          '#maxlength' => 60,
+          '#autocomplete_path' => 'user/autocomplete',
+          '#default_value' => $default_user,
+          '#weight' => 0,
+        );
+        // Add Authored on textfield to the form.
+        $form['admin']['date'] = array(
+          '#type' => 'textfield',
+          '#parents' => array( 0 => 'date' ),
+          '#title' => t('Authored on'),
+          '#size' => 20,
+          '#maxlength' => 25,
+          '#default_value' => date('Y-m-d H:i', $default_date),
+          '#weight' => 1,
+        );
+	// Check if a editing an already existing submission.
+        if (isset($submission->sid)) {
+          // Add separate submit button for the author and date fields .
+          $form['admin']['submit'] = array(
+            '#type' => 'button',
+            '#value' => t('Submit Author/Date'),
+            '#weight' => 2,
+  	        '#executes_submit_callback' => TRUE,
+	        '#submit' => array('_webform_author_date_submit'),
+          );
+	    }
+      }
+    }
   }
 
   return $form;
@@ -1836,6 +1895,11 @@ function webform_client_form_validate($f
   // Run all #element_validate and #required checks. These are skipped initially
   // by setting #validated = TRUE on all components when they are added.
   _webform_client_form_validate($form, $form_state);
+
+  // Check that the author exists.
+  if (!$account = user_load(array('name' => $form_state['values']['author']))) {
+    form_set_error('author', t('Please specify a valid author.'));
+  }
 }
 
 /**
@@ -2019,6 +2083,39 @@ function webform_client_form_pages($form
 }
 
 /**
+ * Submit handler for changing the author and date of an existing submission.
+ */
+function _webform_author_date_submit($form, &$form_state) {
+  $node = node_load($form_state['values']['details']['nid']);
+
+  // Check if user is submitting as a draft.
+  $is_draft = $form_state['values']['op'] == t('Save Draft');
+
+  // Load the submission if editing an existing one.
+  if (!empty($form_state['values']['details']['sid'])) {
+    $submission = webform_get_submission($node->nid, $form_state['values']['details']['sid']);
+
+    // Check if submission auther has changed.
+    if (isset($form_state['values']['author']) && !empty($form_state['values']['author'])) {
+      $submitted_user = user_load(array('name' => $form_state['values']['author']));
+      $submission->uid = $submitted_user->uid;
+    }
+    // Check if submission date has changed.
+    if (isset($form_state['values']['date']) && !empty($form_state['values']['date'])) {
+      $submission->submitted = strtotime($form_state['values']['date']);
+    }
+
+    $submission->remote_addr = ip_address();
+    $submission->is_draft = $is_draft;
+  }
+
+  webform_submission_update($node, $submission);
+
+  drupal_set_message(t('Author and submission date updated.'), 'status');
+  drupal_goto('node/' . $node->nid . '/webform-results');
+}
+
+/**
  * Submit handler for saving the form values and sending e-mails.
  */
 function webform_client_form_submit($form, &$form_state) {
@@ -2035,19 +2132,47 @@ function webform_client_form_submit($for
   // Check if user is submitting as a draft.
   $is_draft = $form_state['values']['op'] == t('Save Draft');
 
-  // Create a submission object.
-  $submission = (object) array(
-    'nid' => $node->nid,
-    'uid' => $user->uid,
-    'submitted' => time(),
-    'remote_addr' => ip_address(),
-    'is_draft' => $is_draft,
-    'data' => webform_submission_data($node, $form_state['values']['submitted']),
-  );
+  // Load the submission if editing an existing one.
+  if (!empty($form_state['values']['details']['sid'])) {
+    $submission = webform_get_submission($node->nid, $form_state['values']['details']['sid']);
+
+    // Check if submission author has changed.
+    if (isset($form_state['values']['author']) && !empty($form_state['values']['author'])) {
+      $submitted_user = user_load(array('name' => $form_state['values']['author']));
+      $submission->uid = $submitted_user->uid;
+    }
+    // Check if submission date has changed.
+    if (isset($form_state['values']['date']) && !empty($form_state['values']['date'])) {
+      $submission->submitted = strtotime($form_state['values']['date']);
+    }
+
+    $submission->remote_addr = ip_address();
+    $submission->is_draft = $is_draft;
+    $submission->data = webform_submission_data($node, $form_state['values']['submitted']);
+  }
+  else {
+    // Set the submission author.
+    if (isset($form_state['values']['author'])) {
+      $submitted_user = user_load(array('name' => $form_state['values']['author']));
+      $author_uid = $submitted_user->uid;
+    }
+    else {
+      $author_uid = $form_state['values']['details']['uid'];
+    }
+    // Build a submission object from scratch.
+    $submission = (object) array(
+      'nid' => $node->nid,
+      'uid' => $author_uid,
+      'submitted' => time(),
+      'remote_addr' => ip_address(),
+      'is_draft' => $is_draft,
+      'data' => webform_submission_data($node, $form_state['values']['submitted']),
+    );
+  }
 
   // Save the submission to the database.
   if (empty($form_state['values']['details']['sid'])) {
-    // No sid was found thus insert it in the dataabase.
+    // No sid was found thus insert it in the database.
     $form_state['values']['details']['sid'] = webform_submission_insert($node, $submission);
     $form_state['values']['details']['is_new'] = TRUE;
 
Index: templates/webform-form.tpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/templates/webform-form.tpl.php,v
retrieving revision 1.1
diff -u -p -r1.1 webform-form.tpl.php
--- templates/webform-form.tpl.php	22 May 2009 03:11:18 -0000	1.1
+++ templates/webform-form.tpl.php	30 Nov 2010 20:05:40 -0000
@@ -20,9 +20,10 @@
 ?>
 <?php
   // If editing or viewing submissions, display the navigation at the top.
-  if (isset($form['submission_info']) || isset($form['navigation'])) {
+  if (isset($form['submission_info']) || isset($form['navigation']) || isset($form['admin'])) {
     print drupal_render($form['navigation']);
     print drupal_render($form['submission_info']);
+    print drupal_render($form['admin']);
   }
 
   // Print out the main part of the form.
