<?php

include_once TOOLKIT . '/class.htmlpage.php';
// The extension cannot be found, show an error message and
// let the user remove or rename the extension folder.
if (isset($_POST['extension-missing'])) {
    $name = $_POST['existing-folder'];
    if (isset($_POST['action']['delete'])) {
        Symphony::ExtensionManager()->cleanupDatabase();
    } elseif (isset($_POST['action']['rename'])) {
        $path = ExtensionManager::__getDriverPath($name);
        if (!@rename(EXTENSIONS . '/' . $_POST['existing-folder'], EXTENSIONS . '/' . $_POST['new-folder'])) {
            Symphony::Engine()->throwCustomError(__('Could not find extension %s at location %s.', array('<code>' . $name . '</code>', '<code>' . $path . '</code>')), __('Symphony Extension Missing Error'), Page::HTTP_STATUS_ERROR, 'missing_extension', array('name' => $name, 'path' => $path, 'rename_failed' => true));
        }
    }
    redirect(SYMPHONY_URL . '/system/extensions/');
}
$Page = new HTMLPage();
$Page->Html->setElementStyle('html');
$Page->Html->setDTD('<!DOCTYPE html>');
$Page->Html->setAttribute('xml:lang', 'en');
$Page->addElementToHead(new XMLElement('meta', null, array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8')), 0);
$Page->addStylesheetToHead(APPLICATION_URL . '/assets/css/symphony.min.css', 'screen', null, false);
$Page->setHttpStatus($e->getHttpStatusCode());
$Page->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$Page->addHeaderToPage('Symphony-Error-Type', 'missing-extension');
$Page->setTitle(__('%1$s &ndash; %2$s', array(__('Symphony'), $e->getHeading())));
$Page->Body->setAttribute('id', 'error');
$div = new XMLElement('div', null, array('class' => 'frame'));
$div->appendChild(new XMLElement('h1', $e->getHeading()));
$div->appendChild(new XMLElement('p', trim($e->getMessage())));