You are here

function webform_node_load in Webform 6.3

Same name and namespace in other branches
  1. 7.4 webform.module \webform_node_load()
  2. 7.3 webform.module \webform_node_load()

Implements hook_node_load().

1 call to webform_node_load()
webform_nodeapi in ./webform.module
Implements hook_nodeapi().

File

./webform.module, line 1197

Code

function webform_node_load($node) {
  module_load_include('inc', 'webform', 'includes/webform.components');
  $additions = array();
  if (isset($node->nid)) {
    $webform = db_fetch_array(db_query('SELECT * FROM {webform} WHERE nid = %d', $node->nid));

    // If a webform record doesn't exist, just return the defaults.
    if (!$webform) {
      $additions['webform'] = webform_node_defaults();
      return $additions;
    }
    $additions['webform'] = $webform;
    $additions['webform']['record_exists'] = TRUE;
    $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;
    }
    $additions['webform']['emails'] = array();
    $result = db_query('SELECT * FROM {webform_emails} WHERE nid = %d', $node->nid);
    while ($email = db_fetch_array($result)) {
      $additions['webform']['emails'][$email['eid']] = $email;
      $additions['webform']['emails'][$email['eid']]['excluded_components'] = array_filter(explode(',', $email['excluded_components']));
      if (variable_get('webform_format_override', 0)) {
        $additions['webform']['emails'][$email['eid']]['html'] = variable_get('webform_default_format', 0);
      }
    }
  }
  $additions['webform']['components'] = 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'] = $c['name'];
    $component['type'] = $c['type'];
    $component['value'] = $c['value'];
    $component['extra'] = unserialize($c['extra']);
    $component['mandatory'] = $c['mandatory'];
    $component['pid'] = $c['pid'];
    $component['weight'] = $c['weight'];
    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;
}