<?php

// $id


function calendarsignup_forms($form_id, $args) {
  if (strpos($form_id, 'calendarsignup_form_') === 0) {
    $node = $args[0];
    if ($form_id == 'calendarsignup_form_'. $node->nid) {
      $forms[$form_id] = array(
        'callback' => 'signup_form',
        'callback arguments' => array($node, 'auth', TRUE),
        );
      return $forms;
    }
  }
}

/**
 * hook_nodeapi implementation
 *
 */
function calendarsignup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') {
    switch ($op) {
      case 'view':
        if (arg(0) == 'event' && _signup_needs_output($node)) {
          // Store the data into the content array, for default display.
          module_load_include('inc', 'signup', 'includes/signup_form');
          $node->content['calendarsignup'] = array(
            '#value' => drupal_get_form('calendarsignup_form_'. $node->nid, $node, 'auth', TRUE),
            '#weight' => 10,
            );
        }
    }
  }
}

/**
 * Implementation of hook_form_alter
 */
function calendarsignup_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form_id, 'calendarsignup_form_') === 0) {
    $form['#submit'][] = 'signup_form';
  }
}

function calendarsignup_preprocess_event_node_day(&$variables) {
  calendarsignup_theming($variables);
}
function calendarsignup_preprocess_event_node_week(&$variables) {
  calendarsignup_theming($variables);
}
function calendarsignup_preprocess_event_node_month(&$variables) {
  calendarsignup_theming($variables);
}
function calendarsignup_preprocess_event_node_list(&$variables) {
  calendarsignup_theming($variables);
}
function calendarsignup_preprocess_event_node_table(&$variables) {
  calendarsignup_theming($variables);
}

function calendarsignup_theming(&$variables) {
  if (isset($variables['node']->content['calendarsignup'])) {
    $variables['calendarsignup'] = $variables['node']->content['calendarsignup']['#value'];
  }
  else {
    $variables['calendarsignup'] = '';
  }
}
