You are here

function webform_email_insert in Webform 7.4

Same name and namespace in other branches
  1. 6.3 includes/webform.emails.inc \webform_email_insert()
  2. 7.3 includes/webform.emails.inc \webform_email_insert()

Insert a new e-mail setting into the database.

Parameters

$email: An array of settings for sending an e-mail.

Return value

int|false The e-mail identifier for this row's settings on success else false.

4 calls to webform_email_insert()
webform_email_clone in includes/webform.emails.inc
Clone an existing e-mail setting.
webform_email_edit_form_submit in includes/webform.emails.inc
Submit handler for webform_email_edit_form().
webform_node_insert in ./webform.module
Implements hook_node_insert().
webform_node_update in ./webform.module
Implements hook_node_update().

File

includes/webform.emails.inc, line 703
Provides interface and database handling for e-mail settings of a webform.

Code

function webform_email_insert($email) {

  // @todo This is not race-condition safe. Switch to using transactions?
  if (!isset($email['eid'])) {
    $next_id_query = db_select('webform_emails')
      ->condition('nid', $email['nid']);
    $next_id_query
      ->addExpression('MAX(eid) + 1', 'eid');
    $email['eid'] = $next_id_query
      ->execute()
      ->fetchField();
    if ($email['eid'] == NULL) {
      $email['eid'] = 1;
    }
  }
  $email['excluded_components'] = implode(',', $email['excluded_components']);
  $email['extra'] = empty($email['extra']) ? '' : serialize($email['extra']);
  $success = drupal_write_record('webform_emails', $email);
  return $success ? $email['eid'] : FALSE;
}