1
<?php
2
/**
3
 *   File functions:
4
 *   Land stats
5
 */
6
//
7
// $Id$
8
9
$title = 'Statystyki ogólne krainy';
10
$title1 = $title;
11
require('includes/head.php');
12
13
/**
14
* Set the language
15
*/
16
require('languages/'.$player -> lang.'/landstats.php');
17
18
if ($player -> location != 'Altara' && $player -> location != 'Ardulith')
19
{
20
    error (ERROR);
21
}
22
23
$smarty -> cache_dir = 'cache/';
24
$smarty -> caching = 2;
25
$smarty -> cache_lifetime = 3600;
26
27
function countPercentage (&$arrCountPcts, &$arrPlayersAmount)
28
{
29
	for ($i = 0, $k = count($arrCountPcts); $i < $k; $i++)
30
	{
31
		$arrCountPcts[$i][2] = round($arrCountPcts[$i][1] / $arrPlayersAmount[0] * 100, 2);
32
	}
33
	return $arrCountPcts;
34
}
35
36
$oldFetchMode = $db -> SetFetchMode(ADODB_FETCH_NUM);
37
$arrPlayersAmount = $db -> GetRow('SELECT count(id) FROM `players`');
38
$arrAll[0] = $db -> GetAll('SELECT `gender`, count(*) FROM `players` GROUP BY `gender` ORDER BY count(*) DESC');
39
$arrAll[1] = $db -> GetAll('SELECT `rasa`, count(*) FROM `players` GROUP BY `rasa` ORDER BY count(*) DESC');
40
$arrAll[2] = $db -> GetAll('SELECT `klasa`, count(*) FROM `players` GROUP BY `klasa` ORDER BY count(*) DESC');
41
$arrAll[3] = $db -> GetAll('SELECT `deity`, count(*) FROM `players` GROUP BY `deity` ORDER BY count(*) DESC');
42
43
countPercentage($arrAll[0], $arrPlayersAmount);
44
countPercentage($arrAll[1], $arrPlayersAmount);
45
countPercentage($arrAll[2], $arrPlayersAmount);
46
countPercentage($arrAll[3], $arrPlayersAmount);
47
48
for ($i = 0; $i < 4; $i++)
49
{
50
	if ($arrAll[0][$i][0] == 'M')
51
	{
52
		$arrAll[0][$i][0] = 'Mężczyzna';
53
	}
54
	elseif ($arrAll[0][$i][0] == 'F')
55
	{
56
		$arrAll[0][$i][0] = 'Kobieta';
57
	}
58
}
59
60
$strPre = 'Brak wybrane';
61
$arrPost = array('j płci', 'j rasy', 'j klasy', 'go bóstwa');
62
63
for ($i = 0; $i < 4; $i++)
64
{
65
	for ($k = 0, $l = count($arrAll[$i]); $k < $l; $k++)
66
	{
67
		$strNotChosen = $strPre.$arrPost[$i];
68
		if ($arrAll[$i][$k][0] == '')
69
		{
70
			$arrAll[$i][$k][0] = $strNotChosen;
71
		}
72
	}
73
}
74
75
$smarty -> assign_by_ref('Desc', $arrDesc);
76
$smarty -> assign_by_ref('Tables', $arrTableNames);
77
$smarty -> assign_by_ref('Players', $arrPlayersAmount[0]);
78
$smarty -> assign_by_ref('Stats', $arrAll);
79
80
$db -> SetFetchMode($oldFetchMode);
81
82
$smarty -> display('landstats.tpl');
83
$smarty -> caching = 0;
84
85
require('includes/foot.php');
86
?>