文件
Parlz/join_group.php
2026-06-04 22:42:27 +08:00

101 行
3.6 KiB
PHP

<?php
// 启用页面混淆和Gzip压缩
include 'minify.php';
// 启动会话
session_start();
// 引入模块
require_once 'modules/user.php';
require_once 'modules/group.php';
// 数据库初始化已在db.php中完成
// 获取群号参数
$group_id = isset($_GET['group_id']) ? $_GET['group_id'] : '';
// 检查群号是否存在
$group = null;
$error = '';
if ($group_id) {
$group = getGroupByGroupId($group_id);
if (!$group) {
$error = '群组不存在或群号错误';
}
} else {
$error = '缺少群号参数';
}
// 如果用户已登录且群组存在,自动尝试加入
if (isLoggedIn() && $group) {
$userId = $_SESSION['user_id'];
// 检查用户是否已经是群成员
if (isGroupMember($group['id'], $userId)) {
$error = '您已经是该群成员';
} else {
// 尝试加入群组
if (joinGroupByGroupId($group_id, $userId)) {
// 加入成功,跳转到主页面
header('Location: index.php?joined_group=' . urlencode($group['name']));
exit;
} else {
$error = '加入群组失败';
}
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>加入群组</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<div class="login-container">
<div class="login-box">
<h1 class="app-title">Parlz</h1>
<div class="tab-content active">
<h2 style="text-align: center; margin-bottom: 20px;"><i class="fas fa-users"></i> 加入群组</h2>
<?php if ($error): ?>
<div class="error">
<i class="fas fa-exclamation-circle"></i> <?php echo $error; ?>
</div>
<?php endif; ?>
<?php if ($group && !$error): ?>
<div style="margin: 20px 0; padding: 20px; background: #f5f5f5; border-radius: 8px;">
<div style="font-size: 24px; font-weight: bold; color: #333; margin-bottom: 10px;"><?php echo $group['name']; ?></div>
<div style="font-size: 16px; color: #666; margin-bottom: 20px;">群号: <?php echo $group['group_id']; ?></div>
<p style="text-align: center;">点击下方按钮加入群组</p>
</div>
<?php if (isLoggedIn()): ?>
<button class="login-btn" onclick="window.location.href='index.php'">
<i class="fas fa-arrow-left"></i> 返回首页
</button>
<?php else: ?>
<div style="margin: 20px 0; padding: 20px; background: #e3f2fd; border-radius: 8px;">
<p style="text-align: center; margin-bottom: 15px;">请先登录后加入群组</p>
<a href="index.php" class="login-btn">
<i class="fas fa-sign-in-alt"></i> 去登录
</a>
</div>
<?php endif; ?>
<?php else: ?>
<button class="login-btn" onclick="window.location.href='index.php'">
<i class="fas fa-arrow-left"></i> 返回首页
</button>
<?php endif; ?>
</div>
</div>
</div>
</body>
</html>