<?php

/* DCMS Special
 * Дата последнего редактирования 07.10.2016
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/$inc.php";
}

only_reg();
$set['title'] = lang('Настройки новостей');
include_once H . 'sys/inc/thead.php';

err();
aut();


switch ((isset($_GET['m'])) ? htmlspecialchars($_GET['m']) : null) {
    default:
        #Навигация
        echo "<div class='list-group-item-null list-group-item-grey'><small>";
        echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
        echo "<a href='/?umenu'>" . lang('Кабинет') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
        echo "<a href='/user/settings/'>" . lang('Настройки') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
        echo lang('Новости');
        echo "</small></div><br />";

        echo "<form class='list-group-item-null' action='news.php?m=saves' method='POST'>";

        $doc->Checkbox('set_news', 'Показывать новости на главной', 1, "" . ($user['set_news'] ? " checked='checked'" : null) . "");
        $doc->Checkbox('set_news_images', 'Показывать изображения', 1, "" . ($user['set_news_images'] ? " checked='checked'" : null) . "");
        $doc->Checkbox('set_news_comments', 'Предосмотр комментариев', 1, "" . ($user['set_news_comments'] ? " checked='checked'" : null) . "");
        $doc->Checkbox('set_news_to_mail', 'Присылать новости на E-mail', 1, "" . ($user['set_news_to_mail'] ? " checked='checked'" : null) . "");

        echo "<br />";
        $doc->Button('btn btn-success btn-sm', 'save', 'save', 'Сохранить');
        echo "</form>";

        break;

    case 'saves':

        if (isset($_POST['save'])) {
            $user['set_news_images'] = (isset($_POST['set_news_images']) && $_POST['set_news_images']) ? '1' : '0';
            $db->query("UPDATE `user` SET `set_news_images` = '" . $user['set_news_images'] . "' WHERE `id` = '" . $user['id'] . "' LIMIT 1");

            $user['set_news'] = (isset($_POST['set_news']) && $_POST['set_news']) ? '1' : '0';
            $db->query("UPDATE `user` SET `set_news` = '" . $user['set_news'] . "' WHERE `id` = '" . $user['id'] . "' LIMIT 1");

            $user['set_news_comments'] = (isset($_POST['set_news_comments']) && $_POST['set_news_comments']) ? '1' : '0';
            $db->query("UPDATE `user` SET `set_news_comments` = '" . $user['set_news_comments'] . "' WHERE `id` = '" . $user['id'] . "' LIMIT 1");

            $user['set_news_to_mail'] = (isset($_POST['set_news_to_mail']) && $_POST['set_news_to_mail']) ? '1' : '0';
            $db->query("UPDATE `user` SET `set_news_to_mail` = '" . $user['set_news_to_mail'] . "' WHERE `id` = '" . $user['id'] . "' LIMIT 1");

            $_SESSION['message'] = lang("Изменения сохранены");
            header("Location: news.php" . SID);
            exit;
        }

        break;
}

include_once H . 'sys/inc/tfoot.php';
