You are here

function date_tools_copy_import_event_form in Date 6.2

Event import form.

1 string reference to 'date_tools_copy_import_event_form'
date_tools_menu in date_tools/date_tools.module

File

date_tools/date_tools.event.inc, line 10
Code to migrate Events to use Date fields instead.

Code

function date_tools_copy_import_event_form($form_state) {

  // We can do an import if there are event fields available whether or not the event module is enabled
  // so we just check whether the table exists.
  if (!db_table_exists('event')) {
    drupal_set_message(t('There is no event table in this database. No event import options are available.'));
    return array();
  }
  if (empty($form_state['values']['step'])) {
    $form_state['values']['step'] = 0;
  }
  $step = intval($form_state['values']['step'] + 1);
  $form['step'] = array(
    '#type' => 'hidden',
    '#value' => $step,
  );
  switch ($step) {
    case 1:

      // Select a content type to import into.
      $node_types = node_get_types('names');
      $form['#prefix'] = '<p>' . t("Create a new CCK content type to import your events into, or, if you do not want to create new nodes for your events, add a date field to the existing event type. Make sure the target content type has a date field that has an optional or required To date so it can accept the From date and To date of the event. If your source event has its own timezone field, make sure you set the target date timezone handling to 'date'. Test the target type by trying to create a node manually and make sure all the right options are available in the form before attempting an import.") . '</p><p><strong>' . t('The import will create new nodes and trigger all related hooks, so you may want to turn off automatic email messaging for this node type while performing the import!') . '</strong></p>';
      $source_type_options = array();
      $result = db_query("SELECT DISTINCT n.type FROM {event} e INNER JOIN {node} n ON e.nid=n.nid");
      while ($arr = db_fetch_array($result)) {
        $source_type_options[$arr['type']] = $node_types[$arr['type']];
      }
      if (sizeof($source_type_options) < 1) {
        drupal_set_message(t('There are no event nodes in this database. No event import options are available.'));
        return array();
      }
      $form['source_type'] = array(
        '#type' => 'select',
        '#options' => $source_type_options,
        '#title' => t('Source type'),
        '#default_value' => '',
      );
      $form += date_tools_copy_type_form(TRUE);
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Import'),
      );
      return $form;
    case 2:

      // Select the fields to import into.
      $type = $form_state['values']['target_type'];
      $form['target_type'] = array(
        '#value' => $type,
        '#type' => 'hidden',
      );
      $form['source_type'] = array(
        '#value' => $form_state['values']['source_type'],
        '#type' => 'hidden',
      );
      $form['fields'] = array(
        '#type' => 'fieldset',
        '#title' => t('!type Fields', array(
          '!type' => check_plain($node_types[$type]),
        )),
        '#weight' => -1,
      );
      $form['fields'] += date_tools_copy_type_fields_form($type);
      $form['delete_old'] = array(
        '#type' => 'select',
        '#options' => array(
          1 => t('Yes'),
          0 => t('No'),
        ),
        '#title' => t('Delete original event?'),
        '#description' => t('Should the original entry be deleted once it has been copied to the new content type? If so, be sure to back up your database first.'),
      );
      $form['max'] = array(
        '#type' => 'textfield',
        '#title' => t('Limit'),
        '#description' => t('The maximum number of nodes to convert in this pass.'),
        '#required' => TRUE,
      );
      $form['start_nid'] = array(
        '#type' => 'textfield',
        '#title' => t('Starting nid'),
        '#default_value' => 0,
        '#description' => t('Convert nodes with nids greater than or equal to this number.'),
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Import'),
      );
      return $form;
  }
}