forked from RafaelKeramidas/RGraphs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.php
More file actions
120 lines (101 loc) · 4.35 KB
/
graph.php
File metadata and controls
120 lines (101 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/***
* RGraph - SA-MP Server Graphs
*
* @Author Rafael 'R@f' Keramidas <rafael@keramid.as>
* @Version 1.0
* @Date 13th September 2012
* @Licence GPLv3
***/
require('includes/config.inc.php');
require('pchart/pData.class.php');
require('pchart/pChart.class.php');
require('pchart/pCache.class.php');
/* Connect to the MySQL Database */
try {
$db = new PDO('mysql:host=' . $config['mysql_host'] . ';dbname=' . $config['mysql_db'], $config['mysql_user'], $config['mysql_passwd']);
}
catch (Exception $e) {
die('Error: ' . $e->getMessage());
}
if(isset($_GET['srvid']) && isset($_GET['size'])) {
$serverid = $_GET['srvid'];
$size = $_GET['size'];
$result = $db->prepare("SELECT srv.name AS name, srv.ip AS ip, srv.port AS port, COUNT(st.statid) AS statscount FROM rgraph_servers srv INNER JOIN rgraph_stats st ON st.fk_server = srv.serverid WHERE serverid = :srvid");
$result->execute(array(
'srvid' => $serverid
));
$dbdata = $result->fetch();
/* Check if the server exists */
if(count($dbdata) != 0) {
$name = $dbdata['name'];
$ip = $dbdata['ip'];
$port = $dbdata['port'];
$scount = $dbdata['statscount'];
if($scount != 0) {
if($size == 'small') {
$result = $db->prepare("SELECT players, DATE_FORMAT(stattime, '%H:%i') AS stime FROM rgraph_stats WHERE fk_server = :srvid AND stattime > DATE_SUB(NOW(), INTERVAL 6 HOUR)");
$result->execute(array(
'srvid' => $serverid
));
$dataSet = new pData;
while($dbdata = $result->fetch()) {
$dataSet->AddPoint($dbdata['players'],"Serie1");
$dataSet->AddPoint($dbdata['stime'],"Serie2");
}
$dataSet->AddAllSeries();
$dataSet->SetAbsciseLabelSerie("Serie2");
$dataSet->SetYAxisName("Amout of players");
$cache = new pCache();
$cache->GetFromCache("Small$serverid",$dataSet->GetData());
$chart = new pChart(600,230);
$chart->setFontProperties("fonts/tahoma.ttf",8);
$chart->setGraphArea(60,30,550,200);
$chart->drawFilledRoundedRectangle(7,7,593,223,5,240,240,240);
$chart->drawRoundedRectangle(5,5,595,225,5,230,230,230);
$chart->drawGraphArea(255,255,255,TRUE);
$chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,0);
$chart->drawGrid(4,TRUE,230,230,230,50);
$chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(), 50, TRUE);
$chart->setFontProperties("fonts/tahoma.ttf",10);
$chart->drawTitle(40,22,"Stats on 6 hours for $name ($ip:$port)",50,50,50,585);
$cache->WriteToCache("Small$serverid",$dataSet->GetData(),$chart);
$chart->Stroke();
}
else if($size = 'big') {
$result = $db->prepare("SELECT players, DATE_FORMAT(stattime, '%H:%i') AS stime FROM rgraph_stats WHERE fk_server = :srvid AND stattime > DATE_SUB(NOW(), INTERVAL 24 HOUR)");
$result->execute(array(
'srvid' => $serverid
));
$dataSet = new pData;
while($dbdata = $result->fetch()) {
$dataSet->AddPoint($dbdata['players'],"Serie1");
$dataSet->AddPoint($dbdata['stime'],"Serie2");
}
$dataSet->AddAllSeries();
$dataSet->SetAbsciseLabelSerie("Serie2");
$dataSet->SetYAxisName("Amout of players");
$cache = new pCache();
$cache->GetFromCache("Big$serverid",$dataSet->GetData());
$chart = new pChart(1800,230);
$chart->setFontProperties("fonts/tahoma.ttf",8);
$chart->setGraphArea(60,30,1750,200);
$chart->drawFilledRoundedRectangle(7,7,1793,223,5,240,240,240);
$chart->drawRoundedRectangle(5,5,1795,225,5,230,230,230);
$chart->drawGraphArea(255,255,255,TRUE);
$chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,0);
$chart->drawGrid(4,TRUE,230,230,230,50);
$chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(), 50, TRUE);
$chart->setFontProperties("fonts/tahoma.ttf",10);
$chart->drawTitle(1100,22,"Stats on 24 hours for $name ($ip:$port)",50,50,50,585);
$cache->WriteToCache("Big$serverid",$dataSet->GetData(),$chart);
$chart->Stroke();
}
}
else {
echo 'No data fetched for the moment...';
}
}
$result->closeCursor();
}
?>