Файл: pages/admin/edit-access.php
Строк: 61
<?php
declare(strict_types=1);
// Physical module map v50.6.
if (!defined('GAME_ROOT')) define('GAME_ROOT', dirname(__DIR__, 2));
chdir(GAME_ROOT);
if (PHP_SAPI !== 'cli') { $_SERVER['PHP_SELF']='/edit_access.php'; $_SERVER['SCRIPT_NAME']='/edit_access.php'; }
require_once './system/common.php';
require_once './system/functions.php';
require_once './system/user.php';
if(!$user || (int)($user['access']??0)<2){ header('Location: /'); exit; }
$targetId=(int)($_GET['val']??$_POST['val']??0);
$target=$targetId>0?db_fetch_one('SELECT `id`,`login`,`access` FROM `users` WHERE `id`=:id LIMIT 1',['id'=>$targetId]):null;
if(!$target || $targetId===(int)$user['id'] || (int)$target['access']>=(int)$user['access']){ $_SESSION['err']='Нельзя редактировать права равного или старшего администратора.'; header('Location: /'); exit; }
$labels=[0=>'Пользователь',1=>'Модератор',2=>'Администратор'];
$maxGrant=((int)$user['id']===1)?2:max(0,(int)$user['access']-1);
if(($_SERVER['REQUEST_METHOD']??'GET')==='POST'){
security_require_csrf();
$newAccess=(int)($_POST['access']??-1);
if(!isset($labels[$newAccess]) || $newAccess>$maxGrant){ $_SESSION['err']='Нельзя выдать выбранный уровень прав.'; }
else{
db_execute('UPDATE `users` SET `access`=:a WHERE `id`=:id',['a'=>$newAccess,'id'=>$targetId]);
if(function_exists('moderation_log')) moderation_log((int)$user['id'],$targetId,'role','Права: '.$labels[$newAccess],0,'apply');
$_SESSION['ok']='Права игрока изменены.';
header('Location: /user/'.$targetId.'/'); exit;
}
header('Location: /admin/edit_access?val='.$targetId); exit;
}
$title='Редактор прав'; require './system/h.php';
?>
<div class="block_light center"><b>Редактор прав</b><br><?=security_html((string)$target['login'])?>, ID <?=$targetId?></div>
<div class="block_zero center"><form method="post" action="/admin/edit_access?val=<?=$targetId?>">
<?=security_csrf_field()?><input type="hidden" name="val" value="<?=$targetId?>">
Выдать права:<br><select name="access">
<?php foreach($labels as $value=>$label): if($value>$maxGrant) continue; ?><option value="<?=$value?>" <?=$value===(int)$target['access']?'selected':''?>><?=security_html($label)?></option><?php endforeach; ?>
</select><br><button class="btn" type="submit">Изменить</button>
</form></div>
<div class="menuList"><li><a href="/user/<?=$targetId?>/"><img src="/images/icon/arrow.png" alt=""> Вернуться к профилю</a></li></div>
<?php require './system/f.php'; ?>