if (isset($_SESSION['loggedIn']))
{
return databaseContainsAuthor($_SESSION['login'], $_SESSION['password']);
}
}
/* Функция проверяет наличие в БД пользователя с переданной парой логин – пароль */
function databaseContainsAuthor($login, $password)
{
include $_SERVER['DOCUMENT_ROOT'].'/chat/dsn.php';
try
{
$sql = 'SELECT COUNT(*) FROM users WHERE login = :login AND password = :password';
$s = $dsn->prepare($sql);
$s->bindValue(':login', $login);
$s->bindValue(':password', $password);
$s->execute();
}
catch (PDOException $e)
{
echo $e->getMessage();
exit();
}
$row = $s->fetch();
if ($row[0] > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
/* Права для пользователя */
function userHasRole($role)
{
include $_SERVER['DOCUMENT_ROOT'].'/chat/dsn.php';
if (isset($_SESSION['login'])) {
try
{
$sql = "SELECT COUNT(*) FROM users
INNER JOIN authorrole ON users.id = authorid
INNER JOIN role ON roleid = role.id
WHERE login = :login AND role.id = :roleId";
$s = $dsn->prepare($sql);
$s->bindValue(':login', $_SESSION['login']);
$s->bindValue(':roleId', $role);
$s->execute();
}
catch (PDOException $e)
{