Subversion Repositories cheapmusic

Rev

Rev 153 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
98 - 1
<?php
121 - 2
    include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/hosting.php');
98 - 3
 
4
    $minDate = 20190101;
5
    $maxDate = date("Ymd");
6
    $unique = false;
7
    $plottype = "bars";
8
 
9
    $startTS = 0;
10
    $endTS = 0;
11
    if (!empty($_GET['start']) && filter_var($_GET['start'], FILTER_VALIDATE_INT, array("options" => array("min_range"=>$minDate, "max_range"=>$maxDate)))) {
12
        $date = $_GET['start'] . " 00:00:00 UTC";
13
        $dateTime = new DateTime($date);
14
        $startTS = $dateTime->format('U');
15
    }
16
    if (!empty($_GET['end']) && filter_var($_GET['end'], FILTER_VALIDATE_INT, array("options" => array("min_range"=>$minDate, "max_range"=>$maxDate)))) {
17
        $date = $_GET['end'] . " 23:59:59 UTC";
18
        $dateTime = new DateTime($date);
19
        $endTS = $dateTime->format('U');
20
    }
21
 
22
    if (!empty($_GET['unique']) && ($_GET['unique'] == '0' || $_GET['unique'] == '1')) {
23
        $unique = ($_GET['unique'] == '1');
24
    }
25
 
26
    $plottypes = array(
27
    "area",
28
    "bars",
29
    "linepoints",
30
    "lines",
31
    "pie",
32
    "points",
33
    "squared",
34
    "squaredarea",
35
    "stackedarea",
36
    "stackedbars",
37
    "stackedsquaredarea",
38
    "thinbarline");
39
    if (!empty($_GET['type']) && in_array($_GET['type'], $plottypes)) {
40
        $plottype = $_GET['type'];
41
    }
42
 
43
    $height = 1024;
44
    if (!empty($_GET['height']) && $_GET['height'] > 0) {
45
        $height = $_GET['height'];
46
    }
47
 
48
    $width = 768;
49
    if (!empty($_GET['width']) && $_GET['width'] > 0) {
50
        $width = $_GET['width'];
51
    }
52
 
53
 
54
    include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/constants.php');
55
    include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/sessions_db.php');
56
    include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/cryptor.php');
57
    require_once $_SERVER['DOCUMENT_ROOT'] . '/php/phplot.php';
58
 
153 - 59
    $configFile = parse_ini_file(FCM_CONFIGFILE, true);
98 - 60
    $crypt = Cryptor::getInstance($configFile['cryptor']);
61
    $tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
62
    $handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
63
    unset($configFile);
64
 
120 - 65
    session_set_cookie_params(604800, '/', '.findcheapmusic.com', true, true);
98 - 66
    session_set_save_handler($handler, true);
67
    if (!empty($_COOKIE['PHPSESSID'])) {
68
        session_id($_COOKIE['PHPSESSID']);
69
    }
70
    @session_start();
71
 
72
    $_sess_db = MySessionHandler::getDBSessionId();
73
 
74
    $countSql = ($unique ? "count(distinct(ip))" : "count(*)");
75
    $whereSql = "";
76
    if ($startTS > 0 && $endTS > 0) {
77
        $whereSql .= " where access between " . $startTS . " and " . $endTS;
78
    } else if ($startTS > 0) {
79
        $whereSql .= " where access >= " . $startTS;
80
    } else if ($endTS > 0) {
81
        $whereSql .= " where access <= " . $endTS;
82
    }
83
 
84
    $searches = [];
85
    $sql = "select from_unixtime(access, '%m/%d/%Y') as day, " . $countSql . " as count from searches";
86
    $sql .= $whereSql;
87
    $sql .= " group by from_unixtime(access, '%m/%d/%Y') order by access";
88
 
89
    $result = mysqli_query($_sess_db, $sql);
90
    if (!$result) {
91
        error_log("Error: " . $sql . " | " . mysqli_error($_sess_db));
92
    } else {
93
        if (mysqli_num_rows($result) > 0) {
94
            while ($row = mysqli_fetch_assoc($result)) {
95
                $searches[] = array($row["day"], $row["count"]);
96
            }
97
 
98
        }
99
    }
100
 
101
    $transfers = [];
102
    $sql = "select from_unixtime(access, '%m/%d/%Y') as day, " . $countSql . " as count from transfers";
103
    $sql .= $whereSql;
104
    $sql .= " group by from_unixtime(access, '%m/%d/%Y') order by access";
105
    $result = mysqli_query($_sess_db, $sql);
106
    if (!$result) {
107
        error_log("Error: " . $sql . " | " . mysqli_error($_sess_db));
108
    } else {
109
        if (mysqli_num_rows($result) > 0) {
110
            while ($row = mysqli_fetch_assoc($result)) {
111
                $transfers += array($row["day"] => $row["count"]);
112
            }
113
 
114
        }
115
    }
116
 
117
    $data = [];
118
    foreach ($searches as list($k, $v)) {
119
        $t = (array_key_exists($k, $transfers) ? $transfers[$k] : 0);
120
        $data[] = array($k, $v, $t);
121
    }
122
//echo"<pre>";print_r($data);echo "</pre>";
123
 
124
$plot = new PHPlot($width, $height);
125
$plot->SetImageBorderType('plain');
126
$title = 'Find Cheap Music';
127
if ($startTS || $endTS) {
128
    $title .= "\n";
129
    if ($startTS) {
130
        $title .= "from " . gmdate("m/d/y", $startTS);
131
    }
132
    if ($endTS) {
133
        $title .= " to " . gmdate("m/d/y", $endTS);
134
    }
135
}
136
$plot->SetTitle($title);
137
$plot->SetPlotType($plottype);
138
//$plot->SetShading(0);
139
$plot->SetDataValues($data);
140
$plot->SetLegend(array('Search', 'Transfer'));
141
$plot->SetXDataLabelAngle(90);
142
$plot->SetYTitle(($unique ? "Unique" : "All") .  " Requests");
143
$plot->SetYTickIncrement(1);
144
$plot->DrawGraph();