diff -urpN phpbb2drupalpatch1/phpbb2drupal.module phpbb2drupalpatch2/phpbb2drupal.module
--- phpbb2drupalpatch1/phpbb2drupal.module	2007-12-16 03:14:34.014600000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal.module	2007-12-23 23:07:45.696498700 +0000
@@ -86,32 +86,8 @@ function phpbb2drupal_cleanup() {
  * Callback admin/phpbb2drupal/postconfiguration
  */
 function phpbb2drupal_postconfiguration() {
-  // Private forums.
-  $output = '<h2>'. t('Private forums') .'</h2>';
-  $output .= '<p>'. t('Setup the private forums as explained in the <a href="http://drupal.org/node/58969" target="_blank">documentation</a>') .'</p>';
-
-  // Redirection from old URL:
-  $output .= '<h2>'. t('Redirection from phpBB2 forum URL to new Drupal forum URL') .'</h2>';
-  $output .= '<p>'. t('Enable the phpbb_redirect.module. This way, users accessing URLs from your old phpBB2 installation will be redirected to your new Drupal forum. (note that currently the module assumes that the phpbb forum was located in the forum/ subdirectory of your Drupal installation).') .'</p>';
-
-  // BBcode
-  $bbcode = variable_get('phpbb2drupal_bbcode', 0);
-  if ($bbcode) {
-    $output .= '<h2>'. t('Remove BBcode module') .'</h2>';
-    $output .= '<p>'. t("The bbcode has been cleaned from the posts. You shouldn't need the bbcode module anymore. You can disable it.") .'</p>';
-  }
-  else {
-    $output .= '<h2>'. t('Configure BBcode module') .'</h2>';
-    $output .= '<p>'. t('Most probably, there are many phpBB forum postings formatted in BBcode. During the import procedure, the BBcode has been cleaned so that it can work with the Drupal bbcode.module. Please install and configure the <a href="http://drupal.org/project/bbcode" target="_blank">BBcode module</a> so that the forum topics display properly. See the BBcode module documentation for details.') .'</p>';
-  }
-
-  //Avatars
-  $output .= '<h2>'. t('Avatars') .'</h2>';
-  $output .= t('<p>Manually copy the avatars from the phpbb2/images/avatars/ directory to the drupal/files/pictures/ directory.</p>
-    <p>Also, in admin > settings > users, you need to enable picture support. </p>
-    <p>Finally, in admin > themes > configure, you need to allow "User Picture in posts/comments".</p>');
-
-  return $output;
+  include_once dirname(__FILE__).'/phpbb2drupal_postconfiguration.inc.php';
+  return _phpbb2drupal_postconfiguration();
 }
 
 /**
@@ -175,514 +151,8 @@ function _phpbb2drupal_db_connect($test=
  * Callback admin/phpbb2drupal/configure
  */
 function phpbb2drupal_admin_settings() {
-  global $conf ;
-  global $db_url;
-  $stage = variable_get('phpbb2drupal_config_stage', 0); 
-
-  //We'll be checking that the setup is complete.
-  //If it is not complete, the migration will not go ahead.
-  $ready_for_migration = 1;
-
-  // Checking that the migration has been tested on a copy first.
-  $form['test'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Test on copy first'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-    
-  $output = '';
-  if (!variable_get('phpbb2drupal_tested', 0)) {
-    $form['test']['#collapsed']= FALSE;
-    $output = '<span class="marker">';
-    $ready_for_migration = 0;
-  }
-  $output .= t('<p>The migration will modify and even destroy some data. You must test this module on a copy of your data first, several times if necessary. Only use this module on your live data when you are familiar with the procedure and you\'re confident everything will run smoothly.</p>
-  <p>Also, you should make a full backup of your database just prior to permorming the migration on the live data. It is better to turn off both the phpBB board and the Drupal site during the migration.</p>');
-  if (!variable_get('phpbb2drupal_tested', 0)) {
-    $output .= '</span>';
-  }
-  $form['test']['intro'] = array('#value' => $output);
-  $output = '';
-
-  $form['test']['phpbb2drupal_tested'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('I am running a trial migration on a disposable copy of the database OR I have already done so and I am running this on my live site, confident that the migration will proceed smoothly'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_tested', 0),
-    '#description' => '',
-  ); 
-
-  // Input format settings
-  $form['input'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Input Format settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $output = '<p>'. t('Select which <a href="@link">input format</a> should the imported messages be set:', array('@link' => url('admin/filters'))) .'</p>';
-  $form['input']['intro'] = array('#value' => $output);
-  $output = '';
-
-  $input_formats = array(0 => t('not set yet'));
-  $sql = 'SELECT format, name FROM {filter_formats}';
-  $result = db_query($sql);
-  while ($format = db_fetch_array($result)) {
-    $input_formats[$format['format']]= $format['name'];
-  }
-  $input_format = variable_get('phpbb2drupal_input_format', 0);
-  $form['input']['phpbb2drupal_input_format'] = array(
-    '#type' => 'radios',
-    '#title' => t('Input format'),
-    '#default_value' => $input_format,
-    '#options' => $input_formats,
-  );
-  if (!$input_format) {
-    $ready_for_migration = 0;
-    $form['input']['#collapsed']= FALSE;
-  }
-  $output .= '<p><em>'. t('This setting will be applied to all posts and private messages.') .'</em></p>';
-  $form['input']['result'] = array('#value' => $output);
-
-
-  // BBcode settings
-  $form['bbcode'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('BBcode settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-
-  $output = t('<p>pbpBB2 posts are often formatted in BBcode. During the import process, BBcode can be handled in two diffent ways:</p>
-    <ul><li>You can leave the BBcode as is, and use the <a href="http://drupal.org/project/bbcode" target="_blank">bbcode module</a> after the migration to filter the imported posts. In this case, the module is not required during the migration but you will need to install it and configure it later.</li>
-    <li>You can decide to have the BBcode filtered now and replaced by plain HTML. The BBcode module will be required during the migration process, but you can disable it later.</li>    </ul>
-    <p>Which one do you choose?</p>
-    <p>Also, make sure to choose the proper input filter, for it will affect how the post is displayed. For example, if you choose to strip the bbcode altogether and use HTML instead, some HTML tags will be stripped by the "filtered HTML" input format, unless you add those tags in the list of allowed tags. Using "Full HTML" is recommanded for the imported posts when doing away with bbcode.</p>');
-  $form['bbcode']['intro'] = array('#value' => $output);
-  $form['bbcode']['phpbb2drupal_bbcode'] = array(
-    '#type' => 'radios',
-    '#title' => t('BBcode handling'),
-    '#default_value' => variable_get('phpbb2drupal_bbcode', 0),
-    '#options' => array(t('Leave BBcode as is.'), t('Transform BBcode into HTML.')),
-    '#description' => '',
-  );
-  $output = '';
-  $result7 = _phpbb2drupal_check_module('bbcode');
-  $output .= $result7['html'];
-  $link_input_format_enable = url('admin/filters/'.$input_format);
-  $link_input_format_configure = url('admin/filters/'.$input_format.'/configure');
-  if (variable_get('phpbb2drupal_bbcode', 0)) { 
-    if ($result7['result'] == 0) {
-      $ready_for_migration = 0;
-      $form['bbcode']['#collapsed']= FALSE;
-      $output .= '<p><span class="marker">';
-      $output .= t('<a href="http://drupal.org/project/bbcode" target="_blank">The bbcode module</a> is required to transform BBcode into HTML. 
-        You first need to <a href="@adminmodules">enable the bbcode module</a>', array('@adminmodules' => url('admin/modules')));
-      $output .= '</span></p>';
-    }
-    $sql = 'SELECT * FROM {filters} WHERE module = \'bbcode\' AND format = %d';
-    $result = db_query($sql, $input_format);
-    if (!db_num_rows($result)) {
-      $form['bbcode']['#collapsed']= FALSE;
-      $output .= '<p class="marker">'. t('You need to <a href="@formatenable">enable bbcode in the selected input format</a> <a href="@formatconfigure">THEN click on configure to see bbcode options</a>', array('@formatenable' => $link_input_format_enable, '@formatconfigure' => $link_input_format_configure)) .'</p>';
-    }
-    $output .= '<p>'. t('For best results, <a href="@bbcodeconfig">all four BBcode configure options should be disabled</a>.', array('@bbcodeconfig' => url('admin/filters/'. $input_format .'/configure'))) .'</p>';
-    
-  }
-  else {
-    if ($result7['result'] == 0) {
-      $form['bbcode']['#collapsed']= FALSE;
-      $output .= '<p>'. t('<a href="http://drupal.org/project/bbcode" target="_blank">The bbcode module</a> is only recommanded. You may <a href="@adminmodules">enable the bbcode module</a> after having installed it.', array('@adminmodules' => url('admin/modules'))) .'</p>';
-    }
-    $output .= t('<p>Don\'t forget to <a href="@formatenable">enable bbcode in the selected input format</a> (admin > input formats > configure) and enable bbcode for the format selected for the imported posts.  <a href="@formatconfigure">Then click on configure to see bbcode options</a></p>
-      <p>You may want to enable it for other input formats, too.</p>', array('@formatenable' => $link_input_format_enable, '@formatconfigure' => $link_input_format_configure));
-  }
-  $output .= '<p><em>'. t('This setting will be applied to all posts, private messages and the users\' signature.') .'</em></p>';
-  $form['bbcode']['result'] = array('#value' => $output);
-
-  
-
-  // Drupal Modules settings
-  $form['modules'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Drupal modules'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $output = '<p>';
-  $result1 = _phpbb2drupal_check_module('forum');
-  $output .= $result1['html'];
-  $result2 = _phpbb2drupal_check_module('node');
-  $output .= $result2['html'];
-  $result3 = _phpbb2drupal_check_module('comment');
-  $output .= $result3['html'];
-  $result4 = _phpbb2drupal_check_module('user');
-  $output .= $result4['html'];
-  $result5 = _phpbb2drupal_check_module('profile');
-  $output .= $result5['html'];
-  $result6 = _phpbb2drupal_check_module('taxonomy');
-  $output .= $result6['html'];
-  $output .= '</p>';
-
-  if ($result1['result'] == 0 || $result2['result'] == 0 || $result3['result'] == 0 || $result4['result'] == 0 || $result5['result'] == 0 || $result6['result'] == 0) {
-    $ready_for_migration = 0;
-    $form['modules']['#collapsed']= FALSE;
-    $output .= '<p class="marker">';
-    $output .= t('Some of the modules are not enabled. <a href="@adminmodules">Got to the admin/modules page to enable them</a>', array('@adminmodules' => url('admin/modules')));
-    $output .= '</p>';
-  }
-  $form['modules']['result'] = array('#value' => $output);
-  $output = '';
-
-  // Where is phpbb2?
-  $form['phpbb2'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Location of phpBB2 data'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['phpbb2']['phpbb2drupal_same_db'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('phpbb is on the same database as drupal'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_same_db', 1),
-    '#description' => '',
-  );
-  if (variable_get('phpbb2drupal_same_db', 1) != 1) {
-    $url = variable_get('phpbb2drupal_db_url', $db_url);
-    if ($url == $db_url) {
-      $output = '<p class="marker">'. t('Set the address of the phpBB database according to the following format: <br /><pre>mysql://phpbb_username:phpbb_password@localhost/phpbb_database</pre>') .'</p>';
-      $ready_for_migration = 0;
-      $form['phpbb2']['#collapsed']= FALSE;
-    }
-
-    $form['phpbb2']['phpbb2drupal_db_url'] = array(
-      '#type' => 'textfield',
-      '#title' => t('phpBB2 database location'),
-      '#default_value' => variable_get('phpbb2drupal_db_url', $db_url),
-      '#size' => 80,
-      '#maxlength' => 255,
-      '#description' => '',
-    );
-  }
-
-  $output = t('<p>Note that due to a limitation within Drupal core, we cannot import messages from one database type to another database type. E.g, we cannot import phpBB from a myqsl DB, to a postgresql DB. You need to import the data into the same type of database first (import all the phpBB data, as is, from mysql to postgresql.</p>
-    <p>If both phpBB and Drupal are on postgresql, see <a href="http://drupal.org/node/64877">this issue</a>.</p>');
-  $form['phpbb2']['note'] = array('#value' => $output);
-  
-  // phpBB2 table prefix
-  $output = '';
-  $form['phpbb2']['phpbb2drupal_table_prefix'] = array(
-    '#type' => 'textfield',
-    '#title' => t('phpBB2 table prefix'),
-    '#default_value' => variable_get('phpbb2drupal_table_prefix', 'phpbb_'),
-    '#size' => 20,
-    '#maxlength' => 255,
-    '#description' => t('What prefix is used for your phpBB2 tables?'),
-  );
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  $tables = array($pre.'categories', $pre.'forums', $pre.'posts', $pre.'posts_text', $pre.'topics', $pre.'users');
-  $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
-  $output .= $result['html'];
-  
-  if ($result['result'] != 1) {
-    $ready_for_migration = 0;
-    $form['phpbb2']['#collapsed']= FALSE;
-    $output .= '<span class="marker">';
-    $output .= t("Some tables couldn't be found. Please correct the errors so that the phpBB2 tables can be accessed.");
-    $output .= '</span>';
-  }
-  $form['phpbb2']['result'] = array('#value' => $output);
-
-
-  
-  // Misc.	
-  $form['misc'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Misc. settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-
-  // Time limit 
-  $output = '';
-  //Registration date format
-  $form['misc']['phpbb2drupal_regdate_us_english'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Convert Registration Date'),
-    '#default_value' => variable_get('phpbb2drupal_regdate_us_english', 0),
-    '#return_value' => 1,
-    '#description' => t('If you find out that the registration date for ALL your users is over 36 years ago, maybe your DB stores the registration date in the English US format (like: "Sep 11, 2001") instead as a linux timestamp (like: "1152568884"). If so, check this box.'),
-  );
-  $form['misc']['phpbb2drupal_time_limit'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Time limit'),
-    '#default_value' => variable_get('phpbb2drupal_time_limit', 1200),
-    '#size' => 7,
-    '#maxlength' => 10,
-    '#description' => t('How long, in seconds, will the migration take?'),
-  );
-  $form['misc']['info'] = array(
-    '#value' => '<p>'. t('1200 = 20 minutes should be enough for most boards. It worked well for a board with 300,000 rows. Beware: if your site is cohosted and safe-mode is on, then this value will have no effect.') .'</p>',
-  );
-  
-  // USERS settings
-  $form['users'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('User import'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  // User to map admin user too
-  $drupal_admin = user_load(array('uid' => 1));
-  $form['users']['phpbb2drupal_admin_user'] = array(
-    '#title' => t('User to map phpBB admin'),
-    '#type' => 'textfield',
-    '#autocomplete_path' => 'user/autocomplete',
-    '#default_value' => variable_get('phpbb2drupal_admin_user', $drupal_admin->name ),
-  );
-  
-
-  // Import users who have never posted?
-  $form['users']['phpbb2drupal_import_spammers'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Import users who have never posted?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_import_spammers', 1),
-    '#description' => '',
-  );
- 
-  //Polls
-  $form['polls'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Polls import'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['polls']['phpbb2drupal_import_polls'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Import polls?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_import_polls', 0),
-    '#description' => '',
-  );
-  if (variable_get('phpbb2drupal_import_polls', 0) == 1) {
-    //poll modules
-    $result = _phpbb2drupal_check_module('poll');
-    $output .= $result['html'];
-    if ($result['result'] != 1) {
-      $ready_for_migration = 0;
-      $form['polls']['#collapsed'] = FALSE;
-      $output .= '<span class="marker">';
-      $output .= t('Please enable the poll module.') ;
-      $output .= '</span>';
-    }
-    $form['polls']['info'] = array('#value' => $output);
-  }
-  
- 
-  //Attachements
-  $output ='';
-  $form['attachments'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Attachments import'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['attachments']['phpbb2drupal_import_attachments'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Import attachments?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_import_attachments', 0),
-    '#description' => '',
-  );
-  if (variable_get('phpbb2drupal_import_attachments', 0) == 1) {
-    // Comment attachments module
-    $result = _phpbb2drupal_check_module('comment_upload');
-    $output .= $result['html'];
-    if ($result['result'] != 1) {
-      $ready_for_migration = 0;
-      $form['attachments']['#collapsed']= FALSE;
-      $output .= '<span class="marker">';
-      $output .= t('The comment_upload.module is not enabled. You can <a href="http://drupal.org/node/37197" target="_blank">go to the module Home Page to download it</a>. <a href="@adminmodules">After having installed it, go to the admin/module page to enable it</a>', array('@adminmodules' => url('admin/modules')));
-      $output .= '</span>';
-    }
-  }
-  
-  // Encoding
-  $form['encoding'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Encoding setting',
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-
- //DEBUG http://php.net/extension_loaded 
- if (!extension_loaded('mbstring') && variable_get('phpbb2drupal_encode', '1')) {
-   $ready_for_migration = 0;
-   $form['encoding']['#collapsed']= FALSE;
-   $output .= '<p class="marker">';
-   $output .= t("The php mbstring module is not installed on this server: the posts' encoding cannot be changed during the migration.");
-   $output .= '</p>';
- }
-
-  $encodings = array(
-    'utf-8' => 'utf-8',
-    'iso-8859-1' => 'iso-8859-1',
-    'UCS-4' => 'UCS-4',
-    'UCS-4BE' => 'UCS-4BE',
-    'UCS-4LE' => 'UCS-4LE',
-    'UCS-2' => 'UCS-2',
-    'UCS-2BE' => 'UCS-2BE',
-    'UCS-2LE' => 'UCS-2LE',
-    'UTF-32' => 'UTF-32',
-    'UTF-32BE' => 'UTF-32BE',
-    'UTF-32LE' => 'UTF-32LE',
-    'UTF-16' => 'UTF-16',
-    'UTF-16BE' => 'UTF-16BE',
-    'UTF-16LE' => 'UTF-16LE',
-    'UTF-7' => 'UTF-7',
-    'UTF7-IMAP' => 'UTF7-IMAP',
-    'ASCII' => 'ASCII',
-    'EUC-JP' => 'EUC-JP',
-    'SJIS' => 'SJIS',
-    'eucJP-win' => 'eucJP-win',
-    'SJIS-win' => 'SJIS-win',
-    'ISO-2022-JP' => 'ISO-2022-JP',
-    'JIS' => 'JIS',
-    'ISO-8859-2' => 'ISO-8859-2',
-    'ISO-8859-3' => 'ISO-8859-3',
-    'ISO-8859-4' => 'ISO-8859-4',
-    'ISO-8859-5' => 'ISO-8859-5',
-    'ISO-8859-6' => 'ISO-8859-6',
-    'ISO-8859-7' => 'ISO-8859-7',
-    'ISO-8859-8' => 'ISO-8859-8',
-    'ISO-8859-9' => 'ISO-8859-9',
-    'ISO-8859-10' => 'ISO-8859-10',
-    'ISO-8859-13' => 'ISO-8859-13',
-    'ISO-8859-14' => 'ISO-8859-14',
-    'ISO-8859-15' => 'ISO-8859-15',
-    'byte2be' => 'byte2be',
-    'byte2le' => 'byte2le',
-    'byte4be' => 'byte4be',
-    'byte4le' => 'byte4le',
-    'BASE64' => 'BASE64',
-    'HTML-ENTITIES' => 'HTML-ENTITIES',
-    '7bit' => '7bit',
-    '8bit' => '8bit',
-    'EUC-CN' => 'EUC-CN',
-    'CP936' => 'CP936',
-    'HZ' => 'HZ',
-    'EUC-TW' => 'EUC-TW',
-    'CP950' => 'CP950',
-    'BIG-5' => 'BIG-5',
-    'EUC-KR' => 'EUC-KR',
-    'UHC (CP949)' => 'UHC (CP949)',
-    'ISO-2022-KR' => 'ISO-2022-KR',
-    'Windows-1251 (CP1251)' => 'Windows-1251 (CP1251)',
-    'Windows-1252 (CP1252)' => 'Windows-1252 (CP1252)',
-    'CP866 (IBM866)' => 'CP866 (IBM866)',
-    'KOI8-R' => 'KOI8-R',
-   );
-  
-  $form['encoding']['phpbb2drupal_encode'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Change encoding of text strings during the import'),
-    '#default_value' => variable_get('phpbb2drupal_encode', '1'),
-  );
-
-  $output .= '<p>'. t('This setting is useful when the phpBB2 encoding is not the same as the Drupal encoding. <strong>You server must have the <em>php mbstring module</em> installed.</strong>') .'</p>';
-  $form['encoding']['info'] = array(
-    '#value' => $output 
-  );
-  
-  $form['encoding']['phpbb2drupal_encoding_phpbb'] = array(
-    '#type' => 'select',
-    '#title' => t('phpBB2 encoding'),
-    '#default_value' => variable_get('phpbb2drupal_encoding_phpbb', 'iso-8859-1'),
-    '#options' => $encodings,
-  );
-
-  $form['encoding']['phpbb2drupal_encoding_drupal'] = array(
-    '#type' => 'select',
-    '#title' => t('Drupal encoding'),
-    '#default_value' => variable_get('phpbb2drupal_encoding_drupal', 'utf-8'),
-    '#options' => $encodings,
-  );
-
-  // Private messages
-  $output = '';
-  $form['pm'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Private Messages'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['pm']['phpbb2drupal_import_pm'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Import private messages?'),
-    '#return_value' => 1,
-    '#default_value' => variable_get('phpbb2drupal_import_pm', 0),
-    '#description' => '',
-  );
-  if (variable_get('phpbb2drupal_import_pm', 0) == 1) {
-
-     // Private messages module
-      $output = '<p>'. t('If you want to use the private message module, make sure to configure it properly (admin > settings> private messages) and allow user to view their own private messages (admin > access control).') .'</p>';
-      $result = _phpbb2drupal_check_module('privatemsg');
-      $output .= $result['html'];
-      if ($result['result'] != 1) {
-        $ready_for_migration = 0;
-        $form['pm']['#collapsed']= FALSE;
-        $output .= '<p class="marker">';
-        $output .= t('The private message module is not enabled. You can <a href="http://drupal.org/project/privatemsg" target="_blank">go to the module Home Page to download it</a>. <a href="@adminmodules">After having installed it, go to the admin/module page to enable it</a>.', array('@adminmodules' => url('admin/modules')));
-        $output .= '</p>';
-      }
-      $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-      $tables = array($pre.'privmsgs', $pre.'privmsgs_text');
-      $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
-      $output .= $result['html'];
-      if ($result['result'] != 1) {
-        $ready_for_migration = 0;
-        $form['pm']['#collapsed']= FALSE;
-        $output .= '<p class="marker">';
-        $output .= t("Couldn't find the phpBB privatemsg tables.");
-        $output .= '</p>';
-      }
-
-      //private messages tables.
-      $result = _phpbb2drupal_check_tables(array('privatemsg', 'privatemsg_folder', 'privatemsg_archive'));
-      $output .= $result['html'];
-      if ($result['result'] != 1) {
-        $ready_for_migration = 0;
-        $form['pm']['#collapsed']= FALSE;
-        $output .= '<p class="marker">';
-        $output .= t("Some tables couldn't be found. Please make sure you have properly installed the privatemsg.mysql on your Drupal data base.");
-        $output .= '</p>';
-      }
-      $form['pm']['info'] = array('#value' => $output);
-
-  }
-  $output ='';
-
-  // Are we ready for migration?
-  $form['migration'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Migration',
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  variable_set('phpbb2drupal_ready', $ready_for_migration);
-  if ($ready_for_migration) {
-    $form['migration']['#collapsed']= FALSE;
-    $output .= '<p>'. t('Check again all the settings above, and if everything is ok, <a href="@migratelink">you can now proceed with the migration</a>', array('@migratelink' => url('admin/phpbb2drupal/migrate'))) .'</p>';
-  }
-  else {
-    $output = '<p class="marker">'. t('You are not ready for the migration yet. Check the settings above.') .'</p>';
-  }
-  
-  $form['migration']['info'] = array('#value' => $output);
-  return system_settings_form($form); 
+  include_once dirname(__FILE__).'/phpbb2drupal_admin_settings.inc.php';
+  return _phpbb2drupal_admin_settings(); 
 }
 
 
@@ -748,1059 +218,70 @@ function _phpbb2drupal_check_tables( $ta
   return $out;
 }
 
-
-
 function phpbb2drupal_migrate() {
-  if (!variable_get('phpbb2drupal_ready', 0)) {
-    return '<p>'. t('You cannot migrate the data now. Please <a href="@settings">complete the setup first</a>', array('@settings' => url('admin/settings/phpbb2drupal'))) .'</p>';
-  }
-
-  $output = 'Phpbb 2 Drupal Migration Form';
-  $output .= drupal_get_form('phpbb2drupal_migrate_form');
-  return $output;
-}
-
-function phpbb2drupal_migrate_form() {
-  _phpbb2drupal_db_connect() ;
-  // Causes problems with form api redirect
-  //ini_set('display_errors', TRUE);
-
-  // Adjust how long you want the script to run...
-  if (!ini_get('safe_mode')) {
-    set_time_limit(variable_get('phpbb2drupal_time_limit', 0));
-  }
-  
-  $PHPBB2DRUPAL_FUNCTIONS = array(
-    'users' => t('Import Users'),
-    'categories' => t('Import Categories'),
-    'topics' => t('Import Topics'),
-    'polls' => t('Import Polls'),
-    'posts' => t('Import Posts'),
-  );
-
-  if (variable_get('phpbb2drupal_import_pm', 0)) { 
-    $PHPBB2DRUPAL_FUNCTIONS['pm'] = t('Import Private Messages');
-  }
-  $PHPBB2DRUPAL_FUNCTIONS['url'] = t('Transform URLs');
-  /*
-  $new = array('cleanup' => 'Clean up');
-  $PHPBB2DRUPAL_FUNCTIONS = array_merge( $PHPBB2DRUPAL_FUNCTIONS, $new);
-  */
-
-  $form['import'] = array(
-    '#type' => 'select',
-    '#title' => t('Next import to perform'),
-    '#default_value' => $_SESSION['phpbb2drupal_selected'],
-    '#options' => $PHPBB2DRUPAL_FUNCTIONS,
-  );
-  $form[] = array(
-    '#type' => 'submit',
-    '#value' => t('Import'),
-  );
-  return $form;
+  include_once dirname(__FILE__).'/phpbb2drupal_migrate.inc.php';
+  return _phpbb2drupal_migrate();
 }
 
 function phpbb2drupal_migrate_form_submit($form_id, $form_values) {
-
-  switch ($form_values['import']) {
-    case 'users':
-      phpbb2drupal_import_users();
-      if (!variable_get('phpbb2drupal_import_user_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'users';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'categories';
-      }
-      break;
-
-    case 'categories':
-      phpbb2drupal_import_categories();
-      if (!variable_get('phpbb2drupal_import_category_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'categories';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'topics';
-      }
-      break;
-
-    case 'topics':      
-      phpbb2drupal_import_topics();
-      if (!variable_get('phpbb2drupal_import_topic_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'topics';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'polls';
-      }
-      break;
-    
-    case 'polls':      
-      phpbb2drupal_import_polls();
-      if (!variable_get('phpbb2drupal_import_poll_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'polls';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'posts';
-      }
-      break;
-      
-    case 'posts':
-      phpbb2drupal_import_posts();
-      if (!variable_get('phpbb2drupal_import_post_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'posts';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'pm';
-      }
-      break;
-
-    case 'pm':      
-      phpbb2drupal_import_pm();
-      if (!variable_get('phpbb2drupal_import_pm_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'pm';
-      }
-      else {
-        $_SESSION['phpbb2drupal_selected'] = 'url';
-      }
-      break;
-    case 'url':
-      phpbb2drupal_replace_url();
-      if (!variable_get('phpbb2drupal_replace_url_successful', 0)) {
-        $_SESSION['phpbb2drupal_selected'] = 'url';
-      }
-      else {
-        drupal_set_message('Congratulations.  Import Finished');
-        drupal_set_message('Please visit the ' . l('Post migration configuration', 'admin/phpbb2drupal/postconfiguration'). ' page');
-        unset($_SESSION['phpbb2drupal_selected']);
-      }
-      break;
-    default:
-      $_SESSION['phpbb2drupal_selected'] = 'users';
-      break;
-  }
+  include_once dirname(__FILE__).'/phpbb2drupal_migrate_form_submit.inc.php';
+  return _phpbb2drupal_migrate_form_submit($form_id, $form_values);
 }
 
 /**
  * Private Message Import Functions
  */
 function phpbb2drupal_import_pm() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  $format = variable_get('phpbb2drupal_input_format', 0);
-  if (variable_get('phpbb2drupal_import_pm_successful', 0) == 1) {
-    return;
-  }
-  db_set_active('phpbb');
-  $query = "SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid, p.privmsgs_subject, pt.privmsgs_text, pt.privmsgs_bbcode_uid, p.privmsgs_date,
-      CASE WHEN p.privmsgs_type = 1 THEN 1
-      WHEN p.privmsgs_type = 5 THEN 1
-      ELSE 0
-      END as newmsg,
-      p.privmsgs_ip, 0, 0, 0
-      FROM %sprivmsgs p
-      LEFT JOIN %sprivmsgs_text AS pt ON p.privmsgs_id = pt.privmsgs_text_id";
-  $messages = db_query($query, $pre, $pre);
-  
-  db_set_active('default');
-  while ($pm = db_fetch_object($messages)) {    
-    $query = 'SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d';
-    $from_result = db_query($query, $pm->privmsgs_from_userid);
-    $from = db_result($from_result);
-    $to_result = db_query($query, $pm->privmsgs_to_userid);
-    $to = db_result($to_result);
-    // don't import private messages from or to users who are not imported.
-    if ($from and $to) {
-      // remove the bbcode_uid from post_text
-      $pm->privmsgs_text = preg_replace("/:$pm->privmsgs_bbcode_uid/", '', $pm->privmsgs_text);
-      $pm->privmsgs_text = _phpbb2drupal_strip_bbcode($pm->privmsgs_text);
-      $pm->privmsgs_text = _phpbb2drupal_text_encode($pm->privmsgs_text);
-      $pm->privmsgs_text = _phpbb2drupal_replace_links($pm->privmsgs_text);
-      $pm->privmsgs_subject = _phpbb2drupal_text_encode($pm->privmsgs_subject);
-      
-      $query = "INSERT INTO {privatemsg} ( id, author, recipient, subject, message, timestamp, newmsg, hostname, folder, author_del, recipient_del, format )
-          VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', 0, 0, 0 , %d)"; 
-      $result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject, 0, 64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip, 0, 255), $format);
-    }
-  }
-  variable_set('phpbb2drupal_import_pm_successful', 1);
-  return '<p>'. t('Private Message Import successful') .'</p>';
+  include_once dirname(__FILE__).'/phpbb2drupal_import_pm.inc.php';
+  return _phpbb2drupal_import_pm();
 }
 
 /**
  * User Import Functions
  */
 function phpbb2drupal_import_users() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  // check if the user database has been successfully imported
-  db_set_active('default');
-  if (variable_get('phpbb2drupal_import_user_successful', 0)) {
-    drupal_set_message(t('Users already imported successfully'));
-    return;
-  }  
-
-  if (variable_get('phpbb2drupal_import_user_started', 0) == 0) {
-    // create temporary tables
-    db_set_active('default');
-
-    // create profile fields for icq, aim, msn...etc
-    $querybase = 'INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES ';
-
-    $query = $querybase . "('YIM', 'user_yim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-
-    $query = $querybase . "('AIM', 'user_aim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-    
-    $query = $querybase . "('icq', 'user_icq', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-    
-    $query = $querybase . "('Website', 'user_website', '', 'Contact', '', 'url', 0, 0, 1, 2, '')";
-    db_query($query);
-
-    $query = $querybase . "('Location', 'user_from', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-
-    $query = $querybase . "('Occupation', 'user_occ', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-
-    $query = $querybase . "('Interests', 'user_interests', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
-    db_query($query);
-
-    variable_set('phpbb2drupal_import_user_started', 1);
-  }
-
-  db_set_active('default');
-  $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
-  db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
-
-  $files_path = variable_get('file_directory_path', 'files');
-  $pictures_path = variable_get('user_picture_path', 'pictures');
-
-  // Insert the users into drupal
-  db_set_active('phpbb');
-  $user_ids = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre);
-
-  $user_count = db_num_rows($user_ids);
-
-  if (!$user_count) {
-      drupal_set_message(t('There were no users found: Aborting script'), 'error');
-      return t('There were no users found: Aborting script.');
-  }
-
-  drupal_set_message(t('Found %user_count users: Beginning Import', array('%user_count' => $user_count + 1)));
-  
-  $import_spammers = variable_get('phpbb2drupal_import_spammers', 1);
-  
-  while ($result = db_fetch_object($user_ids)) {    
-
-    db_set_active('phpbb');
-    $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id));
-
-    // Make sure the user is not on the banlist
-    /* db_set_active('phpbb');
-    $banned = db_result(db_query("SELECT COUNT(*) FROM {banlist} WHERE ban_userid = %d", $user->user_id));
-    if ($banned) {
-        db_set_active('phpbb');
-        continue;
-    }*/
-
-    // If we don't want to import users who have never posted, break this while loop here.
-    if ($import_spammers == 1 || $user->user_posts != 0 ) {
-
-    // Make sure the user is has not already been imported
-    db_set_active('default');
-    $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $user->user_id));
-    if ($count > 0) {
-        $user->user_active = 0;
-    }
-
-    $user->user_aim = strtr($user->user_aim, array('+' => ' ')); # PHPBB stores spaces as +, replace with ' '
-    $user->user_yim = strtr($user->user_yim, array('+' => ' '));
-    $user->user_timezone = $user->user_timezone * 60 * 60;  # Drupal stores timezones in seconds
-
-    // remove the bbcode_uid from post_text
-    $user->user_sig = preg_replace("/:$user->user_sig_bbcode_uid/", '', $user->user_sig);
-
-    // if the $user->user_avatar_type is not their own image, delete it
-    // drupal doesn't have pre-defined avatars.   if we were to import it
-    // then multiple people would share the same avatar image and if one user 
-    // were to changes their avatar then it would change it for everybody else.
-    if ($user->user_avatar_type > 1) {
-        $user->user_avatar = '';
-    }
-
-    $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : '';
-
-    // remove the :bbcode_uid from signature
-    $signature = preg_replace("/:$post->bbcode_uid/", '', $user->user_sig);
-    $signature = _phpbb2drupal_strip_bbcode($signature);
-    $signature = _phpbb2drupal_text_encode($signature);
-    if (variable_get('phpbb2drupal_regdate_us_english', 0)) {
-      $user_regdate = strtotime($user->user_regdate);
-      $user_lastvisit = strtotime($user->user_lastvisit);
-      $user_session_time = strtotime($user->user_session_time);
-    }
-    else {
-      $user_regdate = $user->user_regdate;
-      $user_lastvisit = $user->user_lastvisit;
-      $user_session_time = $user->user_session_time;
-    }
-
-    $data = array(
-      'name' => substr($user->username, 0, 60),
-      'pass' => substr($user->user_password, 0, 32),
-      'mail' => substr($user->user_email, 0, 64),
-      'signature' => substr($signature, 0, 255),
-      'created' => $user_regdate,
-      'access' => $user_session_time,
-      'login' => $user_lastvisit,
-      'status' => $user->user_active,
-      'timezone' => $user->user_timezone, 
-      'picture' => $user->user_avatar,
-      'init' => substr($user->user_email, 0, 64),
-      'roles' => array(0 => 2),                       # Authenticated User
-      'user_website' => $user->user_website,
-      'user_from' => $user->user_from,
-      'user_icq' => $user->user_icq,
-      'user_aim' => $user->user_aim,
-      'user_yim' => $user->user_yim,
-      'user_msnm' => $user->user_msnm,
-      'user_occ' => $user->user_occ,
-      'user_interests' => $user->user_interest
-      );
-    if (variable_get('phpbb2drupal_import_pm', 0)) {
-      $data['privatemsg_allow'] = 1;
-    }
-    
-    $data['interests'] = _phpbb2drupal_text_encode($data['interests']);
-
-    db_set_active('default');
-    $drupal_user = phpbb2drupal_user_save($data, array('account', 'Personal', 'Contact'));
-
-    // populate the temporary user table
-    db_set_active('default');
-    db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES ( %d, %d )', $user->user_id , $drupal_user->uid);
-
-    db_set_active('phpbb');
-    }
-  }
-
-  // set the user import successful flag in the variable table
-  db_set_active('default');
-  variable_set('phpbb2drupal_import_user_successful', '1');
-
-  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user}'));
-  drupal_set_message(t('Successfully Imported %count Users', array('%count' => $count)));
+  include_once dirname(__FILE__).'/_phpbb2drupal_import_users.inc.php';
+  return _phpbb2drupal_import_users();
 }
 
 /**
  * Create Forum Containers and Forums
  */
 function phpbb2drupal_import_categories() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-
-  // check if the forum database has been successfully imported
-  db_set_active('default');
-  if (variable_get('phpbb2drupal_import_category_successful', 0)) {
-    drupal_set_message(t('Categories already imported successfully'));
-    return;
-  }    
-
-  // forum mapping temporary tables
-  if (variable_get('phpbb2drupal_import_category_started', 0) == 0) {
-    db_set_active('default');
-    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}');
-    //db_query("CREATE TABLE {phpbb2drupal_temp_forum} ( forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL, tid integer UNSIGNED DEFAULT '0' NOT NULL, KEY forum_id (forum_id))");
-    variable_set('phpbb2drupal_import_category_started', 1);
-  }
-
-  // Retrieve the vocabulary vid named "Forum"
-  $forum_vid = _forum_get_vid();
-
-  drupal_set_message(t('Forum vid: %forum_vid', array('%forum_vid' => $forum_vid)));
-
-  // Get Categories/Forums from PHPBB
-  db_set_active('phpbb');
-  $category_results = db_query('SELECT * FROM %scategories ORDER BY cat_order', $pre);
-  $cat_count = db_num_rows($category_results);
-  drupal_set_message(t('Found %cat_count categories: Beginning Import', array('%cat_count' => $cat_count)));
-  
-  $forum_count = 0;
-
-  while ($category_result = db_fetch_array($category_results)) {
-
-    $cat_id = $category_result['cat_id'];
-    $forums_results = db_query('SELECT * FROM %sforums WHERE cat_id = %d', $pre, $cat_id);
-    $forum_count += db_num_rows($forums_results);
-    $phpbb2_forums = array();  # reinitialize the temp var not to include it multiple times
-    while ($forum_result = db_fetch_object($forums_results)) {
-      //$phpbb2_categories[$category_result->cat_id]['forums'][] = $forums_result;
-      $phpbb2_forums[$forum_result->forum_id] = $forum_result;
-    }
-
-    $phpbb2_categories[$cat_id] = array_merge($category_result, array('forums' => $phpbb2_forums));
-  }
-
-  drupal_set_message(t('Found %forum_count forums: Beginning Import', array('%forum_count' => $forum_count)));
-
-  // Insert the Containers / Forum into Drupal
-  db_set_active('default');
-
-  // Insert the Containers
-  $container_order = -10;
-  foreach ($phpbb2_categories as $container) {
-    $edit = array(
-      'name' => $container['cat_title'],
-      'vid' => $forum_vid,
-      'description' => '',
-      'weight' => $container_order,
-    );
-    $edit['name'] = _phpbb2drupal_text_encode($edit['name']);
-
-    taxonomy_save_term($edit);
-
-    // serialize the forum containers
-    $containers = variable_get('forum_containers', array());
-    $containers[] = $edit['tid'];
-    variable_set('forum_containers', $containers); 
-
-    // Insert the Forums
-    $forum_order = -10;
-    foreach ($container['forums'] as $forum) {
-      // Make sure the forum/term is has not already been imported
-      if (!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum->forum_id))) {
-        $forum_edit = array(
-          'name' => $forum->forum_name,
-          'vid' => $forum_vid,
-          'description' => $forum->forum_desc,
-          'weight' => $forum_order,
-          'parent' => array($edit['tid']),
-        );
-        $forum_edit['name'] = _phpbb2drupal_text_encode($forum_edit['name']);
-        $forum_edit['description'] = _phpbb2drupal_text_encode($forum_edit['description']);
-
-        taxonomy_save_term($forum_edit);
-
-        $forum_order++;
-        $tid = $forum_edit['tid'];
-
-        db_set_active('default');
-        db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)', $forum->forum_id, $tid);
-      }
-    }
-
-    $container_order++;
-  }
-
-  db_set_active('default');
-  // set the forums import successful flag in the variable table
-  variable_set('phpbb2drupal_import_category_successful', '1');
-
-  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_forum}'));
-  drupal_set_message(t('Successfully Imported %count forums.', array('%count' => $count)));
+  include_once dirname(__FILE__).'/phpbb2drupal_import_categories.inc.php';
+  return _phpbb2drupal_import_categories();
 }
 
 /**
  * Imports PHPBB topics to Drupal equivalent forum nodes
  */
 function phpbb2drupal_import_topics() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
-  $input_format = variable_get('phpbb2drupal_input_format', 0);
-
-  // check if the post database has been successfully imported
-  db_set_active('default');
-  if (variable_get('phpbb2drupal_import_topic_successful', 0)) {
-    drupal_set_message(t('Topics already imported successfully'));
-    return;
-  }    
-
-  if (!variable_get('phpbb2drupal_import_topic_started', 0)) {
-    db_set_active('default');
-    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}');
-    //db_query("CREATE TABLE {phpbb2drupal_temp_topic} ( topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_id  mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, nid integer UNSIGNED DEFAULT '0' NOT NULL, KEY topic_id (topic_id))");
-    variable_set('phpbb2drupal_import_topic_started', 1);
-  }
-
-  // Get All topics from PHPBB
-  db_set_active('phpbb');
-  // topic_status == 2, Moved topics are duplicates don't import
-  $topic_ids = db_query('SELECT topic_id FROM %stopics WHERE topic_vote <> 1 ORDER BY topic_id', $pre);
-
-  $topic_count = db_num_rows($topic_ids);
-
-  drupal_set_message(t('Found %topic_count topics: Beginning Import', array('%topic_count' => $topic_count)));
-
-  // Import the topics into drupal
-  $counter = 0;
-  db_set_active('phpbb');
-  while ($result = db_fetch_object($topic_ids)) {
-      
-    // check if this topic has been imported already just to be sure
-    db_set_active('default');
-    $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $result->topic_id));
-    if ($count > 0) {
-      #print "<h3>Topic $result->topic_id has already been imported</h3>";    
-      #flush();
-      db_set_active('phpbb');
-      continue;
-    } 
-
-    db_set_active('phpbb');
-    /*$query = db_query("SELECT *
-      FROM {topics} t
-      INNER JOIN {posts} p ON t.topic_id = p.topic_id
-      INNER JOIN {posts_text} pt ON p.post_id = pt.post_id                            
-      WHERE t.topic_id = %d
-      ORDER BY p.post_id     
-      LIMIT 1", $result->topic_id); /**/
-
-    $query = db_query('SELECT *
-      FROM %stopics t
-      INNER JOIN %sposts p ON t.topic_id = p.topic_id
-      INNER JOIN %sposts_text pt ON p.post_id = pt.post_id                            
-      WHERE p.post_id = t.topic_first_post_id
-      AND t.topic_id = %d',$pre, $pre, $pre, $result->topic_id);
-      
-    // check if the topic is a valid topic.  if not, continue on
-    if (db_num_rows($query)) {
-        $topic = db_fetch_object($query);
-    }
-    else {
-      drupal_set_message(t('Could not find post details of topic: %topic_id', array('%topic_id' => $result->topic_id)));    
-      continue;
-    }
-    
-    db_set_active('default');
-    $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
-    $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
-
-    if ($topic->topic_poster == 2) {   // is the admin
-      $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
-      $uid = $user->uid;
-    }
-    else if ($topic->topic_poster == -1) {
-      $uid = 0;
-    }
-
-    if ($topic->topic_type == 1) {
-      $sticky = 1;      // sticky
-      $promote = 0;
-    }
-    else if ($topic->topic_type == 2) {
-      $sticky = 1;
-      $promote = 0;     // display on the front page, i.e. promote
-    }
-    else {
-      $sticky = 0;
-      $promote = 0;
-    }
-
-    if ($topic->topic_status == 1) { // LOCKED
-      $comment = 1;  // read-only
-    }
-    else { // UNLOCKED & WATCH NOTIFIED
-      $comment = 2;  // read-write
-    }
-
-    // remove the bbcode_uid from post_text
-    $topic->post_text = preg_replace("/:$topic->bbcode_uid/", '', $topic->post_text);
-    $topic->post_text = _phpbb2drupal_strip_bbcode($topic->post_text);
-    $topic->post_text = _phpbb2drupal_text_encode($topic->post_text);
-
-    $teaser = node_teaser($topic->post_text);
-
-    //construct the node
-    $node = array(
-      'type' => 'forum',
-      'title' => $topic->topic_title,
-      'uid' => $uid,
-      'status' => 1,  // published or not - always publish
-      'promote' => $promote,
-      'created' => $topic->topic_time,
-      'changed' => $topic->post_edit_time,
-      'comment' => $comment,
-      'moderate' => 0,
-      'body' => $topic->post_text,
-      'sticky' => $sticky,
-      'format' => $input_format,
-      'teaser' => $teaser,
-    );
-    $node['title'] = _phpbb2drupal_text_encode($node['title']);
-
-    if ($topic->topic_status == 2) {
-      db_set_active('phpbb');
-      $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
-      db_set_active('default');
-      $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
-
-      $node['tid'] = $moved_tid;        // which forum it used to be part of
-    }
-    else {
-      $node['tid'] = $tid;
-    }
-
-    $node = (object)$node; // node_save requires an object form
-
-    db_set_active('default');
-    node_save($node);
-    taxonomy_node_save($node->nid, array($tid));
-
-    if (!$node->nid) {
-      drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
-    }
-
-    // Handle attachments
-    if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
-      if ($topic->topic_attachment == 1) {
-
-        db_set_active('default');
-        $file_path = variable_get('file_directory_path', 'files');
-
-        db_set_active('phpbb');
-        $files = db_query('SELECT * 
-          FROM %sattachments a 
-          INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id
-          INNER JOIN %sposts p ON a.post_id = p.post_id 
-          WHERE p.topic_id = %d
-          ORDER BY a.attach_id', $pre, $pre, $pre, $topic->topic_id);
-
-        while ($file = db_fetch_object($files)) {
-          db_set_active('default');
-          $fid = db_next_id('{files}_fid');
-          db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, $node->nid, substr($file->real_filename0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
-          db_set_active('phpbb');
-        }
-      }
-    }
-
-    db_set_active('default');
-    db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
-
-    db_set_active('phpbb');
-  }  // while ($result = db_fetch_object($topic_ids))
-
-  db_set_active('default');
-  // set the topic import successful flag in the variable table
-  variable_set('phpbb2drupal_import_topic_successful', '1');
-
-  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_topic}'));
-  drupal_set_message(t('Successfully Imported %count topics', array('%count' => $count)));
+  include_once dirname(__FILE__).'/phpbb2drupal_import_topics.inc.php';
+  return _phpbb2drupal_import_topics();
 }
 
 /**
  * Imports phpBB polls into drupal
  */
 function phpbb2drupal_import_polls() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  $input_format = variable_get('phpbb2drupal_input_format', 0);
-  db_set_active('default');
-
-  // check if the poll database has been successfully imported
-  if (variable_get('phpbb2drupal_import_polls_successful', 0)) {
-    drupal_set_message(t('Polls already imported successfully'));
-    return;
-  }    
-
-  if (!variable_get('phpbb2drupal_import_polls_started', 0)) {
-      variable_set('phpbb2drupal_import_poll_started', 1);
-  }
-
-  // Get all polls from PHPBB
-  db_set_active('phpbb');
-  $topics = db_query('SELECT * FROM %stopics t WHERE topic_vote = 1 ORDER BY topic_id', $pre);
-  $topic_count = db_num_rows($topics);
-  drupal_set_message(t('Found %poll_count polls: Beginning Import', array('%poll_count' => $topic_count)));
-
-  // insert into polls
-  while ($topic = db_fetch_object($topics)) {
-
-    // check if this topic has been imported already just to be sure
-    db_set_active('default');
-    $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $topic->topic_id));
-    if ($count > 0) {
-      drupal_set_message(t('Poll %topic_id has already been imported', array('%topic_id' => $result->topic_id)));    
-      db_set_active('phpbb');
-      continue;
-    } 
-
-    // get the polls 
-    db_set_active('phpbb');
-    $query = db_query('SELECT * FROM %svote_desc vd WHERE topic_id = %d ORDER BY vote_id', $pre, $topic->topic_id); 
-
-    if (db_num_rows($query)) {
-      $poll = db_fetch_object($query);
-    }
-    else {
-      drupal_set_message(t('Could not find details of poll: %topic_id', array('%topic_id' => $topic->topic_id)));    
-      continue;
-    }
-
-    // get vote results
-    $query = db_query('SELECT * FROM %svote_results WHERE vote_id = %d ORDER BY vote_option_id', $pre, $poll->vote_id);
-
-    if (db_num_rows($query)) {
-      $choice = array();
-      while ($result = db_fetch_object($query)) {
-        $choice[] = array(
-          'chtext' => _phpbb2drupal_text_encode($result->vote_option_text),
-          'chvotes' => _phpbb2drupal_text_encode($result->vote_result),
-        );
-      }
-    }
-    else {
-        drupal_set_message(t('Could not find vote_results details of poll: %vote_id', array('%vote_id' => $poll->vote_id)));    
-        continue;
-    }
-
-    db_set_active('default');
-    $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
-    $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
-
-    if ($topic->topic_poster == 2) {   // is the admin
-      $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
-      $uid = $user->uid;
-    }
-    else if ($topic->topic_poster == -1) {
-      $uid = 0;
-    }
-
-    if ($topic->topic_type == 1) {
-      $sticky = 1;      // sticky
-      $promote = 0;
-    }
-    else if ($topic->topic_type == 2) {
-      $sticky = 0;
-      $promote = 1;     // display on the front page, i.e. promote
-    }
-    else {
-      $sticky = 0;
-      $promote = 0;
-    }
-
-    if ($topic->topic_status == 1) { // LOCKED
-      $comment = 1;  // read-only
-    }
-    else { // UNLOCKED & WATCH NOTIFIED
-      $comment = 2;  // read-write
-    }
-
-    //construct the node
-    $node = array(
-      'type' => 'poll',
-      'title' => $poll->vote_text,
-      'uid' => $uid,
-      'status' => 1,  // published or not - always publish
-      'promote' => $promote,
-      'created' => $topic->topic_time,
-      'changed' => $topic->topic_time,
-      'comment' => $comment,
-      'moderate' => 0,
-      'body' => '',
-      'format' => $input_format,
-      'sticky' => $sticky,
-//      'teaser' => $teaser
-    );
-    $node['title'] = _phpbb2drupal_text_encode($node['title']);
-
-
-    // handle moved nodes
-    if ($topic->topic_status == 2) {
-      db_set_active('phpbb');
-      $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
-      db_set_active('default');
-      $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
-
-      $node['tid'] = $moved_tid;        // which forum it used to be part of
-    }
-    else {
-      $node['tid'] = $tid;
-    }
-
-    // Add poll node information
-    $node['runtime'] = $poll->vote_length;
-    $node['active'] = (time() > ($poll->start + $poll->length)) ? 0 : 1;
-    $node['choice'] = $choice;
-
-    $node = (object)$node; // node_save requires an object form
-    
-    db_set_active('default');
-    node_save($node);
-    taxonomy_node_save($node->nid, array($tid));
-
-    if (!$node->nid) {
-      drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
-    }
-
-
-    // get voter information
-    db_set_active('phpbb');
-    $query = db_query('SELECT vote_user_id FROM %svote_voters WHERE vote_id = %d ORDER BY vote_id', $pre, $poll->vote_id);
-
-    // manually update the poll table to store the uid of those who voted
-    if (db_num_rows($query)) {
-      db_set_active('phpbb');
-      while ($result = db_fetch_object($query)) {
-        db_set_active('default');
-        $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $result->vote_user_id));
-        $result = db_query('INSERT INTO {poll_votes} (nid, uid, hostname) VALUES (%d, %d, \'NA\')', $node->nid, $uid);
-        db_set_active('phpbb');
-      }
-    }
-
-    db_set_active('default');
-    db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
-    phpbb2_drupal_poll_insert($node);
-
-
-    db_set_active('phpbb');
-  }
-
-  db_set_active('default');
-  // set the topic import successful flag in the variable table
-  variable_set('phpbb2drupal_import_poll_successful', '1');
-
-  drupal_set_message(t('Successfully imported polls'));
+  include_once dirname(__FILE__).'/phpbb2drupal_import_polls.inc.php';
+  return _phpbb2drupal_import_polls();
 }
 
 /**
  * PHPBB Posts --> Drupal Comments
  */
 function phpbb2drupal_import_posts() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-  $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
