1
|
|
|
<?php
|
2
|
|
|
/* zKillboard
|
3
|
|
|
* Copyright (C) 2012-2015 EVE-KILL Team and EVSCO.
|
4
|
|
|
*
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
8
|
|
|
* (at your option) any later version.
|
9
|
|
|
*
|
10
|
|
|
* This program is distributed in the hope that it will be useful,
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
|
|
* GNU Affero General Public License for more details.
|
14
|
|
|
*
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
|
|
*/
|
18
|
|
|
|
19
|
|
|
// Find the regionID
|
20
|
|
|
if(!is_numeric($region))
|
21
|
|
|
$regionID = (int) Db::queryField("SELECT regionID FROM ccp_regions WHERE regionName = :regionName", "regionID", array(":regionName" => $region), 3600);
|
22
|
|
|
else // Verify it exists
|
23
|
|
|
$regionID = (int) Db::queryField("SELECT regionID FROM ccp_regions WHERE regionID = :regionID", "regionID", array(":regionID" => (int) $region), 3600);
|
24
|
|
|
|
25
|
|
|
// If the regionID we get from above is zero, don't even bother anymore.....
|
26
|
|
|
if($regionID == 0)
|
27
|
|
|
$app->redirect("/");
|
28
|
|
|
elseif(!is_numeric($region)) // if region isn't numeric, we redirect TO the regionID!
|
29
|
|
|
$app->redirect("/region/{$regionID}/");
|
30
|
|
|
|
31
|
|
|
// Now we figure out all the parameters
|
32
|
|
|
$parameters = Util::convertUriToParameters();
|
33
|
|
|
|
34
|
|
|
// Unset the region => id, and make it regionID => id
|
35
|
|
|
unset($parameters["region"]);
|
36
|
|
|
$parameters["regionID"] = $regionID;
|
37
|
|
|
$parameters["index"] = "regionID_dttm";
|
38
|
|
|
|
39
|
|
|
// Make sure that the pageType is correct..
|
40
|
|
|
$subPageTypes = array("page", "groupID", "month", "year", "shipTypeID");
|
41
|
|
|
if(in_array($pageType, $subPageTypes))
|
42
|
|
|
$pageType = "overview";
|
43
|
|
|
|
44
|
|
|
// Some defaults
|
45
|
|
|
@$page = max(1, $parameters["page"]);
|
|
|
|
|
46
|
|
|
$limit = 50;
|
47
|
|
|
$parameters["limit"] = $limit;
|
48
|
|
|
$parameters["page"] = $page;
|
49
|
|
|
|
50
|
|
|
// and now we fetch the info!
|
51
|
|
|
$detail = Info::getRegionDetails($regionID, $parameters);
|
52
|
|
|
|
53
|
|
|
// Define the page information and scope etc.
|
54
|
|
|
$pageName = isset($detail["regionName"]) ? $detail["regionName"] : "???";
|
55
|
|
|
$columnName = "regionID";
|
56
|
|
|
$mixedKills = $pageType == "overview" && UserConfig::get("mixKillsWithLosses", true);
|
57
|
|
|
|
58
|
|
|
// Load kills for the various pages.
|
59
|
|
|
$mixed = $pageType == "overview" ? Kills::getKills($parameters) : array();
|
60
|
|
|
$kills = $pageType == "kills" ? Kills::getKills($parameters) : array();
|
61
|
|
|
|
62
|
|
|
$topLists = array();
|
63
|
|
|
$topKills = array();
|
64
|
|
|
if ($pageType == "top") {
|
65
|
|
|
$topParameters = $parameters; // array("limit" => 10, "kills" => true, "$columnName" => $regionID);
|
66
|
|
|
$topParameters["limit"] = 10;
|
67
|
|
|
$topParameters["year"] = date("Y");
|
68
|
|
|
$topParameters["month"] = date("m");
|
69
|
|
|
$topParameters["kills"] = true;
|
70
|
|
|
|
71
|
|
|
$topLists[] = array("type" => "character", "data" => Stats::getTopPilots($topParameters, true));
|
72
|
|
|
$topLists[] = array("type" => "corporation", "data" => Stats::getTopCorps($topParameters, true));
|
73
|
|
|
$topLists[] = array("type" => "alliance", "data" => Stats::getTopAllis($topParameters, true));
|
74
|
|
|
$topLists[] = array("type" => "ship", "data" => Stats::getTopShips($topParameters, true));
|
75
|
|
|
$topLists[] = array("type" => "system", "data" => Stats::getTopSystems($topParameters, true));
|
76
|
|
|
$topLists[] = array("type" => "weapon", "data" => Stats::getTopWeapons($topParameters, true));
|
77
|
|
|
}
|
78
|
|
|
else
|
79
|
|
|
{
|
80
|
|
|
$p = $parameters;
|
81
|
|
|
$numDays = 7;
|
82
|
|
|
$p["limit"] = 10;
|
83
|
|
|
$p["pastSeconds"] = $numDays * 86400;
|
84
|
|
|
$p["kills"] = $pageType != "losses";
|
85
|
|
|
|
86
|
|
|
$topLists[] = Info::doMakeCommon("Top Characters", "characterID", Stats::getTopPilots($p));
|
87
|
|
|
$topLists[] = Info::doMakeCommon("Top Corporations", "corporationID", Stats::getTopCorps($p));
|
88
|
|
|
$topLists[] = Info::doMakeCommon("Top Ships", "shipTypeID", Stats::getTopShips($p));
|
89
|
|
|
$topLists[] = Info::doMakeCommon("Top Systems", "solarSystemID", Stats::getTopSystems($p));
|
90
|
|
|
|
91
|
|
|
$p["limit"] = 5;
|
92
|
|
|
$topKills = Stats::getTopIsk($p);
|
93
|
|
|
}
|
94
|
|
|
|
95
|
|
|
// Fix the history data!
|
96
|
|
|
$detail["history"] = $pageType == "stats" ? Summary::getMonthlyHistory($columnName, $regionID) : array();
|
97
|
|
|
|
98
|
|
|
// Stats
|
99
|
|
|
$cnt = 0;
|
100
|
|
|
$cnid = 0;
|
101
|
|
|
$stats = array();
|
102
|
|
|
$totalcount = ceil(count($detail["stats"]) / 4);
|
103
|
|
|
foreach ($detail["stats"] as $q) {
|
104
|
|
|
if ($cnt == $totalcount) {
|
105
|
|
|
$cnid++;
|
106
|
|
|
$cnt = 0;
|
107
|
|
|
}
|
108
|
|
|
$stats[$cnid][] = $q;
|
109
|
|
|
$cnt++;
|
110
|
|
|
}
|
111
|
|
|
|
112
|
|
|
// Mixed kills yo!
|
113
|
|
|
if ($mixedKills)
|
114
|
|
|
$kills = Kills::mergeKillArrays($mixed, array(), $limit, $columnName, $regionID);
|
115
|
|
|
|
116
|
|
|
// Find the next and previous regionID
|
117
|
|
|
$prevID = Db::queryField("select regionID from ccp_systems where regionID < :id order by regionID desc limit 1", "regionID", array(":id" => $regionID), 300);
|
118
|
|
|
$nextID = Db::queryField("select regionID from ccp_systems where regionID > :id order by regionID asc limit 1", "regionID", array(":id" => $regionID), 300);
|
119
|
|
|
|
120
|
|
|
$renderParams = array(
|
121
|
|
|
"pageName" => $pageName,
|
122
|
|
|
"kills" => $kills,
|
123
|
|
|
"detail" => $detail,
|
124
|
|
|
"page" => $page,
|
125
|
|
|
"topKills" => $topKills,
|
126
|
|
|
"mixed" => $mixedKills,
|
127
|
|
|
"key" => "region",
|
128
|
|
|
"id" => $regionID,
|
129
|
|
|
"pageType" => $pageType,
|
130
|
|
|
"topLists" => $topLists,
|
131
|
|
|
"summaryTable" => $stats,
|
132
|
|
|
"pager" => (sizeof($kills) >= $limit),
|
133
|
|
|
"datepicker" => true,
|
134
|
|
|
"prevID" => $prevID,
|
135
|
|
|
"nextID" => $nextID
|
136
|
|
|
);
|
137
|
|
|
|
138
|
|
|
$app->etag(md5(serialize($renderParams)));
|
139
|
|
|
$app->expires("+5 minutes");
|
140
|
|
|
$app->render("overview.html", $renderParams);
|
141
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: