<?php
/*
 * JohnCMS NEXT Mobile Content Management System (http://johncms.com)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://johncms.com JohnCMS Project
 * @copyright   Copyright (C) JohnCMS Community
 * @license     GPL-3
 */

defined('_IN_JOHNCMS') or die('Error: restricted access');

require('../system/head.php');

/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var PDO $db */
$db = $container->get(PDO::class);

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

/** @var Johncms\Api\ToolsInterface $tools */
$tools = $container->get(Johncms\Api\ToolsInterface::class);

$error = false;
if ($systemUser->rights >= 6) {
if ($id) {
//---Get 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']);
}
echo '<div class="mainblok"><div class="phdr">Delete Attached File</div>';
echo '<div class="rmenu">Succesfully deleted..!!<br/><a href="' . htmlspecialchars(getenv("HTTP_REFERER")) . '">Back to thread</a></div></div>';
require('../system/end.php');
exit;
} else {
$error = true;
}
if ($error) {
echo '<div class="mainblok"><div class="phdr">Delete Attached File</div>';
echo '<div class="rmenu">Could not be deleted..!!<br/><a href="' . htmlspecialchars(getenv("HTTP_REFERER")) . '">Back to thread</a></div></div>';
require('../system/end.php');
exit;
}
} else {
echo $tools->displayError(_t('Wrong data'));
require('../system/end.php');
exit;
}
} else {
echo $tools->displayError(_t('Access Forbidden'));
}
?>