Created
October 17, 2014 16:14
-
-
Save Zalvie/9232bfd4a415f413abfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Ref: http://community.mybb.com/thread-157011.html | |
# Ref: http://risk-rpg.net/groupstats.php | |
define("IN_MYBB", 1); | |
require_once "./global.php"; | |
$usergroups = $cache->read('usergroups'); | |
$groups = array('Vampire Groups' => [18, 21, 22], | |
'Vampire Species' => [34, 36, 37, 35, 39], | |
'Were Groups' => [19, 20, 40, 23], | |
'Were Species' => [25, 26, 27, 28, 29, 31, 32, 33], | |
'Humans & Psychics' => [11, 24], | |
); | |
array_walk($groups, function (&$g) { | |
$g = array_fill_keys($g, []); | |
}); | |
$query = $db->query("SELECT uid, usergroup, additionalgroups, fid9 as sex FROM " . TABLE_PREFIX . "users u LEFT JOIN " . TABLE_PREFIX . "userfields t ON u.uid=t.ufid where fid9 is not null"); | |
while ($user = $db->fetch_array($query)) | |
foreach (array_unique(array_merge([(int)$user['usergroup']], array_map('intval', array_filter(explode(',', (string)$user['additionalgroups']))))) as $gid) | |
foreach ($groups as &$group) | |
if (isset($group[$gid]) && !empty($user['sex'])) | |
$group[$gid][] = (string)$user['sex'] == 'Male'; | |
foreach ($groups as $title => $gids) { | |
echo "<span class='table_title'>{$title}</span><span class='table_rule'> </span> <div class='announcementbox'><table border='0' width='100%' cellspacing='{$theme['borderwidth']}' cellpadding='{$theme['tablespace']}' class='guidebook_table notableborder smalltext'>"; | |
echo "<tr><th width='25%'>Group</th><th align='center' width='25%'>Males</th><th align='center' width='25%'>Females</th><th align='center' width='25%'>Total</th></tr>"; | |
$total = ['f' => 0, 'm' => 0]; | |
foreach ($gids as $gid => $genders) { | |
if (!isset($usergroups[$gid])) | |
continue; | |
$amount = array_count_values(array_map('intval', $genders)); | |
$total['f'] += (int)$amount[0]; | |
$total['m'] += (int)$amount[1]; | |
echo '<tr>'; | |
echo sprintf('<td><a href="/index.php?action=viewgroups&gid=%d">%s</a></td>', $usergroups[$gid]['gid'], htmlentities($usergroups[$gid]['title'])); | |
echo sprintf('<td align="center">%d</td>', (int)$amount[1]); | |
echo sprintf('<td align="center">%d</td>', (int)$amount[0]); | |
echo sprintf('<td align="center">%d</td>', (int)array_sum($amount)); | |
echo '</tr>'; | |
} | |
echo '<tr>'; | |
echo '<td>Total</td>'; | |
echo sprintf('<td align="center">%d</td>', $total['m']); | |
echo sprintf('<td align="center">%d</td>', $total['f']); | |
echo sprintf('<td align="center">%d</td>', (int)count($gids, COUNT_RECURSIVE) - count($gids)); | |
echo '</tr>'; | |
echo "</table>"; | |
echo "</div>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment