-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
87 lines (86 loc) · 2.86 KB
/
index.php
File metadata and controls
87 lines (86 loc) · 2.86 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PaperCut Web Parser</title>
</head>
<body>
<div align="left">Enter month for report:</div>
<?php
$MONTH = htmlspecialchars($_POST["MONTH"]);
if (empty($MONTH))
{
$MONTH = date("Y-m");
}
$date = date_create_from_format('Y-m', $MONTH);
$TMPDIR = getcwd() . "/tmp";
if (!file_exists($TMPDIR))
{
mkdir($TMPDIR);
}
$ExportCSV = $TMPDIR . "/" . $MONTH . ".csv";
if (file_exists($ExportCSV))
{
unlink($ExportCSV);
}
?>
<form action="index.php" method="POST" name="SELECTMONTH">
<input name="MONTH" type="text" value="<?php echo $MONTH; ?>">
<input type="submit" value="Build report">
</form>
<?php
echo "<a href=\"/tmp/" . $MONTH . ".csv\">Download report as CSV-file</a>";
echo "<br>";
echo "Report for a month: " . date_format($date, 'F Y');
$CONFIGFILE = getcwd() . "/config.php";
require_once($CONFIGFILE);
$dbconnect = mysql_connect($DBHOST, $DBUSER, $DBPASS);
if ($dbconnect)
{
if (mysql_select_db($DBNAME))
{
$QueryPrinterName = "SELECT DISTINCT Printer FROM `data` WHERE DateTime BETWEEN \"" . $MONTH . "-01 00:00:00\" AND \"" . date("Y-m-t", strtotime($MONTH)) . " 23:59:59\" ORDER BY Printer ASC; ";
$ResultPrinterName = mysql_query($QueryPrinterName);
$PrinterName = "";
$TotalPrint = 0;
echo "<table border=1>";
echo "<tr><td><b>Printer name</b></td><td><b>Print</b></td></tr>";
file_put_contents($ExportCSV, "Printer name;Print".PHP_EOL, FILE_APPEND | LOCK_EX);
while ($PrinterName = mysql_fetch_array($ResultPrinterName))
{
$QueryPrint = "SELECT Pages, Copies FROM data WHERE Printer=\"" . $PrinterName[0] . "\" AND DateTime BETWEEN \"" . $MONTH . "-01 00:00:00\" AND \"" . date("Y-m-t", strtotime($MONTH)) . " 23:59:59\";";
$ResultPrint = mysql_query($QueryPrint);
$Pages = 0;
$Copies = 0;
$Summ = 0;
$PrintArray = "";
while ($PrintArray = mysql_fetch_array($ResultPrint))
{
$Pages = $PrintArray[0];
$Copies = $PrintArray[1];
$Print = $Pages * $Copies;
$Summ += $Print;
}
$TotalPrint += $Summ;
echo "<tr><td><a href=\"month.php?SelectMonth=" . $MONTH . "&SelectPrinter=" . $PrinterName[0] . "\">" . $PrinterName[0] . "</a></td><td>" . $Summ . "</td></tr>";
$Txt = $PrinterName[0] . ";" . $Summ;
file_put_contents($ExportCSV, $Txt.PHP_EOL, FILE_APPEND | LOCK_EX);
//echo $PrinterName[0] . " " . $Pages . " * " . $Copies . " = " . $Summ . "<br>";
set_time_limit(30);
}
echo "<tr><td><b>Total print</b></td><td><b>" . $TotalPrint . "</b></td></tr>";
echo "</table>";
mysql_close();
}
else
{
echo "<div align=\"center\"><h2>Cannot select mysql db! Please create database, and try again</h2></div>";
}
}
else
{
echo "<div align=\"center\"><h2>Cannot connect with mysql!</h2></div>";
}
?>
</body>
</html>