-
Notifications
You must be signed in to change notification settings - Fork 0
/
filegraph2.php
292 lines (221 loc) · 8.11 KB
/
filegraph2.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
session_start();
require_once("includes/connection.php");
require_once("includes/functions.php");
header("Content-type: image/png");
include_once("includes/phpMyGraph5.0.php");
// SESSION VARIABLES
if (!loggedin()){
$rmessage = "You must be logged in to use this page!";
$_SESSION['rmessage'] = $rmessage;
toindex();
}
if(isset($_POST['viewtop'])){ // view top products
$_POST = array_map("strip_tags",$_POST);
$_POST = array_map("trim",$_POST);
$time = time();
$cyear = strftime("%Y",$time);
$risbn = '';
$months = array('blank','Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
$querytop = "SELECT `ISBN` , `year`, SUM(`quantity_sold`) AS `Total Quantity` FROM `product_sales` GROUP BY `ISBN`
ORDER BY `Total Quantity` ASC LIMIT 1,3";
$querytoph = $connection->query($querytop);
while ($row = $querytoph->fetch_assoc()){
$risbn = $row["ISBN"];
}
$marray1 = array();
$msarray1 = array();
$msales1 = array();
// Select all months for sales year & put in array
$monthsnh = $connection->query("SELECT DISTINCT `month` FROM `product_sales` WHERE `year` = {$cyear} AND `ISBN` = {$risbn}");
while ($month = $monthsnh->fetch_assoc()){
$marray1[] = $month['month'];
}
foreach($marray1 as $number){
$msarray1[] = $months[$number];
}
// start logic of gathering monthly sales
foreach($marray1 as $monthn){
$mshandle = $connection->query("SELECT `ISBN`, SUM(`quantity_sold`) AS 'Total Quantity' FROM `product_sales` WHERE `ISBN` = {$risbn} AND `month` = '{$monthn}' AND `year` = {$cyear} GROUP BY `ISBN`");
while($ms = $mshandle->fetch_assoc()){
$msales1[] = $ms['Total Quantity'];
}
} // foreach($marray as $month){
$salesdata1 = array_combine($msarray1, $msales1);
/*
$msarray2 = array();
$querytop2 = "SELECT `ISBN` , `year`, SUM( `quantity sold` ) AS `Total Quantity` FROM `psales` GROUP BY `ISBN`
ORDER BY `Total Quantity` DESC LIMIT 2,3";
$querytoph = $connection->query($querytop2);
$marray2 = array();
$msales2 = array();
while ($row = $querytoph->fetch_assoc()){
$risbn = $row['ISBN'];
// Select all months for sales year & put in array
$monthsnh = $connection->query("SELECT DISTINCT `month` FROM `psales` WHERE `year` = {$cyear} AND `ISBN` = {$risbn}");
while ($month = $monthsnh->fetch_assoc()){
$marray2[] = $month['month'];
}
foreach($marray2 as $number){
$msarray2[] = $months[$number];
}
// start logic of gathering monthly sales
foreach($marray2 as $month){
$mshandle = $connection->query("SELECT SUM(`quantity sold`) AS 'Total Quantity' FROM `psales` WHERE `year` = '{$cyear}' AND `month` = '{$month}' AND `ISBN` = {$risbn}");
while($ms = $mshandle->fetch_assoc()){
$msales2[] = $ms['Total Quantity'];
}
} // foreach($marray as $month){
}
$salesdata2 = array_combine($msarray2, $msales2);
$querytop3 = "SELECT `ISBN` , `year`, SUM( `quantity sold` ) AS `Total Quantity` FROM `psales` GROUP BY `ISBN`
ORDER BY `Total Quantity` DESC LIMIT 3,4";
$querytoph = $connection->query($querytop3);
$msarray3 = array();
$marray3 = array();
$msales3 = array();
while ($row = $querytoph->fetch_assoc()){
$risbn = $row['ISBN'];
// Select all months for sales year & put in array
$monthsnh = $connection->query("SELECT DISTINCT `month` FROM `psales` WHERE `year` = {$cyear} AND `ISBN` = {$risbn}");
while ($month = $monthsnh->fetch_assoc()){
$marray3[] = $month['month'];
}
foreach($marray3 as $number){
$msarray3[] = $months[$number];
}
// start logic of gathering monthly sales
foreach($marray3 as $month){
$mshandle = $connection->query("SELECT SUM(`quantity sold`) AS 'Total Quantity' FROM `psales` WHERE `year` = '{$cyear}' AND `month` = '{$month}' AND `ISBN` = {$risbn}");
while($ms = $mshandle->fetch_assoc()){
$msales3[] = $ms['Total Quantity'];
}
} // foreach($marray as $month){
}
$salesdata3 = array_combine($msarray3, $msales3);
*/
$cfg['title'] = "Graph for year {$cyear}";
$cfg['width'] = 800;
$cfg['height'] = 600;
$data1 = $salesdata1;
//$data2 = $salesdata2;
//$data3 = $salesdata3;
$graph = new phpMyGraph();
//Parse
$graph->parseVerticalColumnGraph($data1, $cfg);
} // POST is set for view op products
if(isset($_POST['vcisubmit'])){ //view chart products
$_POST = array_map("strip_tags",$_POST);
$_POST = array_map("trim",$_POST);
$risbn = $connection->real_escape_string($_POST['isbn2']);
$year = $connection->real_escape_string($_POST['years2']);
$erors = array();
//check for ISBN errors
$regex = "/\d{13}/";
if (!preg_match($regex, $risbn)){
$erors [] = "ISBN can only be numbers & 13 long";
}
//if isbn exists in products table
$iequery = "SELECT * FROM `products` WHERE `ISBN` = {$risbn}";
$iequeryh = $connection->query($iequery);
if ($iequeryh->num_rows < 1){
$erors[] = "This ISBN does not exist, please add this product or enter a new ISBN";
}
$time = time();
$cyear = strftime("%Y",$time);
$months = array('blank','Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
//if no errors
if(count($erors) < 1){ // if no erors
$marray1 = array();
$msarray1 = array();
$msales1 = array();
// Select all months for sales year & put in array
$monthsnh = $connection->query("SELECT DISTINCT `month` FROM `product_sales` WHERE `ISBN` = '{$risbn}'");
while ($month = $monthsnh->fetch_assoc()){
$marray1[] = $month['month'];
}
foreach($marray1 as $number){
$msarray1[] = $months[$number];
}
// start logic of gathering monthly sales
foreach($marray1 as $monthn){
$mshandle = $connection->query("SELECT `ISBN`, SUM(`quantity_sold`) AS 'Total Quantity' FROM `product_sales` WHERE `ISBN` = '{$risbn}' AND `month` = '{$monthn}' GROUP BY `ISBN`");
while($ms = $mshandle->fetch_assoc()){
$msales1[] = $ms['Total Quantity'];
}
} // foreach($marray as $month){
$salesdata1 = array_combine($msarray1, $msales1);
$cfg['title'] = "Graph for year {$cyear}";
$cfg['width'] = 800;
$cfg['height'] = 600;
//$data1 = $salesdata1;
$graph = new phpMyGraph();
//Parse
$graph->parseVerticalColumnGraph($salesdata1, $cfg);
} // there are errors
else {
$rmessage = implode('<br />', $erors);
$_SESSION['rmessage'] = $rmessage;
toproducts();
}
} // vcisubmit is set
if(isset($_POST['vccsubmit'])){ //view chart products
$_POST = array_map("strip_tags",$_POST);
$_POST = array_map("trim",$_POST);
$rcode = $connection->real_escape_string($_POST['code2']);
$year = $connection->real_escape_string($_POST['years3']);
$erors = array();
// check for code errors
$regex = "/[^\d{5}]/";
if (preg_match($regex, $rcode)){
$erors [] = "code can only be numbers & 5 long";
}
// if code exists or not
$iequery = "SELECT * FROM `products` WHERE `code` = '{$rcode}' LIMIT 0,30";
$iequeryh = $connection->query($iequery);
if ($iequeryh->num_rows < 1){
$erors[] = "This code does not exist, please add this product or enter a new code";
}
$time = time();
$cyear = strftime("%Y",$time);
$months = array('blank','Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
//if no errors
if(count($erors) < 1){ // if no erors
$marray1 = array();
$msarray1 = array();
$msales1 = array();
// Select all months for sales year & put in array
$monthsnh = $connection->query("SELECT DISTINCT `month` FROM `product_sales`, `products` WHERE `product_sales`.`ISBN` = `products`.`ISBN`
AND `code` = '{$rcode}'");
while ($month = $monthsnh->fetch_assoc()){
$marray1[] = $month['month'];
}
foreach($marray1 as $number){
$msarray1[] = $months[$number];
}
// start logic of gathering monthly sales
foreach($marray1 as $monthn){
$mshandle = $connection->query("SELECT `product_sales`.`ISBN`, SUM(`quantity_sold`) AS 'Total Quantity' FROM `product_sales`, `products` WHERE
`product_sales`.`ISBN` = `products`.`ISBN`
AND `code` = '{$rcode}'
AND `month` = '{$monthn}' GROUP BY `ISBN`");
while($ms = $mshandle->fetch_assoc()){
$msales1[] = $ms['Total Quantity'];
}
} // foreach($marray as $month){
$salesdata1 = array_combine($msarray1, $msales1);
$cfg['title'] = "Graph for year {$cyear}";
$cfg['width'] = 800;
$cfg['height'] = 600;
//$data1 = $salesdata1;
$graph = new phpMyGraph();
//Parse
$graph->parseVerticalColumnGraph($salesdata1, $cfg);
}
else { // there are errors
$rmessage = implode('<br />', $erors);
$_SESSION['rmessage'] = $rmessage;
toproducts();
}
} // vccsubmit is set
?>