You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TS-Website/include/adminlist.php

113 lines
3.9 KiB

9 years ago
<?php
require_once __DIR__ . "/tsutils.php";
require_once __DIR__ . "/cacheutils.class.php";
9 years ago
$cacheutils = new CacheUtils('adminlist');
9 years ago
if($cacheutils->isExpired()) {
$cacheutils->setValue([getAdminList(), date('d.m.Y H:i:s')], 120);
9 years ago
}
$adminlist = $cacheutils->getValue();
9 years ago
// FUNCTIONS
function getAdminList() {
global $config;
9 years ago
global $lang;
$admingroups = $config["adminlist"];
$localIcons = array(100, 200, 300, 400, 500, 600);
9 years ago
try {
$tsAdmin = getTeamspeakConnection();
9 years ago
$output = "";
foreach ($admingroups as $group) {
if (!array_key_exists((string)$group, $tsAdmin->serverGroupList()))
9 years ago
continue;
$group = $tsAdmin->serverGroupGetById($group);
$icon = '';
if ($group["iconid"]) {
if (!$group->iconIsLocal("iconid")) {
$groupicon = getGroupIcon($tsAdmin, $group);
if ($groupicon) {
$icon = '<img src="data:' . TeamSpeak3_Helper_Convert::imageMimeType($groupicon) . ';base64,' . base64_encode($groupicon) . '" alt="Group icon" /> ';
}
} elseif (in_array($group["iconid"], $localIcons)) {
$icon = '<img src="lib/ts3phpframework/images/viewer/group_icon_' . $group["iconid"] . '.png" alt="Group icon" /> ';
}
}
$output .= "<p class=\"groupname\">$icon$group</p>";
$clients = $group->clientList();
if (empty($clients)) {
9 years ago
$output .= '<p class="text-center"><i>' . translate($lang["adminlist"]["emptygroup"]) . '</i></p>';
continue;
}
$onlineClients = [];
$offlineClients = [];
foreach ($clients as $userInfo) {
9 years ago
$user = getClientByDbid($tsAdmin, $userInfo['cldbid']);
if($user["client_type"]) continue;
if (!$user) {
$offlineClients[] = '<p><span class="label label-primary iconspacer">' . htmlspecialchars($userInfo['client_nickname']) . '</span><span class="label label-danger pull-right">' . translate($lang["adminlist"]["status"]["offline"]) . '</span></p>';
9 years ago
continue;
}
$userAwayTitle = '';
if(!$user["client_away_message"]) {
$userAway = translate($lang["adminlist"]["status"]["away"]);
} else {
$userAway = htmlspecialchars($user["client_away_message"]);
if (mb_strlen($userAway) > 23) {
$userAwayTitle = 'title="' . $userAway . '"';
$userAway = mb_substr($userAway, 0, 23) . "...";
}
}
$onlineClients[] = '<p><img src="lib/ts3phpframework/images/viewer/' . $user->getIcon() . '.png" alt="User status">' . '<span class="label label-primary">' . htmlspecialchars($user) . '</span>' . ($user['client_away'] ? '<span class="label label-warning pull-right" ' . $userAwayTitle . '>' . $userAway . '</span>' : '<span class="label label-success pull-right">' . translate($lang["adminlist"]["status"]["online"]) . '</span>') . '</p>';
9 years ago
}
foreach (array_merge($onlineClients, $offlineClients) as $str)
$output .= $str;
9 years ago
}
9 years ago
return $output;
} catch (TeamSpeak3_Exception $e) {
9 years ago
return '<div class="alert alert-danger"><p class="text-center">' . translate($lang["general"]["scripterror"], [$e->getCode(), $e->getMessage()]) . '</p></div>';
9 years ago
}
9 years ago
}
function getClientByDbid($tsAdmin, $cldbid) {
try {
return $tsAdmin->clientGetByDbid($cldbid);
} catch (TeamSpeak3_Exception $e) {
9 years ago
return false;
}
}
function getGroupIcon($tsAdmin, $group) {
try {
return $group->iconDownload();
} catch (TeamSpeak3_Exception $e) {
return false;
}
}
9 years ago
// echo getAdminList();