Файл: sys/classes/user.class.php
Строк: 100
<?php
class user {
static function browser() {
$user_agent = $_SERVER["HTTP_USER_AGENT"];
if (strpos($user_agent, "Firefox") !== false) {
$browser = "Firefox";
} elseif (strpos($user_agent, "Opera") !== false) {
$browser = "Opera";
} elseif (strpos($user_agent, "Chrome") !== false) {
$browser = "Chrome";
} elseif (strpos($user_agent, "MSIE") !== false) {
$browser = "Internet Explorer";
} elseif (strpos($user_agent, "Safari") !== false) {
$browser = "Safari";
} else {
$browser = "Неизвестный";
}
echo "$browser";
}
static function collision($massive, $im = 0) {
global $user;
$new = false;
for ($i = 0; $i < count($massive); $i++) {
$collision_q = mysql_query("SELECT * FROM `user_collision` WHERE `id_user` = '" . $massive[$i] . "' OR `id_user2` = '" . $massive[$i] . "'");
while ($collision = mysql_fetch_assoc($collision_q)) {
if ($collision['id_user'] == $massive[$i]) {
$coll = $collision['id_user2'];
} else {
$coll = $collision['id_user'];
}
$ank_coll2 = self::get_user($coll);
if (!in_array($coll, $massive) && ($user['level'] > $ank_coll2['level']) && ($im == 0 || $user['id'] != $ank_coll2['id'])) {
$massive[] = $coll;
$new = true;
}
}
}
if ($new) {
$massive = self::collision($massive);
}
return $massive;
}
#получаем данные пользователя и уровень прав (+ кеширование)
static function get_user($user_id = 0) {
if ($user_id == 0) {
#бот
$ank2['id'] = 0;
$ank2['nick'] = 'Система';
$ank2['level'] = 999;
$ank2['sex'] = 1;
$ank2['country'] = 'США';
$ank2['browser'] = 'web';
$ank2['ncolor'] = '#FF0000';
$ank2['ncolor2'] = '#FF0000';
$ank2['group_name'] = 'Системный робот';
$ank2['group_access'] = 0;
$ank2['ank_about_me'] = 'Создан для уведомлений';
return $ank2;
} else {
static $users; #переменная не удаляется после вызова функции
$user_id = intval($user_id);
$users[0] = false;
if (!isset($users[$user_id])) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$user_id'"), 0) == 1) {
$users[$user_id] = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '$user_id' LIMIT 1"));
$tmp_us = mysql_fetch_assoc(mysql_query("SELECT `level`,`name` AS `group_name` FROM `user_group` WHERE `id` = '" . $users[$user_id]['group_access'] . "' LIMIT 1"));
if ($tmp_us['group_name'] == null) {
$users[$user_id]['level'] = 0;
$users[$user_id]['group_name'] = 'Пользователь';
} else {
$users[$user_id]['level'] = $tmp_us['level'];
$users[$user_id]['group_name'] = $tmp_us['group_name'];
}
} else {
$users[$user_id] = false;
}
}
return $users[$user_id];
}
}
static function access($access, $u_id = null, $exit = false) {
if ($u_id == null) {
global $user;
} else {
$user = self::get_user($u_id);
}
if (!isset($user['group_access']) || $user['group_access'] == null) {
if ($exit !== false) {
header("Location: $exit");
exit;
} else {
return false;
}
}
if ($exit !== false) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user_group_access` WHERE `id_group` = '$user[group_access]' AND `id_access` = '" . mysql_real_escape_string($access) . "'"), 0) == 0) {
header("Location: $exit");
exit;
}
} else {
return mysql_result(mysql_query("SELECT COUNT(*) FROM `user_group_access` WHERE `id_group` = '$user[group_access]' AND `id_access` = '" . mysql_real_escape_string($access) . "'"), 0);
}
}
#только для зарегистрированых
static function only_reg($link = NULL) {
global $user;
if (!isset($user)) {
if ($link == NULL) {
$link = H . 'index.php?' . SID;
}
header("Location: $link");
exit;
}
}
#только для незарегистрированых
static function only_unreg($link = NULL) {
global $user;
if (isset($user)) {
if ($link == NULL) {
$link = H . 'index.php?' . SID;
}
header("Location: $link");
exit;
}
}
#только для тех, у кого уровень доступа больше или равен $level
static function only_level($level = 0, $link = NULL) {
global $user;
if (!isset($user) || $user['level'] < $level) {
if ($link == NULL) {
$link = '/index.php?' . SID;
}
header("Location: $link");
exit;
}
}
}