You are here

function _webform_update_submission in Webform 5

1 call to _webform_update_submission()
webform_client_form_submit in ./webform.module

File

./webform.module, line 2030

Code

function _webform_update_submission($node, $sid, $submitted) {
  global $user;

  //update submission by first deleting and then inserting it to the database
  db_query("DELETE FROM {webform_submissions} WHERE sid = %d", $sid);
  db_query("INSERT INTO {webform_submissions} (nid, sid, uid, submitted, remote_addr) " . " VALUES (%d, %d, %d, %d, '%s')", $node->nid, $sid, $user->uid, time(), $_SERVER['REMOTE_ADDR']);

  // update the submission data by first removing all this submissions data
  db_query("DELETE FROM {webform_submitted_data} WHERE sid = %d", $sid);

  // and then re-ad it to the database
  foreach ($submitted as $cid => $value) {
    if (is_array($value)) {
      $delta = 0;
      foreach ($value as $k => $v) {
        db_query("INSERT INTO {webform_submitted_data} (nid, sid, cid, no, data) " . "VALUES (%d, %d, %d, %d, '%s')", $node->nid, $sid, $cid, $delta, $v);
        $delta++;
      }
    }
    else {
      db_query("INSERT INTO {webform_submitted_data} (nid, sid, cid, no, data) " . "VALUES (%d, %d, %d, %d, '%s')", $node->nid, $sid, $cid, 0, $value);
    }
  }
  return $sid;
}