public function __construct()
 {
     $this->loader = new Twig_Loader_Filesystem(__DIR__ . '/../templates');
     $this->twig = new Twig_Environment($this->loader, array("debug" => true));
     $this->variables = array();
     $this->twig->addExtension(new Twig_Extension_Debug());
     $this->authorized = FALSE;
     $this->add_function('permitted', function ($user, $action) {
         return permitted($user, $action);
     });
     $this->add_function('can_give_role', function ($user, $role) {
         return can_give_role($user, $role);
     });
     $this->add_function('iiif_page_top_url', 'iiif_page_top_url');
     $this->add_function('iiif_page_bottom_url', 'iiif_page_bottom_url');
     $this->add_function('iiif_info_url', 'iiif_info_url');
     $this->twig->addGlobal("ROLE_ADMIN", ROLE_ADMIN);
     $this->twig->addGlobal("ROLE_TITLE_MANAGER", ROLE_TITLE_MANAGER);
     $this->twig->addGlobal("ROLE_ISSUE_CURATOR", ROLE_ISSUE_CURATOR);
     $this->twig->addGlobal("ROLE_ISSUE_REVIEWER", ROLE_ISSUE_REVIEWER);
     $this->twig->addGlobal("ROLE_USER_MANAGER", ROLE_USER_MANAGER);
     $this->twig->addGlobal("ROLE_MOC_MANAGER", ROLE_MOC_MANAGER);
 }
require_once __DIR__ . "/includes/root.php";
must_allow("modify users");
$user = User::find($_GET["id"]);
if ($user == NULL) {
    $renderer->flash_alert("Can't find a user by the given id!");
    header("Location: user-list.php");
    exit;
}
$curruser = get_user();
if ($curruser->id == $user->id) {
    $renderer->flash_alert("You cannot delete yourself!");
    header("Location: user-list.php");
    exit;
}
foreach ($user->roles as $role) {
    if (!can_give_role($curruser, $role)) {
        $renderer->flash_alert("You cannot delete users with the '{$role}' role");
        header("Location: user-list.php");
        exit;
    }
}
if ($user->id == 1) {
    $renderer->flash_alert("You cannot delete user 1");
    header("Location: user-list.php");
    exit;
}
$user->delete();
audit("delete user", $user->login);
$renderer->flash_success("Deleted {$user->login}");
header("Location: user-list.php");