forked from julmud/phpDVDProfiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gr_bycurrency.php
98 lines (79 loc) · 2.37 KB
/
gr_bycurrency.php
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
<?php
define('IN_SCRIPT', 1);
#Version 1.1, 11th July 2006. Added "collectiontype='owned' and " to select.
include_once('global.php');
if ($TryToChangeMemoryAndTimeLimits) @ini_set('memory_limit', -1);
include($jpgraphlocation.'jpgraph.php');
include($jpgraphlocation.'jpgraph_bar.php');
if (!isset($graphx) || !$graphx)
$graphx = 800 - 40;
if (!isset($graphy) || !$graphy)
$graphy = 'auto';
if ($graphy == 'auto')
$graphy = ($graphx*3)/4;
$sql = $db->sql_query("SELECT date_format(from_unixtime(purchasedate), '%Y/%m') AS month, "
."COUNT(title) AS count, SUM(paid) AS price "
."FROM $DVD_TABLE WHERE collectiontype='owned' AND purchaseplace>0 AND purchasepricecurrencyid='".$db->sql_escape($currency)."' "
."$currencyspecialcondition GROUP BY month") or die($db->sql_error());
$dates = array();
$cost = array();
$lowest = '9999/99';
$highest = date("Y/m");
while ($row = $db->sql_fetch_array($sql)) {
$pdate = $row[0];
$cnt = $row[1];
$amt = $row[2];
if ($pdate < $lowest)
$lowest = $pdate;
if (!array_key_exists($pdate, $dates)) {
$dates[$pdate] = 0;
$cost[$pdate] = 0;
}
$dates[$pdate] = $cnt;
$cost[$pdate] = $amt;
}
// Pad empty months
$current = $lowest;
while($current < $highest) {
if (!array_key_exists($current, $dates)) {
$dates[$current] = 0;
$cost[$current] = 0;
}
list($year, $month) = explode('/', $current);
$month++;
if ($month > 12) {
$month = 1;
$year++;
}
$current = sprintf('%02d/%02d', $year, $month);
}
ksort($dates);
$data = array();
$leg = array();
foreach ($dates as $key => $val) {
$data[] = $cost[$key];
$leg[] = $key;
}
$FixedTitle = preg_replace('/\\$currency/', $currency, html_entity_decode($lang['GRAPHS']['COST']));
if (!isset($next))
$FixedTitle = preg_replace('/\\n.*/', '', $FixedTitle);
else
$FixedTitle = preg_replace('/\\$next/', $next, $FixedTitle);
$graph = new Graph($graphx, $graphy, 'auto');
$graph->SetScale('textint');
$graph->img->SetMargin(50, 30, 50, 60);
$graph->title->Set($FixedTitle);
$graph->xaxis->SetTickLabels($leg);
$graph->xaxis->SetTextLabelInterval(3);
$graph->xaxis->SetFont(FF_COURIER);
$graph->xaxis->SetLabelAngle(45);
$graph->xaxis->HideTicks();
$graph->yaxis->scale->SetGrace($jpgrace);
$bplot = new BarPlot($data);
$bplot->SetFillColor('lightgreen'); // Fill color
$bplot->value->SetColor('black', 'navy');
if (count($leg) <= 20)
$bplot->SetShadow();
$graph->Add($bplot);
$graph->Stroke();
?>