Файл: system/classes/User.php
Строк: 142
<?php
Class User {
private static $id = false;
private static $settings = array();
private static $profile = array();
public static function aut()
{
global $db;
if (!empty(self::$id)) return true;
if (isset($_SESSION['login']) && isset($_SESSION['password'])) {
$us_l = $_SESSION['login'];
$us_p = $_SESSION['password'];
} elseif (isset($_COOKIE['login']) && isset($_COOKIE['password'])) {
$us_l = $_COOKIE['login'];
$us_p = $_COOKIE['password'];
}
if (isset($us_l) && isset($us_p)) {
$idi = $db->fass("SELECT `id` FROM `users` where `login` = '".$db->guard($us_l)."' and `password` = '".$db->guard($us_p)."' LIMIT 1");
if (!empty($idi)) {
self::$id = $idi['id'];
return true;
} else {
return false;
}
} else {
return false;
}
}
public static function ID()
{
return self::$id;
}
public static function settings($var, $uid=null)
{
global $db;
if (self::aut()) {
if (!empty($uid)) {
return $db->fass("SELECT ".$var." FROM `user_settings` where `kto` = '".$uid."' LIMIT 1")[$var];
}
if (empty(self::$settings)) {
self::$settings = $db->fass("SELECT * FROM `user_settings` where `kto` = '".self::ID()."' LIMIT 1");
return self::$settings[$var];
} else {
return self::$settings[$var];
}
} else {
return Core::config($var);
}
}
public static function profile($var)
{
global $db;
if (self::aut()) {
if (empty(self::$profile)) {
self::$profile = $db->fass("SELECT * FROM `users` where `id` = '".self::ID()."' LIMIT 1");
return self::$profile[$var];
} else {
return self::$profile[$var];
}
}
}
public static function level()
{
return self::profile('level');
}
public static function banned($uid, $only_check=false)
{
global $db;
$ban=$db->fass("select * from `ban` where `komy` = '".$uid."' and `time_end` > '".time()."' LIMIT 1");
if ($only_check) return $ban;
if ($ban) {
Tmp::div('error', Language::config('user_baned'));
Tmp::div('main', Language::config('kto_add_ban').': '.nick_new($ban['kto']).'<br>'.Language::config('prich').': '.$ban['message'].'<br> '.Language::config('osvob').': '.times($ban['time_end']));
}
}
public static function panel()
{
global $db;
if(self::aut()) {
$mes = $db->fass_c("SELECT COUNT(*) as count FROM `dialogs_message` WHERE `komy` = '".self::ID()."' and `readln` = '0'");
$journal = $db->fass_c("SELECT COUNT(*) as count FROM `journal` WHERE `komy` = '".self::ID()."' and `readln` = '0'");
$friends = $db->fass_c("SELECT COUNT(*) as count FROM `friends` WHERE `komy` = '".self::ID()."' and `status` = '0'");
echo '<div class="panel flex">';
echo (self::level() >= 2 ? '<a href="/apanel">'.img('admin.png').'</a>' : NULL). '<a href="/panel">'.img('panel.png').''.($mes > 0 || $journal > 0 || $friends > 0 ? NULL: ' '.Language::config('panel')).'</a>';
if ($mes > 0 || $journal > 0 || $friends > 0) {
echo '<a href="/dialogs">'.img('mail.png').''.($mes > 0 ? '<span>+'.$mes.'</span>' : '').'</a>';
} else {
echo '<a href="/dialogs">'.img('mail.png').' '.Language::config('dialogs').'</a>';
}
if ($journal > 0) {
echo '<a href="/journal">'.img('notify.png').'<span>'.($journal > 0 ? '+'.$journal: '').'</span></a>';
}
echo ($friends > 0 ? '<a href="/friends/bid">'.img('friends.png').'<span>+'.$friends.'</span></a>': NULL);
echo '<a href="/exit">'.img('exit.png').''.($mes > 0 || $friends > 0 || $journal > 0 ? NULL: ' '.Language::config('exit')).'</a>';
echo '</div>';
} else {
echo '<div class="panel flex"><a href="/login"><img src="/design/styles/default/img/login.png"> '.Language::config('aut').'</a><a href="/reg"><img src="/design/styles/default/img/reg.png"> '.Language::config('reg').'</a></div>';
if($_SERVER['REQUEST_URI'] !== '/'){
if(Core::config('close') == 0){
header('Location: /');
}
}
}
}
}
?>