|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Alliance\DBStaticAlly; |
|
4
|
|
|
|
|
5
|
|
|
const WHO_IS_USER = 1; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* stat.php |
|
9
|
|
|
* |
|
10
|
|
|
* 2.0 copyright (c) 2010-2012 by Gorlum for http://supernova.ws |
|
11
|
|
|
* [!] Full rewrote |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
function stat_tpl_assign(&$template, $selected, $array_name, $array, $sn_group_stat_common) { |
|
15
|
|
|
global $who, $lang; |
|
16
|
|
|
|
|
17
|
|
|
// $sn_group_stat_common = sn_get_groups('STAT_COMMON'); |
|
18
|
|
|
foreach($array as $key => $value) { |
|
19
|
|
|
if($array_name == 'type' && $who == 2 && !in_array($key, $sn_group_stat_common)) { |
|
20
|
|
|
continue; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$header = isset($value['header']) ? $value['header'] : $lang['stat_type'][$key]; |
|
24
|
|
|
|
|
25
|
|
|
$template->assign_block_vars($array_name, array( |
|
26
|
|
|
'ID' => $key, |
|
27
|
|
|
'HEADER' => $header, |
|
28
|
|
|
'SELECTED' => $key == $selected, |
|
29
|
|
|
)); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$allow_anonymous = true; |
|
34
|
|
|
|
|
35
|
|
|
include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
|
36
|
|
|
|
|
37
|
|
|
lng_include('stat'); |
|
38
|
|
|
|
|
39
|
|
|
$sn_group_stat_common = sn_get_groups('STAT_COMMON'); |
|
40
|
|
|
$who = sys_get_param_int('who', WHO_IS_USER); |
|
41
|
|
|
$type = sys_get_param_int('type'); |
|
42
|
|
|
$type = $who != WHO_IS_USER && !in_array($type, $sn_group_stat_common) ? 1 : $type; |
|
43
|
|
|
$range = sys_get_param_int('range', 1); |
|
44
|
|
|
$source = sys_get_param_str('source'); |
|
45
|
|
|
|
|
46
|
|
|
$template = SnTemplate::gettemplate('stat_statistics', true); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$subject_list = array( |
|
49
|
|
|
1 => array('header' => $lang['stat_player']), |
|
50
|
|
|
); |
|
51
|
|
|
if(!$source) { |
|
52
|
|
|
$subject_list[2] = array('header' => $lang['stat_allys']); |
|
53
|
|
|
} |
|
54
|
|
|
stat_tpl_assign($template, $who, 'subject', $subject_list, $sn_group_stat_common); |
|
55
|
|
|
|
|
56
|
|
|
$stat_types = array( |
|
57
|
|
|
STAT_TOTAL => array( |
|
58
|
|
|
'type' => 'total', |
|
59
|
|
|
), |
|
60
|
|
|
|
|
61
|
|
|
STAT_FLEET => array( |
|
62
|
|
|
'type' => 'fleet', |
|
63
|
|
|
), |
|
64
|
|
|
|
|
65
|
|
|
STAT_TECH => array( |
|
66
|
|
|
'type' => 'tech', |
|
67
|
|
|
), |
|
68
|
|
|
|
|
69
|
|
|
STAT_BUILDING => array( |
|
70
|
|
|
'type' => 'build', |
|
71
|
|
|
), |
|
72
|
|
|
|
|
73
|
|
|
STAT_DEFENSE => array( |
|
74
|
|
|
'type' => 'defs', |
|
75
|
|
|
), |
|
76
|
|
|
|
|
77
|
|
|
STAT_RESOURCE => array( |
|
78
|
|
|
'type' => 'res', |
|
79
|
|
|
), |
|
80
|
|
|
|
|
81
|
|
|
STAT_RAID_TOTAL => array( |
|
82
|
|
|
'type' => 'raids', |
|
83
|
|
|
), |
|
84
|
|
|
|
|
85
|
|
|
STAT_RAID_WON => array( |
|
86
|
|
|
'type' => 'raidswin', |
|
87
|
|
|
), |
|
88
|
|
|
|
|
89
|
|
|
STAT_RAID_LOST => array( |
|
90
|
|
|
'type' => 'raidsloose', |
|
91
|
|
|
), |
|
92
|
|
|
|
|
93
|
|
|
STAT_LVL_BUILDING => array( |
|
94
|
|
|
'type' => 'lvl_minier', |
|
95
|
|
|
), |
|
96
|
|
|
|
|
97
|
|
|
STAT_LVL_TECH => array( |
|
98
|
|
|
'type' => 'player_rpg_tech_level', |
|
99
|
|
|
), |
|
100
|
|
|
|
|
101
|
|
|
STAT_LVL_RAID => array( |
|
102
|
|
|
'type' => 'lvl_raid', |
|
103
|
|
|
), |
|
104
|
|
|
); |
|
105
|
|
|
stat_tpl_assign($template, $type, 'type', $stat_types, $sn_group_stat_common); |
|
106
|
|
|
|
|
107
|
|
|
$Rank = $stat_types[$type]['type']; |
|
108
|
|
|
|
|
109
|
|
|
$is_common_stat = in_array($type, $sn_group_stat_common); |
|
110
|
|
|
$start = floor($range / 100 % 100) * 100; |
|
111
|
|
|
$query = db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source); |
|
112
|
|
|
|
|
113
|
|
|
// TODO - Не работает, если игроков на Блице > 100 |
|
114
|
|
|
$record_count = $source ? SN::$db->db_num_rows($query) : ($who == WHO_IS_USER ? db_user_count() : DBStaticAlly::db_ally_count()); |
|
115
|
|
|
|
|
116
|
|
|
$page_count = floor($record_count / 100); |
|
117
|
|
|
$pages = array(); |
|
118
|
|
|
for($i = 0; $i <= $page_count; $i++) { |
|
119
|
|
|
$first_element = $i * 100 + 1; |
|
120
|
|
|
$last_element = $first_element + 99; |
|
121
|
|
|
$pages[$first_element] = array( |
|
122
|
|
|
'header' => "{$first_element}-{$last_element}", |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$range = $range > $record_count ? $record_count : $range; |
|
127
|
|
|
stat_tpl_assign($template, $range, 'range', $pages, $sn_group_stat_common); |
|
128
|
|
|
|
|
129
|
|
|
while ($row = db_fetch($query)) { |
|
|
|
|
|
|
130
|
|
|
$row_stat = array( |
|
131
|
|
|
'ID' => $row['id'], |
|
132
|
|
|
'RANK' => $row['rank'], |
|
133
|
|
|
'RANK_CHANGE' => $row['rank_old'] ? $row['rank_old'] - $row['rank'] : 0, |
|
134
|
|
|
'POINTS' => HelperString::numberFloorAndFormat($row['points']), |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
if($who == WHO_IS_USER) { |
|
138
|
|
|
$row_stat['ALLY_NAME'] = $row['ally_name']; |
|
139
|
|
|
$row_stat['ALLY_ID'] = $row['ally_id']; |
|
140
|
|
|
empty($row['username']) ? $row['username'] = $row['name'] : false; |
|
141
|
|
|
$row_stat['NAME'] = player_nick_render_to_html($row, [ |
|
142
|
|
|
'icons' => empty($source), |
|
143
|
|
|
'color' => empty($source), |
|
144
|
|
|
]); |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
// // TODO - Добавлять реальное имя игрока на Блице для закрытого раунда |
|
148
|
|
|
} else { |
|
149
|
|
|
$row_stat['MEMBERS'] = $row['ally_members']; |
|
150
|
|
|
$row_stat['POINTS_PER_MEMBER'] = HelperString::numberFloorAndFormat(floor($row['points'] / $row['ally_members'])); |
|
151
|
|
|
$row_stat['NAME'] = $row['name']; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$template->assign_block_vars('stat', $row_stat); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
$next_run = sys_schedule_get_prev_run(SN::$config->stats_schedule, SN::$config->var_stat_update, true); |
|
158
|
|
|
$template->assign_vars(array( |
|
159
|
|
|
'REFRESH_DATE' => SN::$config->var_stat_update ? date(FMT_DATE_TIME, strtotime(SN::$config->var_stat_update) + SN_CLIENT_TIME_DIFF) : '', |
|
160
|
|
|
'NEXT_DATE' => $next_run ? date(FMT_DATE_TIME, $next_run + SN_CLIENT_TIME_DIFF) : '', |
|
161
|
|
|
'RANGE' => $range, |
|
162
|
|
|
'SUBJECT' => $who, |
|
163
|
|
|
'TYPE' => $type, |
|
164
|
|
|
'USER_ALLY' => $user['ally_id'], |
|
165
|
|
|
// TODO - Для блица - вытаскивать blitz_player_id и подсвечивать пользователя на блице |
|
166
|
|
|
'USER_ID' => $source ? 0 : $user['id'], |
|
167
|
|
|
'SOURCE' => $source, |
|
168
|
|
|
'STATS_HIDE_PM_LINK' => SN::$config->stats_hide_pm_link || $source, |
|
169
|
|
|
)); |
|
170
|
|
|
|
|
171
|
|
|
SnTemplate::display($template, $lang['stat_header']); |
|
172
|
|
|
|