<?php

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

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

only_reg();

$doc->Title('Уведомления');

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

aut();
err();

$get = $_GET['id'];
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$get'"));
$q = mysql_fetch_array(mysql_query("SELECT * FROM `friends` WHERE `user` = '$get'"));


#Навигация
echo "<div class='card-header'>";
echo "<a href='/' data-toggle='tooltip' data-placement='right' title='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='/info.php?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 "</div>";

only_reg();

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

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

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

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

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

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

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

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

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

err();

echo "<form class='list-group-item' 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) . "");

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

echo "</form>";

$doc->Link('list-group-item', 'index.php?act=feed', 'arrow-left', 'Вернуться');

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