# 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('');
}
if (exponent_permissions_check('manage_core', exponent_core_makeLocation('sharedcoremodule'))) {
    $core = null;
    if (isset($_GET['id'])) {
        $core = $db->selectObject('sharedcore_core', 'id=' . intval($_GET['id']));
    }
    if ($core) {
        $db->delete('sharedcore_core', 'id=' . $core->id);
        if (!defined('SYS_SHAREDCORE')) {
            include_once BASE . 'subsystems/sharedcore.php';
        }
        foreach ($db->selectObjects('sharedcore_site', 'core_id=' . $core->id) as $site) {
            $db->delete('sharedcore_extension', 'site_id=' . $site->id);
            exponent_sharedcore_clear($site->path, true);
        }
        $db->delete('sharedcore_site', 'core_id=' . $core->id);
        exponent_flow_redirect();
    } else {
        echo SITE_404_HTML;
    }
} else {
    echo SITE_403_HTML;
}
    exit('');
}
$loc = exponent_core_makeLocation('sharedcoremodule');
if (exponent_permissions_check('manage_core', $loc) || exponent_permissions_check('manage_site', $loc)) {
    $site = null;
    if (isset($_GET['id'])) {
        $site = $db->selectObject('sharedcore_site', 'id=' . intval($_GET['id']));
    }
    if ($site) {
        if ($site->inactive == 0) {
            $core = $db->selectObject('sharedcore_core', 'id=' . $site->core_id);
            if ($core) {
                if (!defined('SYS_SHAREDCORE')) {
                    include_once BASE . 'subsystems/sharedcore.php';
                }
                exponent_sharedcore_clear($site->path);
                // Not full
                exponent_sharedcore_setup($core, $site);
                $extensions = array(CORE_EXT_MODULE => array(), CORE_EXT_SUBSYSTEM => array(), CORE_EXT_THEME => array());
                foreach ($db->selectObjects('sharedcore_extension', 'site_id=' . $site->id) as $e) {
                    $extensions[$e->type][] = $e->name;
                }
                exponent_sharedcore_link($core, $site, $extensions);
                exponent_flow_redirect();
            } else {
                echo SITE_404_HTML;
                // temp
            }
        } else {
            echo SITE_403_HTML;
        }