<?php



defined('_IN_JOHNCMS') or die('Error: restricted access');
/** @var Interop\Container\ContainerInterface $container */
$container = App::getContainer();
/** @var PDO $db */
$db = $container->get(PDO::class);
/** @var Johncms\Tools $tools */
$tools = $container->get('tools');
$error = false;

if ($systemUser->rights >= 6) {
if ($id) {

/** @var info file */
$req = $db->query("SELECT * FROM `cms_forum_files` WHERE `id` = '$id'");
if ($req->rowCount()) {
        $res = $req->fetch();
        $db->exec("DELETE FROM `cms_forum_files` WHERE `id` = '$id'");
        if (file_exists('../files/forum/attach/' . $res['filename'])) {
            unlink('../files/forum/attach/' . $res['filename']);
         }
        require('../system/head.php');
        echo '<div class="mainblok"><div class="phdr"><b>Information</b></div>' .
        '<div class="rmenu">File Deleted Succes</div>' .
        '<div class="phdr"><a href="javascript:history.back(2)">' . _t('Back') . '</a></div>' .
       '</div>';
       require('../system/end.php');
} else {
      $error = true;
}


if ($error) {
       require('../system/head.php');
       echo '<div class="mainblok"><div class="phdr"><b>Information</b></div>' .
       '<div class="rmenu">File Deleted Error Or File Wass Deleted on server</div>' .
       '<div class="phdr"><a href="javascript:history.back(2)">' . _t('Back') . '</a></div>' .
       '</div>';
       require('../system/end.php');
       exit;
}
} else {
       require('../system/head.php');
       echo $tools->displayError(_t('File does not exist'), '<a href="index.php">' . _t('Forum') . '</a>');
        require('../system/end.php');
        exit;
}
} else {
        header('location: ../?err');        
}
?>
