You are here

function flipping_book_management_form_submit in Flipping Book 7

Submit callback.

See also

flipping_book_management_form()

File

includes/flipping_book.pages.inc, line 86
Flipping Book Pages.

Code

function flipping_book_management_form_submit($form, &$form_state) {
  $title = $form_state['values']['fb'][0]['title'];
  $file = $form_state['values']['fb'][0]['file'];
  $filepath = drupal_realpath($file->uri);
  if (module_exists('transliteration')) {
    $dir = pathinfo(transliteration_clean_filename($file->filename), PATHINFO_FILENAME);
  }
  else {
    $dir = pathinfo(_flipping_book_clean_filename($file->filename), PATHINFO_FILENAME);
  }
  $fdir = flipping_book_dir();
  file_prepare_directory($fdir, FILE_CREATE_DIRECTORY);
  $destination = file_destination($fdir . '/' . $dir, FILE_EXISTS_RENAME);
  $zip = new ZipArchive();
  $res = $zip
    ->open($filepath);
  if ($res) {
    try {
      $zip
        ->extractTo(drupal_realpath($destination) . '/');
      $record = array(
        'title' => $title,
        'dir' => str_replace(flipping_book_dir() . '/', '', $destination),
        'created' => REQUEST_TIME,
      );
      if (drupal_write_record('flipping_book', $record)) {
        drupal_set_message(t('Your Flipping Book has been imported.'));
      }
      else {
        drupal_set_message(t('There was an error saving your Flipping Book.'), 'error');
      }
    } catch (Exception $e) {
      drupal_set_message(t('Cannot extract Flipping Book file: @message', array(
        '@message',
        $e
          ->getMessage(),
      )), 'error');
    }
  }
  else {
    drupal_set_message(t('Cannot save Flipping Book informations'), 'error');
  }
}