-
-  db_set_active('default');
-  // check if the post database has been successfully imported
-  if (variable_get('phpbb2drupal_import_post_successful', 0)) {
-    drupal_set_message(t('Posts already imported successfully'));
-    return;
-  }    
-
-  if (!variable_get('phpbb2drupal_import_post_started', 0)) {
-    db_set_active('default');
-    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_post}');
-    /*db_query("CREATE TABLE {phpbb2drupal_temp_post} (
-                post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
-                cid int(10) DEFAULT '0' NOT NULL,
-                KEY post_id (post_id))"  
-            );
-     */
-    db_set_active('default');
-    variable_set('phpbb2drupal_import_post_started', 1);
-  }
-
-  db_set_active('phpbb');
-  $topic_ids = db_query('SELECT topic_id, topic_vote, topic_first_post_id, topic_last_post_id
-    FROM %stopics 
-    WHERE topic_replies > 0
-    ORDER BY topic_id', $pre);
-
-  $topic_count = db_num_rows($topic_ids);
-  drupal_set_message(t('Found %post_count posts: Beginning Import', array('%post_count' => $topic_count)));
-
-  $errors = 0;
-  $loops = 0;
-  // Import the posts into drupal
-  while ($obj = db_fetch_object($topic_ids)) {
-    $loops++;
-
-    // skip first post if the post is not a poll
-    // stupid phpbb... make the way you store topics consistent for crying out loud
-    db_set_active('phpbb');
-    if ($obj->topic_vote == 0) {
-      $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d AND post_id <> %d ORDER BY post_id',
-        $pre, $obj->topic_id, $obj->topic_first_post_id);
-    }
-    else {
-      $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d ORDER BY post_id', $pre, $obj->topic_id);
-    }
-
-    unset($obj);
-
-    while ($result = db_fetch_object($post_ids)) {
-      $loops++;
-
-      db_set_active('phpbb');
-      /*
-		$query = db_query("SELECT * FROM {posts} p INNER JOIN {posts_text} pt ON p.post_id = pt.post_id WHERE p.post_id = %d", $result->post_id);
-      //*/
-
-      $query = db_query('SELECT * FROM %sposts p, %sposts_text pt WHERE p.post_id = pt.post_id AND p.post_id = %d',
-        $pre, $pre, $result->post_id);
-
-      // make sure the post is valid
-      if (db_num_rows($query)) {
-        $post = db_fetch_object($query);
-      }
-      else {
-        $errors++;
-        drupal_set_message(t("Couldn't find post text for %post_id", array('%post_id' => $result->post_id)));
-        continue;
-      }
-
-      // skip if the post has already been imported
-      db_set_active('default');
-      $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post->post_id));
-      if ($count > 0) {
-        $errors++;
-        drupal_set_message(t('Post %post_id was already inserted', array('%post_id' => $post->post_id)));
-        db_set_active('phpbb');
-        continue;
-      }
-
-      db_set_active('default');
-      $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $post->poster_id));
-      $pid = db_result(db_query('SELECT MAX(pid) FROM {comments} WHERE nid = %d', $nid));
-      // get the node ID. The title may be useful further down if the comment doesn't have its own title.
-      $node = (db_fetch_object(db_query('SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid  WHERE topic_id = %d', $post->topic_id)));
-      $nid = $node->nid;
-
-      $pid = (is_null($pid)) ? 0 : $pid;
-
-      if ($post->poster_id == 2) {   // is the admin
-        $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
-        $uid = $user->uid;
-      }
-      else if ($post->poster_id == -1) { // anonymous
-        $uid = 0; 
-      }    
-
-      $hostname = phpbb2drupal_decode_ip($post->poster_ip);
-
-      // remove the :bbcode_uid from post_text
-      $post->post_text = preg_replace("/:$post->bbcode_uid/", '', $post->post_text);
-      $post->post_text = _phpbb2drupal_strip_bbcode($post->post_text);
-      $post->post_text = _phpbb2drupal_text_encode($post->post_text);
-      $post->post_subject = _phpbb2drupal_text_encode($post->post_subject);
-
-      //construct the node
-      $comment = array(
-        'pid' => $pid,
-        'nid' => $nid,
-        'uid' => $uid,
-        'subject' => $post->post_subject,
-        'comment' => $post->post_text,
-        'hostname' => $hostname,
-        'timestamp' => $post->post_time
-      );
-
-      // if the title field is empty, use the node title as default.
-      if (empty($comment['subject'])) {
-        $comment['subject'] = $node->title;
-      }
-
-      db_set_active('default');
-      $cid = phpbb2drupal_comment_save($comment);
-
-      if (!$cid) {
-        $errors++;
-        drupal_set_message(t('Failed importing %post_id', array('%post_id' => $post->post_id)));
-      }
-            
-      // Handle attachments
-      if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
-        if ($post->post_attachment == 1) {
-          db_set_active('default');
-          $file_path = variable_get('file_directory_path', 'files');
-
-          db_set_active('phpbb');
-          $files = db_query('SELECT * FROM %sattachments a INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id WHERE a.post_id = %d',
-            $pre, $pre, $post->post_id);
-
-          while ($file = db_fetch_object($files)) {
-            db_set_active('default');
-            $fid = db_next_id('{files}_fid');
-            db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, 0, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
-            db_query('INSERT INTO {comment_files} (cid, fid) VALUES (%d, %d)', $cid, $fid);
-            db_set_active('phpbb');
-          }        
-        }
-      }
-
-      db_set_active('default');
-      db_query('INSERT INTO {phpbb2drupal_temp_post} (post_id, cid) VALUES (%d, %d)', $post->post_id, $cid);
-
-      db_set_active('phpbb');
-    }
-  }
-
-  // set the post import successful flag in the variable table
-  db_set_active('default');
-  variable_set('phpbb2drupal_import_post_successful', '1');
-  drupal_set_message(t('Successfully Imported %imported posts', array('%imported' => $imported)));
-  drupal_set_message(t('The were %loops loops executed', array('%loops' => $loops)));
-  drupal_set_message(t('There %errors errors while importing posts', array('%errors' => $errors)));
+  include_once dirname(__FILE__).'/phpbb2drupal_import_posts.inc.php';
+  return _phpbb2drupal_import_posts();
 }
 
 /**
  * Clean UP
  */
 function phpbb2drupal_import_cleanup() {
-  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
-
-  #
-  # Update Drupal sequence 
-  #
-  db_set_active('default');
-  $term_data_tid = db_result(db_query('SELECT MAX(tid) FROM {term_data}'));
-  $comments_cid = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
-  $node_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
-  $users_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
-
-  db_query("DELETE FROM {sequences} WHERE name='term_data_tid'");
-  db_query("DELETE FROM {sequences} WHERE name='comments_cid'");
-  db_query("DELETE FROM {sequences} WHERE name='node_nid'");
-  db_query("DELETE FROM {sequences} WHERE name='users_uid'");
-
-  db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', '%s')", $term_data_tid);
-  db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', '%s')", $comments_cid);
-  db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', '%s')", $node_nid);
-  db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', '%s')", $users_uid);
-
-  if (variable_get('phpbb2drupal_import_attachments', 0)) {
-    $files_fid = db_result(db_query('SELECT MAX(fid) FROM {files}'));
-    if (!$files_fid) { //may be NULL
-      $files_fid = 0;
-    }
-    db_query("DELETE FROM {sequences} WHERE name='files_fid'");
-    db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', '%s')", $files_fid);
-  }
-  
-  // don't DROP: the data is used for redirects from old forum.
-  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_user}");
-  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}");
-  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}");
-  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_post}");
-
-  variable_del('phpbb2drupal_import_user_successful');
-  variable_del('phpbb2drupal_import_user_started');
-  variable_del('phpbb2drupal_import_category_successful');
-  variable_del('phpbb2drupal_replace_url_successful');
-  variable_del('phpbb2drupal_import_category_started');
-  variable_del('phpbb2drupal_import_topic_successful');
-  variable_del('phpbb2drupal_import_topic_started');
-  variable_del('phpbb2drupal_import_post_successful');
-  variable_del('phpbb2drupal_import_post_started');
-  variable_del('phpbb2drupal_ready');
-  variable_del('phpbb2drupal_regdate_us_english');
-  variable_del('phpbb2drupal_input_format');
-  variable_del('phpbb2drupal_db_url');
-  variable_del('phpbb2drupal_tested');
-  variable_del('phpbb2drupal_same_db');
-  variable_del('phpbb2drupal_table_prefix');
-  variable_del('phpbb2drupal_time_limit');
-  variable_del('phpbb2drupal_import_spammers');
-  variable_del('phpbb2drupal_import_attachments');
-  variable_del('phpbb2drupal_import_polls'); 
-  variable_del('phpbb2drupal_import_pm');
-  variable_del('phpbb2drupal_import_poll_started');
-  variable_del('phpbb2drupal_import_poll_successful');
-  variable_del('phpbb2drupal_import_pm_successful');
-  variable_del('phpbb2drupal_admin_user');
-  variable_del('phpbb2drupal_encode');
-  variable_del('phpbb2drupal_encoding_phpbb');
-  variable_del('phpbb2drupal_encoding_drupal');
-
-  db_query('DELETE FROM {cache}');
+  include_once dirname(__FILE__).'/phpbb2drupal_import_cleanup.inc.php';
+  return _phpbb2drupal_import_cleanup();
 }
 
 /**
diff -urpN phpbb2drupalpatch1/phpbb2drupal_admin_settings.inc.php phpbb2drupalpatch2/phpbb2drupal_admin_settings.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_admin_settings.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_admin_settings.inc.php	2007-12-23 21:39:41.253098700 +0000
@@ -0,0 +1,514 @@
+<?php
+/**
+ * Callback admin/phpbb2drupal/configure
+ */
+function _phpbb2drupal_admin_settings() {
+  global $conf ;
+  global $db_url;
+  $stage = variable_get('phpbb2drupal_config_stage', 0); 
+
+  //We'll be checking that the setup is complete.
+  //If it is not complete, the migration will not go ahead.
+  $ready_for_migration = 1;
+
+  // Checking that the migration has been tested on a copy first.
+  $form['test'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Test on copy first'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+    
+  $output = '';
+  if (!variable_get('phpbb2drupal_tested', 0)) {
+    $form['test']['#collapsed']= FALSE;
+    $output = '<span class="marker">';
+    $ready_for_migration = 0;
+  }
+  $output .= t('<p>The migration will modify and even destroy some data. You must test this module on a copy of your data first, several times if necessary. Only use this module on your live data when you are familiar with the procedure and you\'re confident everything will run smoothly.</p>
+  <p>Also, you should make a full backup of your database just prior to permorming the migration on the live data. It is better to turn off both the phpBB board and the Drupal site during the migration.</p>');
+  if (!variable_get('phpbb2drupal_tested', 0)) {
+    $output .= '</span>';
+  }
+  $form['test']['intro'] = array('#value' => $output);
+  $output = '';
+
+  $form['test']['phpbb2drupal_tested'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('I am running a trial migration on a disposable copy of the database OR I have already done so and I am running this on my live site, confident that the migration will proceed smoothly'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_tested', 0),
+    '#description' => '',
+  ); 
+
+  // Input format settings
+  $form['input'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Input Format settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $output = '<p>'. t('Select which <a href="@link">input format</a> should the imported messages be set:', array('@link' => url('admin/filters'))) .'</p>';
+  $form['input']['intro'] = array('#value' => $output);
+  $output = '';
+
+  $input_formats = array(0 => t('not set yet'));
+  $sql = 'SELECT format, name FROM {filter_formats}';
+  $result = db_query($sql);
+  while ($format = db_fetch_array($result)) {
+    $input_formats[$format['format']]= $format['name'];
+  }
+  $input_format = variable_get('phpbb2drupal_input_format', 0);
+  $form['input']['phpbb2drupal_input_format'] = array(
+    '#type' => 'radios',
+    '#title' => t('Input format'),
+    '#default_value' => $input_format,
+    '#options' => $input_formats,
+  );
+  if (!$input_format) {
+    $ready_for_migration = 0;
+    $form['input']['#collapsed']= FALSE;
+  }
+  $output .= '<p><em>'. t('This setting will be applied to all posts and private messages.') .'</em></p>';
+  $form['input']['result'] = array('#value' => $output);
+
+
+  // BBcode settings
+  $form['bbcode'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('BBcode settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+  $output = t('<p>pbpBB2 posts are often formatted in BBcode. During the import process, BBcode can be handled in two diffent ways:</p>
+    <ul><li>You can leave the BBcode as is, and use the <a href="http://drupal.org/project/bbcode" target="_blank">bbcode module</a> after the migration to filter the imported posts. In this case, the module is not required during the migration but you will need to install it and configure it later.</li>
+    <li>You can decide to have the BBcode filtered now and replaced by plain HTML. The BBcode module will be required during the migration process, but you can disable it later.</li>    </ul>
+    <p>Which one do you choose?</p>
+    <p>Also, make sure to choose the proper input filter, for it will affect how the post is displayed. For example, if you choose to strip the bbcode altogether and use HTML instead, some HTML tags will be stripped by the "filtered HTML" input format, unless you add those tags in the list of allowed tags. Using "Full HTML" is recommanded for the imported posts when doing away with bbcode.</p>');
+  $form['bbcode']['intro'] = array('#value' => $output);
+  $form['bbcode']['phpbb2drupal_bbcode'] = array(
+    '#type' => 'radios',
+    '#title' => t('BBcode handling'),
+    '#default_value' => variable_get('phpbb2drupal_bbcode', 0),
+    '#options' => array(t('Leave BBcode as is.'), t('Transform BBcode into HTML.')),
+    '#description' => '',
+  );
+  $output = '';
+  $result7 = _phpbb2drupal_check_module('bbcode');
+  $output .= $result7['html'];
+  $link_input_format_enable = url('admin/filters/'.$input_format);
+  $link_input_format_configure = url('admin/filters/'.$input_format.'/configure');
+  if (variable_get('phpbb2drupal_bbcode', 0)) { 
+    if ($result7['result'] == 0) {
+      $ready_for_migration = 0;
+      $form['bbcode']['#collapsed']= FALSE;
+      $output .= '<p><span class="marker">';
+      $output .= t('<a href="http://drupal.org/project/bbcode" target="_blank">The bbcode module</a> is required to transform BBcode into HTML. 
+        You first need to <a href="@adminmodules">enable the bbcode module</a>', array('@adminmodules' => url('admin/modules')));
+      $output .= '</span></p>';
+    }
+    $sql = 'SELECT * FROM {filters} WHERE module = \'bbcode\' AND format = %d';
+    $result = db_query($sql, $input_format);
+    if (!db_num_rows($result)) {
+      $form['bbcode']['#collapsed']= FALSE;
+      $output .= '<p class="marker">'. t('You need to <a href="@formatenable">enable bbcode in the selected input format</a> <a href="@formatconfigure">THEN click on configure to see bbcode options</a>', array('@formatenable' => $link_input_format_enable, '@formatconfigure' => $link_input_format_configure)) .'</p>';
+    }
+    $output .= '<p>'. t('For best results, <a href="@bbcodeconfig">all four BBcode configure options should be disabled</a>.', array('@bbcodeconfig' => url('admin/filters/'. $input_format .'/configure'))) .'</p>';
+    
+  }
+  else {
+    if ($result7['result'] == 0) {
+      $form['bbcode']['#collapsed']= FALSE;
+      $output .= '<p>'. t('<a href="http://drupal.org/project/bbcode" target="_blank">The bbcode module</a> is only recommanded. You may <a href="@adminmodules">enable the bbcode module</a> after having installed it.', array('@adminmodules' => url('admin/modules'))) .'</p>';
+    }
+    $output .= t('<p>Don\'t forget to <a href="@formatenable">enable bbcode in the selected input format</a> (admin > input formats > configure) and enable bbcode for the format selected for the imported posts.  <a href="@formatconfigure">Then click on configure to see bbcode options</a></p>
+      <p>You may want to enable it for other input formats, too.</p>', array('@formatenable' => $link_input_format_enable, '@formatconfigure' => $link_input_format_configure));
+  }
+  $output .= '<p><em>'. t('This setting will be applied to all posts, private messages and the users\' signature.') .'</em></p>';
+  $form['bbcode']['result'] = array('#value' => $output);
+
+  
+
+  // Drupal Modules settings
+  $form['modules'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Drupal modules'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $output = '<p>';
+  $result1 = _phpbb2drupal_check_module('forum');
+  $output .= $result1['html'];
+  $result2 = _phpbb2drupal_check_module('node');
+  $output .= $result2['html'];
+  $result3 = _phpbb2drupal_check_module('comment');
+  $output .= $result3['html'];
+  $result4 = _phpbb2drupal_check_module('user');
+  $output .= $result4['html'];
+  $result5 = _phpbb2drupal_check_module('profile');
+  $output .= $result5['html'];
+  $result6 = _phpbb2drupal_check_module('taxonomy');
+  $output .= $result6['html'];
+  $output .= '</p>';
+
+  if ($result1['result'] == 0 || $result2['result'] == 0 || $result3['result'] == 0 || $result4['result'] == 0 || $result5['result'] == 0 || $result6['result'] == 0) {
+    $ready_for_migration = 0;
+    $form['modules']['#collapsed']= FALSE;
+    $output .= '<p class="marker">';
+    $output .= t('Some of the modules are not enabled. <a href="@adminmodules">Got to the admin/modules page to enable them</a>', array('@adminmodules' => url('admin/modules')));
+    $output .= '</p>';
+  }
+  $form['modules']['result'] = array('#value' => $output);
+  $output = '';
+
+  // Where is phpbb2?
+  $form['phpbb2'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Location of phpBB2 data'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['phpbb2']['phpbb2drupal_same_db'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('phpbb is on the same database as drupal'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_same_db', 1),
+    '#description' => '',
+  );
+  if (variable_get('phpbb2drupal_same_db', 1) != 1) {
+    $url = variable_get('phpbb2drupal_db_url', $db_url);
+    if ($url == $db_url) {
+      $output = '<p class="marker">'. t('Set the address of the phpBB database according to the following format: <br /><pre>mysql://phpbb_username:phpbb_password@localhost/phpbb_database</pre>') .'</p>';
+      $ready_for_migration = 0;
+      $form['phpbb2']['#collapsed']= FALSE;
+    }
+
+    $form['phpbb2']['phpbb2drupal_db_url'] = array(
+      '#type' => 'textfield',
+      '#title' => t('phpBB2 database location'),
+      '#default_value' => variable_get('phpbb2drupal_db_url', $db_url),
+      '#size' => 80,
+      '#maxlength' => 255,
+      '#description' => '',
+    );
+  }
+
+  $output = t('<p>Note that due to a limitation within Drupal core, we cannot import messages from one database type to another database type. E.g, we cannot import phpBB from a myqsl DB, to a postgresql DB. You need to import the data into the same type of database first (import all the phpBB data, as is, from mysql to postgresql.</p>
+    <p>If both phpBB and Drupal are on postgresql, see <a href="http://drupal.org/node/64877">this issue</a>.</p>');
+  $form['phpbb2']['note'] = array('#value' => $output);
+  
+  // phpBB2 table prefix
+  $output = '';
+  $form['phpbb2']['phpbb2drupal_table_prefix'] = array(
+    '#type' => 'textfield',
+    '#title' => t('phpBB2 table prefix'),
+    '#default_value' => variable_get('phpbb2drupal_table_prefix', 'phpbb_'),
+    '#size' => 20,
+    '#maxlength' => 255,
+    '#description' => t('What prefix is used for your phpBB2 tables?'),
+  );
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  $tables = array($pre.'categories', $pre.'forums', $pre.'posts', $pre.'posts_text', $pre.'topics', $pre.'users');
+  $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
+  $output .= $result['html'];
+  
+  if ($result['result'] != 1) {
+    $ready_for_migration = 0;
+    $form['phpbb2']['#collapsed']= FALSE;
+    $output .= '<span class="marker">';
+    $output .= t("Some tables couldn't be found. Please correct the errors so that the phpBB2 tables can be accessed.");
+    $output .= '</span>';
+  }
+  $form['phpbb2']['result'] = array('#value' => $output);
+
+
+  
+  // Misc.	
+  $form['misc'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Misc. settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+  // Time limit 
+  $output = '';
+  //Registration date format
+  $form['misc']['phpbb2drupal_regdate_us_english'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Convert Registration Date'),
+    '#default_value' => variable_get('phpbb2drupal_regdate_us_english', 0),
+    '#return_value' => 1,
+    '#description' => t('If you find out that the registration date for ALL your users is over 36 years ago, maybe your DB stores the registration date in the English US format (like: "Sep 11, 2001") instead as a linux timestamp (like: "1152568884"). If so, check this box.'),
+  );
+  $form['misc']['phpbb2drupal_time_limit'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Time limit'),
+    '#default_value' => variable_get('phpbb2drupal_time_limit', 1200),
+    '#size' => 7,
+    '#maxlength' => 10,
+    '#description' => t('How long, in seconds, will the migration take?'),
+  );
+  $form['misc']['info'] = array(
+    '#value' => '<p>'. t('1200 = 20 minutes should be enough for most boards. It worked well for a board with 300,000 rows. Beware: if your site is cohosted and safe-mode is on, then this value will have no effect.') .'</p>',
+  );
+  
+  // USERS settings
+  $form['users'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('User import'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  // User to map admin user too
+  $drupal_admin = user_load(array('uid' => 1));
+  $form['users']['phpbb2drupal_admin_user'] = array(
+    '#title' => t('User to map phpBB admin'),
+    '#type' => 'textfield',
+    '#autocomplete_path' => 'user/autocomplete',
+    '#default_value' => variable_get('phpbb2drupal_admin_user', $drupal_admin->name ),
+  );
+  
+
+  // Import users who have never posted?
+  $form['users']['phpbb2drupal_import_spammers'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Import users who have never posted?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_import_spammers', 1),
+    '#description' => '',
+  );
+ 
+  //Polls
+  $form['polls'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Polls import'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['polls']['phpbb2drupal_import_polls'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Import polls?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_import_polls', 0),
+    '#description' => '',
+  );
+  if (variable_get('phpbb2drupal_import_polls', 0) == 1) {
+    //poll modules
+    $result = _phpbb2drupal_check_module('poll');
+    $output .= $result['html'];
+    if ($result['result'] != 1) {
+      $ready_for_migration = 0;
+      $form['polls']['#collapsed'] = FALSE;
+      $output .= '<span class="marker">';
+      $output .= t('Please enable the poll module.') ;
+      $output .= '</span>';
+    }
+    $form['polls']['info'] = array('#value' => $output);
+  }
+  
+ 
+  //Attachements
+  $output ='';
+  $form['attachments'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Attachments import'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['attachments']['phpbb2drupal_import_attachments'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Import attachments?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_import_attachments', 0),
+    '#description' => '',
+  );
+  if (variable_get('phpbb2drupal_import_attachments', 0) == 1) {
+    // Comment attachments module
+    $result = _phpbb2drupal_check_module('comment_upload');
+    $output .= $result['html'];
+    if ($result['result'] != 1) {
+      $ready_for_migration = 0;
+      $form['attachments']['#collapsed']= FALSE;
+      $output .= '<span class="marker">';
+      $output .= t('The comment_upload.module is not enabled. You can <a href="http://drupal.org/node/37197" target="_blank">go to the module Home Page to download it</a>. <a href="@adminmodules">After having installed it, go to the admin/module page to enable it</a>', array('@adminmodules' => url('admin/modules')));
+      $output .= '</span>';
+    }
+  }
+  
+  // Encoding
+  $form['encoding'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Encoding setting',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+ //DEBUG http://php.net/extension_loaded 
+ if (!extension_loaded('mbstring') && variable_get('phpbb2drupal_encode', '1')) {
+   $ready_for_migration = 0;
+   $form['encoding']['#collapsed']= FALSE;
+   $output .= '<p class="marker">';
+   $output .= t("The php mbstring module is not installed on this server: the posts' encoding cannot be changed during the migration.");
+   $output .= '</p>';
+ }
+
+  $encodings = array(
+    'utf-8' => 'utf-8',
+    'iso-8859-1' => 'iso-8859-1',
+    'UCS-4' => 'UCS-4',
+    'UCS-4BE' => 'UCS-4BE',
+    'UCS-4LE' => 'UCS-4LE',
+    'UCS-2' => 'UCS-2',
+    'UCS-2BE' => 'UCS-2BE',
+    'UCS-2LE' => 'UCS-2LE',
+    'UTF-32' => 'UTF-32',
+    'UTF-32BE' => 'UTF-32BE',
+    'UTF-32LE' => 'UTF-32LE',
+    'UTF-16' => 'UTF-16',
+    'UTF-16BE' => 'UTF-16BE',
+    'UTF-16LE' => 'UTF-16LE',
+    'UTF-7' => 'UTF-7',
+    'UTF7-IMAP' => 'UTF7-IMAP',
+    'ASCII' => 'ASCII',
+    'EUC-JP' => 'EUC-JP',
+    'SJIS' => 'SJIS',
+    'eucJP-win' => 'eucJP-win',
+    'SJIS-win' => 'SJIS-win',
+    'ISO-2022-JP' => 'ISO-2022-JP',
+    'JIS' => 'JIS',
+    'ISO-8859-2' => 'ISO-8859-2',
+    'ISO-8859-3' => 'ISO-8859-3',
+    'ISO-8859-4' => 'ISO-8859-4',
+    'ISO-8859-5' => 'ISO-8859-5',
+    'ISO-8859-6' => 'ISO-8859-6',
+    'ISO-8859-7' => 'ISO-8859-7',
+    'ISO-8859-8' => 'ISO-8859-8',
+    'ISO-8859-9' => 'ISO-8859-9',
+    'ISO-8859-10' => 'ISO-8859-10',
+    'ISO-8859-13' => 'ISO-8859-13',
+    'ISO-8859-14' => 'ISO-8859-14',
+    'ISO-8859-15' => 'ISO-8859-15',
+    'byte2be' => 'byte2be',
+    'byte2le' => 'byte2le',
+    'byte4be' => 'byte4be',
+    'byte4le' => 'byte4le',
+    'BASE64' => 'BASE64',
+    'HTML-ENTITIES' => 'HTML-ENTITIES',
+    '7bit' => '7bit',
+    '8bit' => '8bit',
+    'EUC-CN' => 'EUC-CN',
+    'CP936' => 'CP936',
+    'HZ' => 'HZ',
+    'EUC-TW' => 'EUC-TW',
+    'CP950' => 'CP950',
+    'BIG-5' => 'BIG-5',
+    'EUC-KR' => 'EUC-KR',
+    'UHC (CP949)' => 'UHC (CP949)',
+    'ISO-2022-KR' => 'ISO-2022-KR',
+    'Windows-1251 (CP1251)' => 'Windows-1251 (CP1251)',
+    'Windows-1252 (CP1252)' => 'Windows-1252 (CP1252)',
+    'CP866 (IBM866)' => 'CP866 (IBM866)',
+    'KOI8-R' => 'KOI8-R',
+   );
+  
+  $form['encoding']['phpbb2drupal_encode'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Change encoding of text strings during the import'),
+    '#default_value' => variable_get('phpbb2drupal_encode', '1'),
+  );
+
+  $output .= '<p>'. t('This setting is useful when the phpBB2 encoding is not the same as the Drupal encoding. <strong>You server must have the <em>php mbstring module</em> installed.</strong>') .'</p>';
+  $form['encoding']['info'] = array(
+    '#value' => $output 
+  );
+  
+  $form['encoding']['phpbb2drupal_encoding_phpbb'] = array(
+    '#type' => 'select',
+    '#title' => t('phpBB2 encoding'),
+    '#default_value' => variable_get('phpbb2drupal_encoding_phpbb', 'iso-8859-1'),
+    '#options' => $encodings,
+  );
+
+  $form['encoding']['phpbb2drupal_encoding_drupal'] = array(
+    '#type' => 'select',
+    '#title' => t('Drupal encoding'),
+    '#default_value' => variable_get('phpbb2drupal_encoding_drupal', 'utf-8'),
+    '#options' => $encodings,
+  );
+
+  // Private messages
+  $output = '';
+  $form['pm'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Private Messages'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['pm']['phpbb2drupal_import_pm'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Import private messages?'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('phpbb2drupal_import_pm', 0),
+    '#description' => '',
+  );
+  if (variable_get('phpbb2drupal_import_pm', 0) == 1) {
+
+     // Private messages module
+      $output = '<p>'. t('If you want to use the private message module, make sure to configure it properly (admin > settings> private messages) and allow user to view their own private messages (admin > access control).') .'</p>';
+      $result = _phpbb2drupal_check_module('privatemsg');
+      $output .= $result['html'];
+      if ($result['result'] != 1) {
+        $ready_for_migration = 0;
+        $form['pm']['#collapsed']= FALSE;
+        $output .= '<p class="marker">';
+        $output .= t('The private message module is not enabled. You can <a href="http://drupal.org/project/privatemsg" target="_blank">go to the module Home Page to download it</a>. <a href="@adminmodules">After having installed it, go to the admin/module page to enable it</a>.', array('@adminmodules' => url('admin/modules')));
+        $output .= '</p>';
+      }
+      $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+      $tables = array($pre.'privmsgs', $pre.'privmsgs_text');
+      $result = _phpbb2drupal_check_tables($tables, 'phpbb', 0);
+      $output .= $result['html'];
+      if ($result['result'] != 1) {
+        $ready_for_migration = 0;
+        $form['pm']['#collapsed']= FALSE;
+        $output .= '<p class="marker">';
+        $output .= t("Couldn't find the phpBB privatemsg tables.");
+        $output .= '</p>';
+      }
+
+      //private messages tables.
+      $result = _phpbb2drupal_check_tables(array('privatemsg', 'privatemsg_folder', 'privatemsg_archive'));
+      $output .= $result['html'];
+      if ($result['result'] != 1) {
+        $ready_for_migration = 0;
+        $form['pm']['#collapsed']= FALSE;
+        $output .= '<p class="marker">';
+        $output .= t("Some tables couldn't be found. Please make sure you have properly installed the privatemsg.mysql on your Drupal data base.");
+        $output .= '</p>';
+      }
+      $form['pm']['info'] = array('#value' => $output);
+
+  }
+  $output ='';
+
+  // Are we ready for migration?
+  $form['migration'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Migration',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  variable_set('phpbb2drupal_ready', $ready_for_migration);
+  if ($ready_for_migration) {
+    $form['migration']['#collapsed']= FALSE;
+    $output .= '<p>'. t('Check again all the settings above, and if everything is ok, <a href="@migratelink">you can now proceed with the migration</a>', array('@migratelink' => url('admin/phpbb2drupal/migrate'))) .'</p>';
+  }
+  else {
+    $output = '<p class="marker">'. t('You are not ready for the migration yet. Check the settings above.') .'</p>';
+  }
+  
+  $form['migration']['info'] = array('#value' => $output);
+  return system_settings_form($form); 
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_categories.inc.php phpbb2drupalpatch2/phpbb2drupal_import_categories.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_categories.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_categories.inc.php	2007-12-23 21:43:13.522298700 +0000
@@ -0,0 +1,107 @@
+<?php
+/**
+ * Create Forum Containers and Forums
+ */
+function _phpbb2drupal_import_categories() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+
+  // check if the forum database has been successfully imported
+  db_set_active('default');
+  if (variable_get('phpbb2drupal_import_category_successful', 0)) {
+    drupal_set_message(t('Categories already imported successfully'));
+    return;
+  }    
+
+  // forum mapping temporary tables
+  if (variable_get('phpbb2drupal_import_category_started', 0) == 0) {
+    db_set_active('default');
+    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}');
+    //db_query("CREATE TABLE {phpbb2drupal_temp_forum} ( forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL, tid integer UNSIGNED DEFAULT '0' NOT NULL, KEY forum_id (forum_id))");
+    variable_set('phpbb2drupal_import_category_started', 1);
+  }
+
+  // Retrieve the vocabulary vid named "Forum"
+  $forum_vid = _forum_get_vid();
+
+  drupal_set_message(t('Forum vid: %forum_vid', array('%forum_vid' => $forum_vid)));
+
+  // Get Categories/Forums from PHPBB
+  db_set_active('phpbb');
+  $category_results = db_query('SELECT * FROM %scategories ORDER BY cat_order', $pre);
+  $cat_count = db_num_rows($category_results);
+  drupal_set_message(t('Found %cat_count categories: Beginning Import', array('%cat_count' => $cat_count)));
+  
+  $forum_count = 0;
+
+  while ($category_result = db_fetch_array($category_results)) {
+
+    $cat_id = $category_result['cat_id'];
+    $forums_results = db_query('SELECT * FROM %sforums WHERE cat_id = %d', $pre, $cat_id);
+    $forum_count += db_num_rows($forums_results);
+    $phpbb2_forums = array();  # reinitialize the temp var not to include it multiple times
+    while ($forum_result = db_fetch_object($forums_results)) {
+      //$phpbb2_categories[$category_result->cat_id]['forums'][] = $forums_result;
+      $phpbb2_forums[$forum_result->forum_id] = $forum_result;
+    }
+
+    $phpbb2_categories[$cat_id] = array_merge($category_result, array('forums' => $phpbb2_forums));
+  }
+
+  drupal_set_message(t('Found %forum_count forums: Beginning Import', array('%forum_count' => $forum_count)));
+
+  // Insert the Containers / Forum into Drupal
+  db_set_active('default');
+
+  // Insert the Containers
+  $container_order = -10;
+  foreach ($phpbb2_categories as $container) {
+    $edit = array(
+      'name' => $container['cat_title'],
+      'vid' => $forum_vid,
+      'description' => '',
+      'weight' => $container_order,
+    );
+    $edit['name'] = _phpbb2drupal_text_encode($edit['name']);
+
+    taxonomy_save_term($edit);
+
+    // serialize the forum containers
+    $containers = variable_get('forum_containers', array());
+    $containers[] = $edit['tid'];
+    variable_set('forum_containers', $containers); 
+
+    // Insert the Forums
+    $forum_order = -10;
+    foreach ($container['forums'] as $forum) {
+      // Make sure the forum/term is has not already been imported
+      if (!db_result(db_query('SELECT forum_id FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum->forum_id))) {
+        $forum_edit = array(
+          'name' => $forum->forum_name,
+          'vid' => $forum_vid,
+          'description' => $forum->forum_desc,
+          'weight' => $forum_order,
+          'parent' => array($edit['tid']),
+        );
+        $forum_edit['name'] = _phpbb2drupal_text_encode($forum_edit['name']);
+        $forum_edit['description'] = _phpbb2drupal_text_encode($forum_edit['description']);
+
+        taxonomy_save_term($forum_edit);
+
+        $forum_order++;
+        $tid = $forum_edit['tid'];
+
+        db_set_active('default');
+        db_query('INSERT INTO {phpbb2drupal_temp_forum} (forum_id, tid) VALUES (%d, %d)', $forum->forum_id, $tid);
+      }
+    }
+
+    $container_order++;
+  }
+
+  db_set_active('default');
+  // set the forums import successful flag in the variable table
+  variable_set('phpbb2drupal_import_category_successful', '1');
+
+  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_forum}'));
+  drupal_set_message(t('Successfully Imported %count forums.', array('%count' => $count)));
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_cleanup.inc.php phpbb2drupalpatch2/phpbb2drupal_import_cleanup.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_cleanup.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_cleanup.inc.php	2007-12-23 21:43:07.469498700 +0000
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Clean UP
+ */
+function _phpbb2drupal_import_cleanup() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+
+  #
+  # Update Drupal sequence 
+  #
+  db_set_active('default');
+  $term_data_tid = db_result(db_query('SELECT MAX(tid) FROM {term_data}'));
+  $comments_cid = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
+  $node_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
+  $users_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
+
+  db_query("DELETE FROM {sequences} WHERE name='term_data_tid'");
+  db_query("DELETE FROM {sequences} WHERE name='comments_cid'");
+  db_query("DELETE FROM {sequences} WHERE name='node_nid'");
+  db_query("DELETE FROM {sequences} WHERE name='users_uid'");
+
+  db_query("INSERT INTO {sequences} (name,id) VALUES ('term_data_tid', '%s')", $term_data_tid);
+  db_query("INSERT INTO {sequences} (name,id) VALUES ('comments_cid', '%s')", $comments_cid);
+  db_query("INSERT INTO {sequences} (name,id) VALUES ('node_nid', '%s')", $node_nid);
+  db_query("INSERT INTO {sequences} (name,id) VALUES ('users_uid', '%s')", $users_uid);
+
+  if (variable_get('phpbb2drupal_import_attachments', 0)) {
+    $files_fid = db_result(db_query('SELECT MAX(fid) FROM {files}'));
+    if (!$files_fid) { //may be NULL
+      $files_fid = 0;
+    }
+    db_query("DELETE FROM {sequences} WHERE name='files_fid'");
+    db_query("INSERT INTO {sequences} (name,id) VALUES ('files_fid', '%s')", $files_fid);
+  }
+  
+  // don't DROP: the data is used for redirects from old forum.
+  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_user}");
+  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_forum}");
+  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}");
+  #db_query("DROP TABLE IF EXISTS {phpbb2drupal_temp_post}");
+
+  variable_del('phpbb2drupal_import_user_successful');
+  variable_del('phpbb2drupal_import_user_started');
+  variable_del('phpbb2drupal_import_category_successful');
+  variable_del('phpbb2drupal_replace_url_successful');
+  variable_del('phpbb2drupal_import_category_started');
+  variable_del('phpbb2drupal_import_topic_successful');
+  variable_del('phpbb2drupal_import_topic_started');
+  variable_del('phpbb2drupal_import_post_successful');
+  variable_del('phpbb2drupal_import_post_started');
+  variable_del('phpbb2drupal_ready');
+  variable_del('phpbb2drupal_regdate_us_english');
+  variable_del('phpbb2drupal_input_format');
+  variable_del('phpbb2drupal_db_url');
+  variable_del('phpbb2drupal_tested');
+  variable_del('phpbb2drupal_same_db');
+  variable_del('phpbb2drupal_table_prefix');
+  variable_del('phpbb2drupal_time_limit');
+  variable_del('phpbb2drupal_import_spammers');
+  variable_del('phpbb2drupal_import_attachments');
+  variable_del('phpbb2drupal_import_polls'); 
+  variable_del('phpbb2drupal_import_pm');
+  variable_del('phpbb2drupal_import_poll_started');
+  variable_del('phpbb2drupal_import_poll_successful');
+  variable_del('phpbb2drupal_import_pm_successful');
+  variable_del('phpbb2drupal_admin_user');
+  variable_del('phpbb2drupal_encode');
+  variable_del('phpbb2drupal_encoding_phpbb');
+  variable_del('phpbb2drupal_encoding_drupal');
+
+  db_query('DELETE FROM {cache}');
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_pm.inc.php phpbb2drupalpatch2/phpbb2drupal_import_pm.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_pm.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_pm.inc.php	2007-12-23 21:42:58.015898700 +0000
@@ -0,0 +1,42 @@
+<?php
+function _phpbb2drupal_import_pm() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  $format = variable_get('phpbb2drupal_input_format', 0);
+  if (variable_get('phpbb2drupal_import_pm_successful', 0) == 1) {
+    return;
+  }
+  db_set_active('phpbb');
+  $query = "SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid, p.privmsgs_subject, pt.privmsgs_text, pt.privmsgs_bbcode_uid, p.privmsgs_date,
+      CASE WHEN p.privmsgs_type = 1 THEN 1
+      WHEN p.privmsgs_type = 5 THEN 1
+      ELSE 0
+      END as newmsg,
+      p.privmsgs_ip, 0, 0, 0
+      FROM %sprivmsgs p
+      LEFT JOIN %sprivmsgs_text AS pt ON p.privmsgs_id = pt.privmsgs_text_id";
+  $messages = db_query($query, $pre, $pre);
+  
+  db_set_active('default');
+  while ($pm = db_fetch_object($messages)) {    
+    $query = 'SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d';
+    $from_result = db_query($query, $pm->privmsgs_from_userid);
+    $from = db_result($from_result);
+    $to_result = db_query($query, $pm->privmsgs_to_userid);
+    $to = db_result($to_result);
+    // don't import private messages from or to users who are not imported.
+    if ($from and $to) {
+      // remove the bbcode_uid from post_text
+      $pm->privmsgs_text = preg_replace("/:$pm->privmsgs_bbcode_uid/", '', $pm->privmsgs_text);
+      $pm->privmsgs_text = _phpbb2drupal_strip_bbcode($pm->privmsgs_text);
+      $pm->privmsgs_text = _phpbb2drupal_text_encode($pm->privmsgs_text);
+      $pm->privmsgs_text = _phpbb2drupal_replace_links($pm->privmsgs_text);
+      $pm->privmsgs_subject = _phpbb2drupal_text_encode($pm->privmsgs_subject);
+      
+      $query = "INSERT INTO {privatemsg} ( id, author, recipient, subject, message, timestamp, newmsg, hostname, folder, author_del, recipient_del, format )
+          VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', 0, 0, 0 , %d)"; 
+      $result = db_query ($query, db_next_id('{privatemsg}_id'), $from, $to, substr($pm->privmsgs_subject, 0, 64), $pm->privmsgs_text, $pm->privmsgs_date, $pm->newmsg, substr($pm->privmsgs_ip, 0, 255), $format);
+    }
+  }
+  variable_set('phpbb2drupal_import_pm_successful', 1);
+  return '<p>'. t('Private Message Import successful') .'</p>';
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_polls.inc.php phpbb2drupalpatch2/phpbb2drupal_import_polls.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_polls.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_polls.inc.php	2007-12-23 21:42:49.451498700 +0000
@@ -0,0 +1,175 @@
+<?php
+/**
+ * Imports phpBB polls into drupal
+ */
+function _phpbb2drupal_import_polls() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  $input_format = variable_get('phpbb2drupal_input_format', 0);
+  db_set_active('default');
+
+  // check if the poll database has been successfully imported
+  if (variable_get('phpbb2drupal_import_polls_successful', 0)) {
+    drupal_set_message(t('Polls already imported successfully'));
+    return;
+  }    
+
+  if (!variable_get('phpbb2drupal_import_polls_started', 0)) {
+      variable_set('phpbb2drupal_import_poll_started', 1);
+  }
+
+  // Get all polls from PHPBB
+  db_set_active('phpbb');
+  $topics = db_query('SELECT * FROM %stopics t WHERE topic_vote = 1 ORDER BY topic_id', $pre);
+  $topic_count = db_num_rows($topics);
+  drupal_set_message(t('Found %poll_count polls: Beginning Import', array('%poll_count' => $topic_count)));
+
+  // insert into polls
+  while ($topic = db_fetch_object($topics)) {
+
+    // check if this topic has been imported already just to be sure
+    db_set_active('default');
+    $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $topic->topic_id));
+    if ($count > 0) {
+      drupal_set_message(t('Poll %topic_id has already been imported', array('%topic_id' => $result->topic_id)));    
+      db_set_active('phpbb');
+      continue;
+    } 
+
+    // get the polls 
+    db_set_active('phpbb');
+    $query = db_query('SELECT * FROM %svote_desc vd WHERE topic_id = %d ORDER BY vote_id', $pre, $topic->topic_id); 
+
+    if (db_num_rows($query)) {
+      $poll = db_fetch_object($query);
+    }
+    else {
+      drupal_set_message(t('Could not find details of poll: %topic_id', array('%topic_id' => $topic->topic_id)));    
+      continue;
+    }
+
+    // get vote results
+    $query = db_query('SELECT * FROM %svote_results WHERE vote_id = %d ORDER BY vote_option_id', $pre, $poll->vote_id);
+
+    if (db_num_rows($query)) {
+      $choice = array();
+      while ($result = db_fetch_object($query)) {
+        $choice[] = array(
+          'chtext' => _phpbb2drupal_text_encode($result->vote_option_text),
+          'chvotes' => _phpbb2drupal_text_encode($result->vote_result),
+        );
+      }
+    }
+    else {
+        drupal_set_message(t('Could not find vote_results details of poll: %vote_id', array('%vote_id' => $poll->vote_id)));    
+        continue;
+    }
+
+    db_set_active('default');
+    $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
+    $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
+
+    if ($topic->topic_poster == 2) {   // is the admin
+      $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+      $uid = $user->uid;
+    }
+    else if ($topic->topic_poster == -1) {
+      $uid = 0;
+    }
+
+    if ($topic->topic_type == 1) {
+      $sticky = 1;      // sticky
+      $promote = 0;
+    }
+    else if ($topic->topic_type == 2) {
+      $sticky = 0;
+      $promote = 1;     // display on the front page, i.e. promote
+    }
+    else {
+      $sticky = 0;
+      $promote = 0;
+    }
+
+    if ($topic->topic_status == 1) { // LOCKED
+      $comment = 1;  // read-only
+    }
+    else { // UNLOCKED & WATCH NOTIFIED
+      $comment = 2;  // read-write
+    }
+
+    //construct the node
+    $node = array(
+      'type' => 'poll',
+      'title' => $poll->vote_text,
+      'uid' => $uid,
+      'status' => 1,  // published or not - always publish
+      'promote' => $promote,
+      'created' => $topic->topic_time,
+      'changed' => $topic->topic_time,
+      'comment' => $comment,
+      'moderate' => 0,
+      'body' => '',
+      'format' => $input_format,
+      'sticky' => $sticky,
+//      'teaser' => $teaser
+    );
+    $node['title'] = _phpbb2drupal_text_encode($node['title']);
+
+
+    // handle moved nodes
+    if ($topic->topic_status == 2) {
+      db_set_active('phpbb');
+      $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
+      db_set_active('default');
+      $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
+
+      $node['tid'] = $moved_tid;        // which forum it used to be part of
+    }
+    else {
+      $node['tid'] = $tid;
+    }
+
+    // Add poll node information
+    $node['runtime'] = $poll->vote_length;
+    $node['active'] = (time() > ($poll->start + $poll->length)) ? 0 : 1;
+    $node['choice'] = $choice;
+
+    $node = (object)$node; // node_save requires an object form
+    
+    db_set_active('default');
+    node_save($node);
+    taxonomy_node_save($node->nid, array($tid));
+
+    if (!$node->nid) {
+      drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
+    }
+
+
+    // get voter information
+    db_set_active('phpbb');
+    $query = db_query('SELECT vote_user_id FROM %svote_voters WHERE vote_id = %d ORDER BY vote_id', $pre, $poll->vote_id);
+
+    // manually update the poll table to store the uid of those who voted
+    if (db_num_rows($query)) {
+      db_set_active('phpbb');
+      while ($result = db_fetch_object($query)) {
+        db_set_active('default');
+        $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $result->vote_user_id));
+        $result = db_query('INSERT INTO {poll_votes} (nid, uid, hostname) VALUES (%d, %d, \'NA\')', $node->nid, $uid);
+        db_set_active('phpbb');
+      }
+    }
+
+    db_set_active('default');
+    db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
+    phpbb2_drupal_poll_insert($node);
+
+
+    db_set_active('phpbb');
+  }
+
+  db_set_active('default');
+  // set the topic import successful flag in the variable table
+  variable_set('phpbb2drupal_import_poll_successful', '1');
+
+  drupal_set_message(t('Successfully imported polls'));
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_posts.inc.php phpbb2drupalpatch2/phpbb2drupal_import_posts.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_posts.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_posts.inc.php	2007-12-23 21:42:37.798298700 +0000
@@ -0,0 +1,170 @@
+<?php
+/**
+ * PHPBB Posts --> Drupal Comments
+ */
+function _phpbb2drupal_import_posts() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
+
+  db_set_active('default');
+  // check if the post database has been successfully imported
+  if (variable_get('phpbb2drupal_import_post_successful', 0)) {
+    drupal_set_message(t('Posts already imported successfully'));
+    return;
+  }    
+
+  if (!variable_get('phpbb2drupal_import_post_started', 0)) {
+    db_set_active('default');
+    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_post}');
+    /*db_query("CREATE TABLE {phpbb2drupal_temp_post} (
+                post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+                cid int(10) DEFAULT '0' NOT NULL,
+                KEY post_id (post_id))"  
+            );
+     */
+    db_set_active('default');
+    variable_set('phpbb2drupal_import_post_started', 1);
+  }
+
+  db_set_active('phpbb');
+  $topic_ids = db_query('SELECT topic_id, topic_vote, topic_first_post_id, topic_last_post_id
+    FROM %stopics 
+    WHERE topic_replies > 0
+    ORDER BY topic_id', $pre);
+
+  $topic_count = db_num_rows($topic_ids);
+  drupal_set_message(t('Found %post_count posts: Beginning Import', array('%post_count' => $topic_count)));
+
+  $errors = 0;
+  $loops = 0;
+  // Import the posts into drupal
+  while ($obj = db_fetch_object($topic_ids)) {
+    $loops++;
+
+    // skip first post if the post is not a poll
+    // stupid phpbb... make the way you store topics consistent for crying out loud
+    db_set_active('phpbb');
+    if ($obj->topic_vote == 0) {
+      $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d AND post_id <> %d ORDER BY post_id',
+        $pre, $obj->topic_id, $obj->topic_first_post_id);
+    }
+    else {
+      $post_ids = db_query('SELECT post_id FROM %sposts WHERE topic_id = %d ORDER BY post_id', $pre, $obj->topic_id);
+    }
+
+    unset($obj);
+
+    while ($result = db_fetch_object($post_ids)) {
+      $loops++;
+
+      db_set_active('phpbb');
+      /*
+		$query = db_query("SELECT * FROM {posts} p INNER JOIN {posts_text} pt ON p.post_id = pt.post_id WHERE p.post_id = %d", $result->post_id);
+      //*/
+
+      $query = db_query('SELECT * FROM %sposts p, %sposts_text pt WHERE p.post_id = pt.post_id AND p.post_id = %d',
+        $pre, $pre, $result->post_id);
+
+      // make sure the post is valid
+      if (db_num_rows($query)) {
+        $post = db_fetch_object($query);
+      }
+      else {
+        $errors++;
+        drupal_set_message(t("Couldn't find post text for %post_id", array('%post_id' => $result->post_id)));
+        continue;
+      }
+
+      // skip if the post has already been imported
+      db_set_active('default');
+      $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post->post_id));
+      if ($count > 0) {
+        $errors++;
+        drupal_set_message(t('Post %post_id was already inserted', array('%post_id' => $post->post_id)));
+        db_set_active('phpbb');
+        continue;
+      }
+
+      db_set_active('default');
+      $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $post->poster_id));
+      $pid = db_result(db_query('SELECT MAX(pid) FROM {comments} WHERE nid = %d', $nid));
+      // get the node ID. The title may be useful further down if the comment doesn't have its own title.
+      $node = (db_fetch_object(db_query('SELECT n.nid, n.title FROM {phpbb2drupal_temp_topic} ptt LEFT JOIN {node_revisions} AS n ON ptt.nid = n.nid  WHERE topic_id = %d', $post->topic_id)));
+      $nid = $node->nid;
+
+      $pid = (is_null($pid)) ? 0 : $pid;
+
+      if ($post->poster_id == 2) {   // is the admin
+        $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+        $uid = $user->uid;
+      }
+      else if ($post->poster_id == -1) { // anonymous
+        $uid = 0; 
+      }    
+
+      $hostname = phpbb2drupal_decode_ip($post->poster_ip);
+
+      // remove the :bbcode_uid from post_text
+      $post->post_text = preg_replace("/:$post->bbcode_uid/", '', $post->post_text);
+      $post->post_text = _phpbb2drupal_strip_bbcode($post->post_text);
+      $post->post_text = _phpbb2drupal_text_encode($post->post_text);
+      $post->post_subject = _phpbb2drupal_text_encode($post->post_subject);
+
+      //construct the node
+      $comment = array(
+        'pid' => $pid,
+        'nid' => $nid,
+        'uid' => $uid,
+        'subject' => $post->post_subject,
+        'comment' => $post->post_text,
+        'hostname' => $hostname,
+        'timestamp' => $post->post_time
+      );
+
+      // if the title field is empty, use the node title as default.
+      if (empty($comment['subject'])) {
+        $comment['subject'] = $node->title;
+      }
+
+      db_set_active('default');
+      $cid = phpbb2drupal_comment_save($comment);
+
+      if (!$cid) {
+        $errors++;
+        drupal_set_message(t('Failed importing %post_id', array('%post_id' => $post->post_id)));
+      }
+            
+      // Handle attachments
+      if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
+        if ($post->post_attachment == 1) {
+          db_set_active('default');
+          $file_path = variable_get('file_directory_path', 'files');
+
+          db_set_active('phpbb');
+          $files = db_query('SELECT * FROM %sattachments a INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id WHERE a.post_id = %d',
+            $pre, $pre, $post->post_id);
+
+          while ($file = db_fetch_object($files)) {
+            db_set_active('default');
+            $fid = db_next_id('{files}_fid');
+            db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, 0, substr($file->real_filename, 0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
+            db_query('INSERT INTO {comment_files} (cid, fid) VALUES (%d, %d)', $cid, $fid);
+            db_set_active('phpbb');
+          }        
+        }
+      }
+
+      db_set_active('default');
+      db_query('INSERT INTO {phpbb2drupal_temp_post} (post_id, cid) VALUES (%d, %d)', $post->post_id, $cid);
+
+      db_set_active('phpbb');
+    }
+  }
+
+  // set the post import successful flag in the variable table
+  db_set_active('default');
+  variable_set('phpbb2drupal_import_post_successful', '1');
+  drupal_set_message(t('Successfully Imported %imported posts', array('%imported' => $imported)));
+  drupal_set_message(t('The were %loops loops executed', array('%loops' => $loops)));
+  drupal_set_message(t('There %errors errors while importing posts', array('%errors' => $errors)));
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_topics.inc.php phpbb2drupalpatch2/phpbb2drupal_import_topics.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_topics.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_topics.inc.php	2007-12-23 21:42:31.152698700 +0000
@@ -0,0 +1,188 @@
+<?php
+/**
+ * Imports PHPBB topics to Drupal equivalent forum nodes
+ */
+function _phpbb2drupal_import_topics() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  $PHPBB2DRUPAL_IMPORT_ATTACHMENTS = variable_get('phpbb2drupal_import_attachments', 0);
+  $input_format = variable_get('phpbb2drupal_input_format', 0);
+
+  // check if the post database has been successfully imported
+  db_set_active('default');
+  if (variable_get('phpbb2drupal_import_topic_successful', 0)) {
+    drupal_set_message(t('Topics already imported successfully'));
+    return;
+  }    
+
+  if (!variable_get('phpbb2drupal_import_topic_started', 0)) {
+    db_set_active('default');
+    //db_query('DROP TABLE IF EXISTS {phpbb2drupal_temp_topic}');
+    //db_query("CREATE TABLE {phpbb2drupal_temp_topic} ( topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, post_id  mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, nid integer UNSIGNED DEFAULT '0' NOT NULL, KEY topic_id (topic_id))");
+    variable_set('phpbb2drupal_import_topic_started', 1);
+  }
+
+  // Get All topics from PHPBB
+  db_set_active('phpbb');
+  // topic_status == 2, Moved topics are duplicates don't import
+  $topic_ids = db_query('SELECT topic_id FROM %stopics WHERE topic_vote <> 1 ORDER BY topic_id', $pre);
+
+  $topic_count = db_num_rows($topic_ids);
+
+  drupal_set_message(t('Found %topic_count topics: Beginning Import', array('%topic_count' => $topic_count)));
+
+  // Import the topics into drupal
+  $counter = 0;
+  db_set_active('phpbb');
+  while ($result = db_fetch_object($topic_ids)) {
+      
+    // check if this topic has been imported already just to be sure
+    db_set_active('default');
+    $count = db_result(db_query('SELECT count(*) FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $result->topic_id));
+    if ($count > 0) {
+      #print "<h3>Topic $result->topic_id has already been imported</h3>";    
+      #flush();
+      db_set_active('phpbb');
+      continue;
+    } 
+
+    db_set_active('phpbb');
+    /*$query = db_query("SELECT *
+      FROM {topics} t
+      INNER JOIN {posts} p ON t.topic_id = p.topic_id
+      INNER JOIN {posts_text} pt ON p.post_id = pt.post_id                            
+      WHERE t.topic_id = %d
+      ORDER BY p.post_id     
+      LIMIT 1", $result->topic_id); /**/
+
+    $query = db_query('SELECT *
+      FROM %stopics t
+      INNER JOIN %sposts p ON t.topic_id = p.topic_id
+      INNER JOIN %sposts_text pt ON p.post_id = pt.post_id                            
+      WHERE p.post_id = t.topic_first_post_id
+      AND t.topic_id = %d',$pre, $pre, $pre, $result->topic_id);
+      
+    // check if the topic is a valid topic.  if not, continue on
+    if (db_num_rows($query)) {
+        $topic = db_fetch_object($query);
+    }
+    else {
+      drupal_set_message(t('Could not find post details of topic: %topic_id', array('%topic_id' => $result->topic_id)));    
+      continue;
+    }
+    
+    db_set_active('default');
+    $uid = db_result(db_query('SELECT uid FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $topic->topic_poster));
+    $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $topic->forum_id));
+
+    if ($topic->topic_poster == 2) {   // is the admin
+      $user = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+      $uid = $user->uid;
+    }
+    else if ($topic->topic_poster == -1) {
+      $uid = 0;
+    }
+
+    if ($topic->topic_type == 1) {
+      $sticky = 1;      // sticky
+      $promote = 0;
+    }
+    else if ($topic->topic_type == 2) {
+      $sticky = 1;
+      $promote = 0;     // display on the front page, i.e. promote
+    }
+    else {
+      $sticky = 0;
+      $promote = 0;
+    }
+
+    if ($topic->topic_status == 1) { // LOCKED
+      $comment = 1;  // read-only
+    }
+    else { // UNLOCKED & WATCH NOTIFIED
+      $comment = 2;  // read-write
+    }
+
+    // remove the bbcode_uid from post_text
+    $topic->post_text = preg_replace("/:$topic->bbcode_uid/", '', $topic->post_text);
+    $topic->post_text = _phpbb2drupal_strip_bbcode($topic->post_text);
+    $topic->post_text = _phpbb2drupal_text_encode($topic->post_text);
+
+    $teaser = node_teaser($topic->post_text);
+
+    //construct the node
+    $node = array(
+      'type' => 'forum',
+      'title' => $topic->topic_title,
+      'uid' => $uid,
+      'status' => 1,  // published or not - always publish
+      'promote' => $promote,
+      'created' => $topic->topic_time,
+      'changed' => $topic->post_edit_time,
+      'comment' => $comment,
+      'moderate' => 0,
+      'body' => $topic->post_text,
+      'sticky' => $sticky,
+      'format' => $input_format,
+      'teaser' => $teaser,
+    );
+    $node['title'] = _phpbb2drupal_text_encode($node['title']);
+
+    if ($topic->topic_status == 2) {
+      db_set_active('phpbb');
+      $forum_id = db_result(db_query('SELECT forum_id FROM %stopics WHERE topic_id = %d', $pre, $topic->topic_moved_id));
+      db_set_active('default');
+      $moved_tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
+
+      $node['tid'] = $moved_tid;        // which forum it used to be part of
+    }
+    else {
+      $node['tid'] = $tid;
+    }
+
+    $node = (object)$node; // node_save requires an object form
+
+    db_set_active('default');
+    node_save($node);
+    taxonomy_node_save($node->nid, array($tid));
+
+    if (!$node->nid) {
+      drupal_set_message(t('Failed importing %topic_id', array('%topic_id' => $topic->topic_id)));
+    }
+
+    // Handle attachments
+    if ($PHPBB2DRUPAL_IMPORT_ATTACHMENTS) {
+      if ($topic->topic_attachment == 1) {
+
+        db_set_active('default');
+        $file_path = variable_get('file_directory_path', 'files');
+
+        db_set_active('phpbb');
+        $files = db_query('SELECT * 
+          FROM %sattachments a 
+          INNER JOIN %sattachments_desc ad ON a.attach_id = ad.attach_id
+          INNER JOIN %sposts p ON a.post_id = p.post_id 
+          WHERE p.topic_id = %d
+          ORDER BY a.attach_id', $pre, $pre, $pre, $topic->topic_id);
+
+        while ($file = db_fetch_object($files)) {
+          db_set_active('default');
+          $fid = db_next_id('{files}_fid');
+          db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $fid, $node->nid, substr($file->real_filename0, 255), substr("$file_path/$file->physical_filename", 0, 255), substr($file->mimetype, 0, 255), $file->filesize);
+          db_set_active('phpbb');
+        }
+      }
+    }
+
+    db_set_active('default');
+    db_query('INSERT INTO {phpbb2drupal_temp_topic} (topic_id, post_id, nid) VALUES (%d, %d, %d)', $topic->topic_id, $topic->post_id, $node->nid);
+
+    db_set_active('phpbb');
+  }  // while ($result = db_fetch_object($topic_ids))
+
+  db_set_active('default');
+  // set the topic import successful flag in the variable table
+  variable_set('phpbb2drupal_import_topic_successful', '1');
+
+  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_topic}'));
+  drupal_set_message(t('Successfully Imported %count topics', array('%count' => $count)));
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_import_users.inc.php phpbb2drupalpatch2/phpbb2drupal_import_users.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_import_users.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_import_users.inc.php	2007-12-23 21:43:19.902698700 +0000
@@ -0,0 +1,167 @@
+<?php
+/**
+ * User Import Functions
+ */
+function _phpbb2drupal_import_users() {
+  $pre = variable_get('phpbb2drupal_table_prefix', 'phpbb_');
+  // check if the user database has been successfully imported
+  db_set_active('default');
+  if (variable_get('phpbb2drupal_import_user_successful', 0)) {
+    drupal_set_message(t('Users already imported successfully'));
+    return;
+  }  
+
+  if (variable_get('phpbb2drupal_import_user_started', 0) == 0) {
+    // create temporary tables
+    db_set_active('default');
+
+    // create profile fields for icq, aim, msn...etc
+    $querybase = 'INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, options) VALUES ';
+
+    $query = $querybase . "('YIM', 'user_yim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+
+    $query = $querybase . "('AIM', 'user_aim', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+    
+    $query = $querybase . "('icq', 'user_icq', '', 'Contact', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+    
+    $query = $querybase . "('Website', 'user_website', '', 'Contact', '', 'url', 0, 0, 1, 2, '')";
+    db_query($query);
+
+    $query = $querybase . "('Location', 'user_from', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+
+    $query = $querybase . "('Occupation', 'user_occ', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+
+    $query = $querybase . "('Interests', 'user_interests', '', 'Personal', '', 'textfield', 0, 0, 1, 2, '')";
+    db_query($query);
+
+    variable_set('phpbb2drupal_import_user_started', 1);
+  }
+
+  db_set_active('default');
+  $drupal_admin = user_load(array('name' => variable_get('phpbb2drupal_admin_user', '')));
+  db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES (2 , %d)', $drupal_admin->uid);
+
+  $files_path = variable_get('file_directory_path', 'files');
+  $pictures_path = variable_get('user_picture_path', 'pictures');
+
+  // Insert the users into drupal
+  db_set_active('phpbb');
+  $user_ids = db_query('SELECT user_id FROM %susers WHERE user_id > 2 ORDER BY user_id', $pre);
+
+  $user_count = db_num_rows($user_ids);
+
+  if (!$user_count) {
+      drupal_set_message(t('There were no users found: Aborting script'), 'error');
+      return t('There were no users found: Aborting script.');
+  }
+
+  drupal_set_message(t('Found %user_count users: Beginning Import', array('%user_count' => $user_count + 1)));
+  
+  $import_spammers = variable_get('phpbb2drupal_import_spammers', 1);
+  
+  while ($result = db_fetch_object($user_ids)) {    
+
+    db_set_active('phpbb');
+    $user = db_fetch_object(db_query('SELECT * FROM %susers WHERE user_id = %d', $pre, $result->user_id));
+
+    // Make sure the user is not on the banlist
+    /* db_set_active('phpbb');
+    $banned = db_result(db_query("SELECT COUNT(*) FROM {banlist} WHERE ban_userid = %d", $user->user_id));
+    if ($banned) {
+        db_set_active('phpbb');
+        continue;
+    }*/
+
+    // If we don't want to import users who have never posted, break this while loop here.
+    if ($import_spammers == 1 || $user->user_posts != 0 ) {
+
+    // Make sure the user is has not already been imported
+    db_set_active('default');
+    $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user} WHERE user_id = %d', $user->user_id));
+    if ($count > 0) {
+        $user->user_active = 0;
+    }
+
+    $user->user_aim = strtr($user->user_aim, array('+' => ' ')); # PHPBB stores spaces as +, replace with ' '
+    $user->user_yim = strtr($user->user_yim, array('+' => ' '));
+    $user->user_timezone = $user->user_timezone * 60 * 60;  # Drupal stores timezones in seconds
+
+    // remove the bbcode_uid from post_text
+    $user->user_sig = preg_replace("/:$user->user_sig_bbcode_uid/", '', $user->user_sig);
+
+    // if the $user->user_avatar_type is not their own image, delete it
+    // drupal doesn't have pre-defined avatars.   if we were to import it
+    // then multiple people would share the same avatar image and if one user 
+    // were to changes their avatar then it would change it for everybody else.
+    if ($user->user_avatar_type > 1) {
+        $user->user_avatar = '';
+    }
+
+    $user->user_avatar = ($user->user_avatar) ? "$files_path/$pictures_path/$user->user_avatar" : '';
+
+    // remove the :bbcode_uid from signature
+    $signature = preg_replace("/:$post->bbcode_uid/", '', $user->user_sig);
+    $signature = _phpbb2drupal_strip_bbcode($signature);
+    $signature = _phpbb2drupal_text_encode($signature);
+    if (variable_get('phpbb2drupal_regdate_us_english', 0)) {
+      $user_regdate = strtotime($user->user_regdate);
+      $user_lastvisit = strtotime($user->user_lastvisit);
+      $user_session_time = strtotime($user->user_session_time);
+    }
+    else {
+      $user_regdate = $user->user_regdate;
+      $user_lastvisit = $user->user_lastvisit;
+      $user_session_time = $user->user_session_time;
+    }
+
+    $data = array(
+      'name' => substr($user->username, 0, 60),
+      'pass' => substr($user->user_password, 0, 32),
+      'mail' => substr($user->user_email, 0, 64),
+      'signature' => substr($signature, 0, 255),
+      'created' => $user_regdate,
+      'access' => $user_session_time,
+      'login' => $user_lastvisit,
+      'status' => $user->user_active,
+      'timezone' => $user->user_timezone, 
+      'picture' => $user->user_avatar,
+      'init' => substr($user->user_email, 0, 64),
+      'roles' => array(0 => 2),                       # Authenticated User
+      'user_website' => $user->user_website,
+      'user_from' => $user->user_from,
+      'user_icq' => $user->user_icq,
+      'user_aim' => $user->user_aim,
+      'user_yim' => $user->user_yim,
+      'user_msnm' => $user->user_msnm,
+      'user_occ' => $user->user_occ,
+      'user_interests' => $user->user_interest
+      );
+    if (variable_get('phpbb2drupal_import_pm', 0)) {
+      $data['privatemsg_allow'] = 1;
+    }
+    
+    $data['interests'] = _phpbb2drupal_text_encode($data['interests']);
+
+    db_set_active('default');
+    $drupal_user = phpbb2drupal_user_save($data, array('account', 'Personal', 'Contact'));
+
+    // populate the temporary user table
+    db_set_active('default');
+    db_query('INSERT INTO {phpbb2drupal_temp_user} (user_id, uid) VALUES ( %d, %d )', $user->user_id , $drupal_user->uid);
+
+    db_set_active('phpbb');
+    }
+  }
+
+  // set the user import successful flag in the variable table
+  db_set_active('default');
+  variable_set('phpbb2drupal_import_user_successful', '1');
+
+  $count = db_result(db_query('SELECT COUNT(*) FROM {phpbb2drupal_temp_user}'));
+  drupal_set_message(t('Successfully Imported %count Users', array('%count' => $count)));
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_migrate.inc.php phpbb2drupalpatch2/phpbb2drupal_migrate.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_migrate.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_migrate.inc.php	2007-12-23 23:53:53.655098700 +0000
@@ -0,0 +1,50 @@
+<?php
+function phpbb2drupal_migrate() {
+  if (!variable_get('phpbb2drupal_ready', 0)) {
+    return '<p>'. t('You cannot migrate the data now. Please <a href="@settings">complete the setup first</a>', array('@settings' => url('admin/settings/phpbb2drupal'))) .'</p>';
+  }
+
+  $output = 'Phpbb 2 Drupal Migration Form';
+  $output .= drupal_get_form('phpbb2drupal_migrate_form');
+  return $output;
+}
+
+function phpbb2drupal_migrate_form() {
+  _phpbb2drupal_db_connect() ;
+  // Causes problems with form api redirect
+  //ini_set('display_errors', TRUE);
+
+  // Adjust how long you want the script to run...
+  if (!ini_get('safe_mode')) {
+    set_time_limit(variable_get('phpbb2drupal_time_limit', 0));
+  }
+  
+  $PHPBB2DRUPAL_FUNCTIONS = array(
+    'users' => t('Import Users'),
+    'categories' => t('Import Categories'),
+    'topics' => t('Import Topics'),
+    'polls' => t('Import Polls'),
+    'posts' => t('Import Posts'),
+  );
+
+  if (variable_get('phpbb2drupal_import_pm', 0)) { 
+    $PHPBB2DRUPAL_FUNCTIONS['pm'] = t('Import Private Messages');
+  }
+  $PHPBB2DRUPAL_FUNCTIONS['url'] = t('Transform URLs');
+  /*
+  $new = array('cleanup' => 'Clean up');
+  $PHPBB2DRUPAL_FUNCTIONS = array_merge( $PHPBB2DRUPAL_FUNCTIONS, $new);
+  */
+
+  $form['import'] = array(
+    '#type' => 'select',
+    '#title' => t('Next import to perform'),
+    '#default_value' => $_SESSION['phpbb2drupal_selected'],
+    '#options' => $PHPBB2DRUPAL_FUNCTIONS,
+  );
+  $form[] = array(
+    '#type' => 'submit',
+    '#value' => t('Import'),
+  );
+  return $form;
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_migrate_form_submit.inc.php phpbb2drupalpatch2/phpbb2drupal_migrate_form_submit.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_migrate_form_submit.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_migrate_form_submit.inc.php	2007-12-23 22:52:00.258498700 +0000
@@ -0,0 +1,79 @@
+<?php
+function _phpbb2drupal_migrate_form_submit($form_id, $form_values) {
+
+  switch ($form_values['import']) {
+    case 'users':
+      phpbb2drupal_import_users();
+      if (!variable_get('phpbb2drupal_import_user_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'users';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'categories';
+      }
+      break;
+
+    case 'categories':
+      phpbb2drupal_import_categories();
+      if (!variable_get('phpbb2drupal_import_category_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'categories';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'topics';
+      }
+      break;
+
+    case 'topics':      
+      phpbb2drupal_import_topics();
+      if (!variable_get('phpbb2drupal_import_topic_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'topics';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'polls';
+      }
+      break;
+    
+    case 'polls':      
+      phpbb2drupal_import_polls();
+      if (!variable_get('phpbb2drupal_import_poll_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'polls';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'posts';
+      }
+      break;
+      
+    case 'posts':
+      phpbb2drupal_import_posts();
+      if (!variable_get('phpbb2drupal_import_post_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'posts';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'pm';
+      }
+      break;
+
+    case 'pm':      
+      phpbb2drupal_import_pm();
+      if (!variable_get('phpbb2drupal_import_pm_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'pm';
+      }
+      else {
+        $_SESSION['phpbb2drupal_selected'] = 'url';
+      }
+      break;
+    case 'url':
+      phpbb2drupal_replace_url();
+      if (!variable_get('phpbb2drupal_replace_url_successful', 0)) {
+        $_SESSION['phpbb2drupal_selected'] = 'url';
+      }
+      else {
+        drupal_set_message('Congratulations.  Import Finished');
+        drupal_set_message('Please visit the ' . l('Post migration configuration', 'admin/phpbb2drupal/postconfiguration'). ' page');
+        unset($_SESSION['phpbb2drupal_selected']);
+      }
+      break;
+    default:
+      $_SESSION['phpbb2drupal_selected'] = 'users';
+      break;
+  }
+}
\ No newline at end of file
diff -urpN phpbb2drupalpatch1/phpbb2drupal_postconfiguration.inc.php phpbb2drupalpatch2/phpbb2drupal_postconfiguration.inc.php
--- phpbb2drupalpatch1/phpbb2drupal_postconfiguration.inc.php	1970-01-01 00:00:00.000000000 +0000
+++ phpbb2drupalpatch2/phpbb2drupal_postconfiguration.inc.php	2007-12-23 22:44:01.619298700 +0000
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Callback admin/phpbb2drupal/postconfiguration
+ */
+function _phpbb2drupal_postconfiguration() {
+  // Private forums.
+  $output = '<h2>'. t('Private forums') .'</h2>';
+  $output .= '<p>'. t('Setup the private forums as explained in the <a href="http://drupal.org/node/58969" target="_blank">documentation</a>') .'</p>';
+
+  // Redirection from old URL:
+  $output .= '<h2>'. t('Redirection from phpBB2 forum URL to new Drupal forum URL') .'</h2>';
+  $output .= '<p>'. t('Enable the phpbb_redirect.module. This way, users accessing URLs from your old phpBB2 installation will be redirected to your new Drupal forum. (note that currently the module assumes that the phpbb forum was located in the forum/ subdirectory of your Drupal installation).') .'</p>';
+
+  // BBcode
+  $bbcode = variable_get('phpbb2drupal_bbcode', 0);
+  if ($bbcode) {
+    $output .= '<h2>'. t('Remove BBcode module') .'</h2>';
+    $output .= '<p>'. t("The bbcode has been cleaned from the posts. You shouldn't need the bbcode module anymore. You can disable it.") .'</p>';
+  }
+  else {
+    $output .= '<h2>'. t('Configure BBcode module') .'</h2>';
+    $output .= '<p>'. t('Most probably, there are many phpBB forum postings formatted in BBcode. During the import procedure, the BBcode has been cleaned so that it can work with the Drupal bbcode.module. Please install and configure the <a href="http://drupal.org/project/bbcode" target="_blank">BBcode module</a> so that the forum topics display properly. See the BBcode module documentation for details.') .'</p>';
+  }
+
+  //Avatars
+  $output .= '<h2>'. t('Avatars') .'</h2>';
+  $output .= t('<p>Manually copy the avatars from the phpbb2/images/avatars/ directory to the drupal/files/pictures/ directory.</p>
+    <p>Also, in admin > settings > users, you need to enable picture support. </p>
+    <p>Finally, in admin > themes > configure, you need to allow "User Picture in posts/comments".</p>');
+
+  return $output;
+}
\ No newline at end of file
