You are here

function webform_load in Webform 5.2

Same name and namespace in other branches
  1. 5 webform.module \webform_load()
  2. 6.2 webform.module \webform_load()

Implementation of hook_load().

2 calls to webform_load()
webform_form in ./webform.module
Implementation of hook_form(). Creates the standard form for editing or creating a webform.
webform_view in ./webform.module
Implementation of hook_view().

File

./webform.module, line 375

Code

function webform_load($node) {
  include_once drupal_get_path('module', 'webform') . '/webform_components.inc';
  $additions = new stdClass();
  if ($webform = db_fetch_array(db_query('SELECT * FROM {webform} WHERE nid = %d', $node->nid))) {
    $additions->webform = $webform;
    $additions->webform['roles'] = array();
    $result = db_query('SELECT rid FROM {webform_roles} WHERE nid = %d', $node->nid);
    while ($role = db_fetch_object($result)) {
      $additions->webform['roles'][] = $role->rid;
    }
  }
  else {
    $additions->webform = array(
      'confirmation' => '',
      'teaser' => 0,
      'submit_text' => '',
      'submit_limit' => -1,
      'submit_interval' => -1,
      'email' => '',
      'email_from_name' => 'default',
      'email_from_address' => 'default',
      'email_subject' => 'default',
      'additional_validate' => '',
      'additional_submit' => '',
      'roles' => array(
        1,
        2,
      ),
    );
  }
  $additions->webform['components'] = array();
  $additions->webform['additional_emails'] = array();
  $result = db_query('SELECT * FROM {webform_component} WHERE nid = %d ORDER BY weight, name', $node->nid);
  while ($c = db_fetch_array($result)) {
    $component =& $additions->webform['components'][$c['cid']];
    $component['nid'] = $node->nid;
    $component['cid'] = $c['cid'];
    $component['form_key'] = $c['form_key'] ? $c['form_key'] : $c['cid'];
    $component['name'] = t($c['name']);
    $component['type'] = $c['type'];
    $component['value'] = $c['value'];
    $component['extra'] = unserialize($c['extra']);
    $component['mandatory'] = $c['mandatory'];
    $component['email'] = $c['email'];
    $component['pid'] = $c['pid'];
    $component['weight'] = $c['weight'];
    if (isset($component['extra']['email']) && $component['extra']['email']) {
      $additions->webform['additional_emails'][$c['cid']] = $c['cid'];
    }
    webform_component_defaults($component);
  }

  // Organize the components into a fieldset-based order.
  if (!empty($additions->webform['components'])) {
    $component_tree = array();
    $page_count = 1;
    _webform_components_tree_build($additions->webform['components'], $component_tree, 0, $page_count);
    $additions->webform['components'] = _webform_components_tree_flatten($component_tree['children']);
  }
  return $additions;
}