<?php
if (array_key_exists('countNot', $_SESSION) === false)
    $_SESSION['countNot'] = 0;
$u = DB:: $pdo->queryFetch("SELECT u.*, (SELECT COUNT(*) FROM `mail` AS m,
		        (SELECT MAX(id) AS id FROM `mail` WHERE `unlink` != :id AND (`id_kont` = :id) GROUP BY IF(`id_user` = :id, `id_kont`, `id_user`)) as max
		        WHERE m.id = max.id AND m.read = '0' AND (m.id_kont = :id) AND m.unlink != :id) as new_mail_count FROM `users` u WHERE u.`id` = :id LIMIT 1;", array(':id' => $user['id']));
$isPlay = false;
$sumCount = $u['new_mail_count'] + $u['count_new_notice'];
if ($sumCount > 0 && $_SESSION['countNot'] != $sumCount) {
    $isPlay = true;
}
$_SESSION['countNot'] = $sumCount;
$data = [
    'count_mail' => $u['new_mail_count'],
    'count_notice' => $u['count_new_notice'],
    'isPlay' => $isPlay
];

header('Cache-Control: private, max-age=0, no-cache');
echo json_encode($data);
