You are here

function date_copy_import_event_form in Date 6

Same name and namespace in other branches
  1. 5.2 date_copy/date_copy.module \date_copy_import_event_form()
  2. 5 date_copy.module \date_copy_import_event_form()

Event import form.

1 string reference to 'date_copy_import_event_form'
date_copy_menu in date_copy/date_copy.module
Implementation of hook_menu().

File

date_copy/date_copy.module, line 428

Code

function date_copy_import_event_form($form_values = NULL) {

  // 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();
  }
  $step = intval($form_values['step'] + 1);
  $form['step'] = array(
    '#type' => 'hidden',
    '#value' => $step,
  );
  $form['#multistep'] = TRUE;
  $form['#redirect'] = FALSE;
  switch ($step) {
    case 1:

      // Select a content type to import into.
      $node_types = node_get_types('names');
      $form['#prefix'] = t('<p>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>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_copy_type_form(TRUE);
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
      );
      return $form;
    case 2:

      // Select the fields to import into.
      $type = $form_values['target_type'];
      $form['target_type'] = array(
        '#value' => $type,
        '#type' => 'hidden',
      );
      $form['source_type'] = array(
        '#value' => $form_values['source_type'],
        '#type' => 'hidden',
      );
      $form['fields'] = array(
        '#type' => 'fieldset',
        '#title' => t('!type Fields', array(
          '!type' => $node_types[$type],
        )),
        '#weight' => -1,
      );
      $form['fields'] += date_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('Submit'),
      );
      return $form;
  }
}