I am using the Webform module for a reporting system. There are several (multi-page) webforms and each authenticated user is assigned to one of the webforms (thus there may be multiple users per webform). Each user is allowed to submit his webform only once, but he may save his submission as draft until final completion. When he finally submits his report, he is not allowed to edit his submission anymore and an administrator is going to check the values submitted.

So far, I can configure Webform in order to allow this scenario. However, if the administrator finds errors or invalid data, I need him to be able to convert a submission back to draft status. I couldn't find any option to allow administrator to make such an action. I am aware that this might be out of scope for this module, but before starting to code I wanted to ask if I missed this possibility somehow or if there are preferred hooks to use.

Second, the reporting system distinguishes between one-time reports (only to be filled out at the end of a project once) and interim reports (have to be filled out once a year). If the above problem is solved, administrators could also turn interim submissions back to draft to allow the user to edit the values (as there might only be minor changes from year to year).

Any helpful information to point me into the right direction would be much appreciated.

Comments

Paul Broon created an issue. See original summary.

quicksketch’s picture

Hi Paul, this indeed is not supported by Webform itself. I'd suggest using Webform's API to put submissions back into the draft state if needed, e.g.

$submission->is_draft = TRUE;

You can do this in hook_webform_submission_presave(), in which the $submission is passed by reference so you don't have to save it yourself manually. You might also form_alter() the submission form, or perhaps just reuse a component that is admin-only to toggle the draft state.

broon’s picture

Status: Active » Closed (won't fix)

Thanks for the quick (what a pun!) answer.

I just ended up writing this short module:

function MYMODULE_menu() {
 $items['node/%webform_menu/submission/%webform_menu_submission/reopen'] = array(
    'load arguments' => array(1),
    'page callback' => 'MYMODULE_submission_reopen',
    'page arguments' => array(1, 3),
    'access arguments' => array('reopen submission'),
  );
}

function MYMODULE_submission_reopen($node, $submission) {
  $submission->is_draft = TRUE;
  // Update the main submission info.
  drupal_write_record('webform_submissions', $submission, 'sid');
  drupal_set_message(t("Submission has been re-opened."), 'status', FALSE);
  drupal_goto(drupal_get_destination());
}

And in my views table of all completed submissions I add a submission id field (sid) and rewrote it accordingly to my menu item entry.