<?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('Уведомления');

require_once H . 'sys/inc/thead.php';

aut();
err();

$get = $_GET['id'];
$ank = $db->get_array($db->query("SELECT * FROM `user` WHERE `id` = '$get'"));
$q = $db->get_array($db->query("SELECT * FROM `friends` WHERE `user` = '$get'"));


#Навигация
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='/id$user[id]'>$user[nick]</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='/user/notification/'>" . lang('Уведомления') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Настройки') . " $ank[nick]";
echo "</small></div><br />";

only_reg();

if (isset($_POST['save'])) {

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

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

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

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

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

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

    $q['lenta_news'] = (isset($_POST['lenta_news']) && $_POST['lenta_news']) ? '1' : '0';
    $db->query("UPDATE `friends` SET `lenta_news` = '" . $db->safesql($q['lenta_news']) . "' WHERE `user` = '$get' AND `friends` = '$user[id]' LIMIT 1");
    
    $q['lenta_chat'] = (isset($_POST['lenta_chat']) && $_POST['lenta_chat']) ? '1' : '0';
    $db->query("UPDATE `friends` SET `lenta_chat` = '" . $db->safesql($q['lenta_chat']) . "' WHERE `user` = '$get' AND `friends` = '$user[id]' LIMIT 1");

    if (!isset($err)) {
        msg('Изменения успешно приняты');
    }
}

err();

echo "<form class='list-group-item-null' method='POST'>";

$doc->Checkbox('lenta_friends', 'Уведомления о новых друзьях', '1', "" . ($q['lenta_friends'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_diary', 'Уведомления о дневниках и комментариях', '1', "" . ($q['lenta_diary'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_forum', 'Уведомления о новых темах в форуме', '1', "" . ($q['lenta_forum'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_foto', 'Уведомления о новых фото', '1', "" . ($q['lenta_foto'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_news', 'Уведомления о комментариях в новостях', '1', "" . ($q['lenta_news'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_news', 'Уведомления о сообщениях в чате', '1', "" . ($q['lenta_chat'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_avatar', 'Уведомления о смене аватаров', '1', "" . ($q['lenta_avatar'] ? " checked='checked'" : null) . "");
$doc->Checkbox('lenta_obmen', 'Уведомления о новых файлах', '1', "" . ($q['lenta_obmen'] ? " checked='checked'" : null) . "");

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

echo "</form>";

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