/**
 * Executes all necessary functions to make the importation happen.
 */
function import_main()
{
    import_init();
    $user = $_POST['user'];
    $password = $_POST['password'];
    $database = $_POST['database'];
    $host = $_POST['host'];
    $prefix = $_POST['prefix'];
    $bbip = new BBIP_phpBB();
    $bbip->db = new BPDB(array('name' => $database, 'user' => $user, 'password' => $password, 'host' => $host));
    $bbip->export_lib->db = $bbip->db;
    $bbip->export_lib->initialize_db($prefix);
    if ('true' == $_POST['users']) {
        $bbip->import_users = true;
    }
    if ('true' == $_POST['content']) {
        $bbip->import_content = true;
    }
    if ('true' == $_POST['preserve']) {
        $bbip->preserve_ids = true;
        if ('true' == $_POST['current']) {
            $bbip->preserve_current_user = true;
        }
        if ('true' == $_POST['admins']) {
            $bbip->preserve_admins = true;
        }
    }
    $bbip->read_file($_FILES['import_file']['tmp_name']);
    while ($bbip->file_contents) {
        $current = $bbip->find_element($bbip->file_contents);
        if ('!--' != $current[0] && '?xml' != $current[0] && 'forums_data' != $current[0]) {
            die('Invalid top-level element (' . $current[0] . ').');
        }
        $bbip->call_element($current);
        $bbip->file_contents = $bbip->remove_element($current[1], $bbip->file_contents);
    }
    $bbip->check_for_duplicates();
    $bbip->import_prep();
    if ($bbip->import_users) {
        $bbip->insert_users();
    }
    if ($bbip->import_content) {
        $bbip->insert_forums();
        $bbip->insert_topics();
    }
    display_import_results($bbip);
}
/**
 * Executes all necessary functions to make the importation happen.
 */
function import_main()
{
    global $bbdb;
    import_init();
    $bbip = new BBIP_bbPress();
    $bbip->db = $bbdb;
    $bbip->export_lib->db = $bbdb;
    if ('true' == $_POST['users']) {
        $bbip->import_users = true;
    }
    if ('true' == $_POST['content']) {
        $bbip->import_content = true;
    }
    if ('true' == $_POST['preserve']) {
        $bbip->preserve_ids = true;
        if ('true' == $_POST['current']) {
            $bbip->preserve_current_user = true;
        }
        if ('true' == $_POST['admins']) {
            $bbip->preserve_admins = true;
        }
    }
    $bbip->read_file($_FILES['import_file']['tmp_name']);
    while ($bbip->file_contents) {
        $current = $bbip->find_element($bbip->file_contents);
        if ('!--' != $current[0] && '?xml' != $current[0] && 'forums_data' != $current[0]) {
            die('Invalid top-level element (' . $current[0] . ').');
        }
        $bbip->call_element($current);
        $bbip->file_contents = $bbip->remove_element($current[1], $bbip->file_contents);
    }
    $bbip->check_for_duplicates();
    $bbip->import_prep();
    if ($bbip->import_users) {
        $bbip->insert_users();
    }
    if ($bbip->import_content) {
        $bbip->insert_forums();
        $bbip->insert_topics();
    }
    display_import_results($bbip);
}