<?php
require_once 'conn.php';
checkLogin();
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>管理区域</title>
    <link rel="stylesheet" href="css/common.css" type="text/css" />
    <link rel="stylesheet" href="css/alert.css" type="text/css" />
    <script src="system/js/jquery-1.7.2.min.js"></script>
    <script src="js/js.js"></script>
    <style>
        body {
            margin: 0;
            padding: 20px;
            background: #fff;
        }
        #man_zone {
            margin-left: 0;
        }
    </style>
</head>
<body class="clear">
<?php // require_once 'panel.php'; ?>
<div id="man_zone">
<?php
// 获取所有em_role等于当前用户employee_id的员工
$employeeResult = $conn->query("SELECT id, em_user FROM employee WHERE em_role=" . $_SESSION['employee_id']);

if ($employeeResult) {
    while ($employeeRow = $employeeResult->fetch_assoc()) {
?>
    <div class="tagclound">
        <h1 class="tagCloundHead2"><?= htmlspecialcharsFix($employeeRow['em_user']) ?>的客户画像:</h1>
        <div class="tagArea">
        <?php
        // 对每个员工,查询其添加的所有标签
        $tagResult = $conn->query("SELECT tagName, COUNT(id) as count FROM tagtable WHERE employeeId=" . $employeeRow['id'] . " GROUP BY tagName");
        
        if ($tagResult) {
            while ($tagRow = $tagResult->fetch_assoc()) {
                echo '<a href="subTag.php?employeeId=' . $employeeRow['id'] . '&tagName=' . urlencode($tagRow['tagName']) . '">' . 
                     htmlspecialcharsFix($tagRow['tagName']) . '(' . $tagRow['count'] . ')</a>';
            }
        }
        ?>
        </div>
    </div>
<?php
    }
}
?>
</div>
</body>
</html>