You are here

function organigrams_form_import_submit in Organigrams 7

Submit function for organigrams_form_import.

File

./organigrams.admin.inc, line 790
Defines the administration forms for managing organigrams.

Code

function organigrams_form_import_submit($form, &$form_state) {
  $data = json_decode($form_state['values']['import']);
  $organigram = $data->organigram;

  // Remove the original organigram ID.
  unset($organigram->oid);

  // Get a unique machine name.
  $organigram->machine_name = organigrams_check_machine_name($organigram->machine_name);

  // Save the organigram.
  organigrams_save($organigram);

  // Show an error if the organigram save failed.
  if (empty($organigram->oid)) {
    drupal_set_message(t('Failed importing the organigram. Please make sure you copied the whole export script.'), 'error');
  }
  else {

    // Show a success message if the importing succeeded.
    drupal_set_message(t('Successfully imported organigram %name.', array(
      '%name' => $organigram->name,
    )));

    // Check if there are items to import.
    if (!empty($data->items)) {

      // Import the items.
      $status = organigrams_import_items($organigram->oid, $data->items);

      // Show an additional error message if the items import failed.
      if ($status !== TRUE) {
        drupal_set_message($status, 'error');
      }
    }

    // Redirect to the new organigram.
    drupal_goto('admin/structure/organigrams/' . $organigram->machine_name);
  }
}