You are here

function webform_protected_downloads_process_submissions in Webform Protected Downloads 7

Same name and namespace in other branches
  1. 6 webform_protected_downloads.module \webform_protected_downloads_process_submissions()

Process unprocessed webform submissions

Return value

void

1 string reference to 'webform_protected_downloads_process_submissions'
webform_protected_downloads_form_alter in ./webform_protected_downloads.module
Implementation of hook_form_alter().

File

./webform_protected_downloads.module, line 778
This file contains hook declarations and functions for the Webform Protected Downloads module.

Code

function webform_protected_downloads_process_submissions($form, &$form_state) {
  if (!$form_state['webform_completed']) {

    // Do nothing unless the form has been completed
    return;
  }
  $sid = $form_state['values']['details']['sid'];
  $nid = $form_state['values']['details']['nid'];

  // check whether the node has protected files, otherwise we can skip the
  // following steps
  if (!webform_protected_downloads_node_has_protected_files($nid)) {
    return;
  }

  // load the configuration for this node
  $conf = webform_protected_downloads_get_configuration($nid);

  // this should not happen, if it does something is seriously not working and
  // we can't figurue out where to send the mail, so skip it
  if (!isset($form_state['values']['submitted'][$conf->mail_field_cid])) {
    _webform_protected_downloads_log('Problem with node !nid: The mail field could not be found in the form submission. No e-mail has been send.', array(
      '!nid' => $nid,
    ), WATCHDOG_ERROR);
    return;
  }

  // now get the mail adress that should be used
  $mail = $form_state['values']['submitted'][$conf->mail_field_cid];

  // create hash, calculate expiration timestamp
  $hash = webform_protected_downloads_create_hash();
  $processed = time();
  $expires = $conf->expiration_download == 0 ? 0 : $processed + $conf->expiration_download;

  // we need to save before sending the mail
  $record = array(
    'sid' => $sid,
    'hash' => $hash,
    'processed' => $processed,
    'expires' => $expires,
    'used' => 0,
  );
  drupal_write_record('wpd_access_hashes', $record);

  // now send the mail
  webform_protected_downloads_send_mail($sid, $nid, $mail, $hash);
  if ($conf->redirect) {
    $form_state['redirect'] = 'node/' . $nid . '/download/' . $hash;
  }
}