$return = $tar->extract($dest_dir);
        if (!$return) {
            echo '<br />' . $i18n['error_tar'] . '<br />';
        } else {
            if (!file_exists($dest_dir . '/files') || !is_dir($dest_dir . '/files')) {
                echo '<br />' . $i18n['bad_archive'] . '<br />';
            } else {
                // Show the form for specifying which mod types to 'extract'
                $mods = array();
                // Stores the mod classname, the files list, and the module's real name
                if (!defined('SYS_FILES')) {
                    require_once BASE . 'subsystems/files.php';
                }
                $dh = opendir($dest_dir . '/files');
                while (($file = readdir($dh)) !== false) {
                    if ($file[0] != '.' && is_dir($dest_dir . '/files/' . $file)) {
                        $mods[$file] = array('', array_keys(exponent_files_listFlat($dest_dir . '/files/' . $file, 1, null, array(), $dest_dir . '/files/' . $file . '/')));
                        if (class_exists($file)) {
                            $mods[$file][0] = call_user_func(array($file, 'name'));
                            // $file is the class name of the module
                        }
                    }
                }
                $template = new template('importer', '_files_selectModList');
                $template->assign('dest_dir', $dest_dir);
                $template->assign('file_data', $mods);
                $template->output();
            }
        }
    }
}
##################################################
// Part of the Extensions category
if (!defined('EXPONENT')) {
    exit('');
}
if (exponent_permissions_check('extensions', exponent_core_makeLocation('AdministrationModule'))) {
    $template = new template('AdministrationModule', '_upload_finalSummary', $loc);
    $ext_filename = BASE . "/tmp/uploads/" . session_id();
    if (!file_exists($ext_filename) || !is_dir($ext_filename)) {
        $template->assign('nofiles', 1);
    } else {
        if (!defined('SYS_FILES')) {
            require_once BASE . 'subsystems/files.php';
        }
        $success = array();
        foreach (array_keys(exponent_files_listFlat($ext_filename, true, null, array(), $ext_filename)) as $file) {
            if ($file != '/archive.tar' && $file != '/archive.tar.gz' && $file != 'archive.tar.bz2' && $file != '/archive.zip') {
                exponent_files_makeDirectory(dirname($file));
                $success[$file] = copy($ext_filename . $file, BASE . substr($file, 1));
                if (basename($file) == 'views_c') {
                    chmod(BASE . substr($file, 1), 0777);
                }
            }
        }
        $del_return = exponent_files_removeDirectory($ext_filename);
        echo $del_return;
        $template->assign('nofiles', 0);
        $template->assign('success', $success);
        $template->assign('redirect', exponent_flow_get());
        ob_start();
        include BASE . 'modules/AdministrationModule/actions/installtables.php';
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
// Part of the Extensions category.
if (!defined('EXPONENT')) {
    exit('');
}
if (exponent_permissions_check('extensions', exponent_core_makeLocation('AdministrationModule'))) {
    if (!defined('SYS_FILES')) {
        require_once BASE . 'subsystems/files.php';
    }
    $ext_filename = BASE . "/tmp/uploads/" . session_id();
    $files = array();
    foreach (exponent_files_listFlat($ext_filename, true, null, array(), $ext_filename) as $key => $f) {
        if ($key != '/archive.tar' && $key != '/archive.tar.gz' && $key != '/archive.tar.bz2' && $key != '/archive.zip') {
            $files[] = array('absolute' => $key, 'relative' => $f, 'canCreate' => exponent_files_canCreate(BASE . substr($key, 1)), 'ext' => substr($f, -3, 3));
        }
    }
    $template = new template('AdministrationModule', '_upload_filesList', $loc);
    $template->assign('relative', $ext_filename);
    $template->assign('files', $files);
    $template->output();
} else {
    echo SITE_403_HTML;
}
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
// Part of the Extensions category.
if (!defined('EXPONENT')) {
    exit('');
}
if (exponent_permissions_check('extensions', exponent_core_makeLocation('administrationmodule'))) {
    if (!defined('SYS_FILES')) {
        require_once BASE . 'subsystems/files.php';
    }
    $sessid = session_id();
    $files = array();
    foreach (exponent_files_listFlat(BASE . 'extensionuploads/' . $sessid, true, null, array(), BASE . 'extensionuploads/' . $sessid) as $key => $f) {
        if ($key != '/archive.tar' && $key != '/archive.tar.gz' && $key != '/archive.tar.bz2' && $key != '/archive.zip') {
            $files[] = array('absolute' => $key, 'relative' => $f, 'canCreate' => exponent_files_canCreate(BASE . substr($key, 1)), 'ext' => substr($f, -3, 3));
        }
    }
    $template = new template('administrationmodule', '_upload_filesList', $loc);
    $template->assign('relative', 'extensionuploads/' . $sessid);
    $template->assign('files', $files);
    $template->output();
} else {
    echo SITE_403_HTML;
}
function exponent_files_listFlat($dir, $recurse = false, $ext = null, $exclude_dirs = array(), $relative = "")
{
    $files = array();
    if (is_readable($dir)) {
        $dh = opendir($dir);
        while (($file = readdir($dh)) !== false) {
            if (is_dir("{$dir}/{$file}") && !in_array($file, $exclude_dirs) && $recurse && $file != "." && $file != ".." && $file != "CVS") {
                $files = array_merge($files, exponent_files_listFlat("{$dir}/{$file}", $recurse, $ext, $exclude_dirs, $relative));
            }
            if (is_file("{$dir}/{$file}") && ($ext == null || substr($file, -1 * strlen($ext), strlen($ext)) == $ext)) {
                $files[str_replace($relative, "", "{$dir}/{$file}")] = $file;
            }
        }
    }
    return $files;
}
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
if (!defined('EXPONENT')) {
    exit('');
}
$dest_dir = $_POST['dest_dir'];
$files = array();
if (!defined('SYS_FILES')) {
    require_once BASE . 'subsystems/files.php';
}
foreach (array_keys($_POST['mods']) as $mod) {
    $files[$mod] = array('', array());
    if (class_exists($mod)) {
        $files[$mod][0] = call_user_func(array($mod, 'name'));
    }
    foreach (array_keys(exponent_files_listFlat($dest_dir . '/files/' . $mod, 1, null, array(), $dest_dir . '/files/' . $mod . '/')) as $file) {
        $files[$mod][1][$file] = exponent_files_canCreate(BASE . 'files/' . $mod . '/' . $file);
    }
}
exponent_sessions_set('dest_dir', $dest_dir);
exponent_sessions_set('files_data', $files);
$template = new template('importer', '_files_verifyFiles');
$template->assign('files_data', $files);
$template->output();
##################################################
// Part of the Extensions category
if (!defined('EXPONENT')) {
    exit('');
}
if (exponent_permissions_check('extensions', exponent_core_makeLocation('administrationmodule'))) {
    $template = new template('administrationmodule', '_upload_finalSummary', $loc);
    $sessid = session_id();
    if (!file_exists(BASE . "extensionuploads/{$sessid}") || !is_dir(BASE . "extensionuploads/{$sessid}")) {
        $template->assign('nofiles', 1);
    } else {
        if (!defined('SYS_FILES')) {
            require_once BASE . 'subsystems/files.php';
        }
        $success = array();
        foreach (array_keys(exponent_files_listFlat(BASE . "extensionuploads/{$sessid}", true, null, array(), BASE . "extensionuploads/{$sessid}")) as $file) {
            if ($file != '/archive.tar' && $file != '/archive.tar.gz' && $file != 'archive.tar.bz2' && $file != '/archive.zip') {
                exponent_files_makeDirectory(dirname($file));
                $success[$file] = copy(BASE . "extensionuploads/{$sessid}" . $file, BASE . substr($file, 1));
                if (basename($file) == 'views_c') {
                    chmod(BASE . substr($file, 1), 0777);
                }
            }
        }
        $del_return = exponent_files_removeDirectory(BASE . "extensionuploads/{$sessid}");
        echo $del_return;
        $template->assign('nofiles', 0);
        $template->assign('success', $success);
        $template->assign('redirect', exponent_flow_get());
        ob_start();
        include BASE . 'modules/administrationmodule/actions/installtables.php';