-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixsavemonths.php
More file actions
75 lines (62 loc) · 1.67 KB
/
matrixsavemonths.php
File metadata and controls
75 lines (62 loc) · 1.67 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
<?php
require_once('headerDB.inc.php');
$month_key = [
587 => ['Jan', 1]
, 588 => ['Feb', 2]
, 589 => ['Mar', 3]
, 590 => ['Apr', 4]
, 591 => ['May', 5]
, 592 => ['Jun', 6]
, 593 => ['Jul', 7]
, 594 => ['Aug', 8]
, 595 => ['Sep', 9]
, 596 => ['Oct', 10]
, 597 => ['Nov', 11]
, 598 => ['Dec', 12]
];
// check if Month Start exists
$_POST["id4"] = 583;
include('matrixQuery.php');
$month_start = $value;
// check if Month End exists
$_POST["id4"] = 584;
include('matrixQuery.php');
$month_end = $value;
// set calculation range
if (isset($month_start) && isset($month_end)) {
foreach ($month_key as $arr) if($month_start == $arr[0]) { $month_start = $arr[1]; break; }
foreach ($month_key as $arr) if($month_end == $arr[0]) { $month_end = $arr[1]; break; }
if ($month_start <= $month_end) {
$month_range = [$month_start];
while ($month_start < $month_end) {
$month_start++;
$month_range[] = $month_start;
}
} else {
$month_range = [$month_start, $month_end];
while ($month_start < 12) {
$month_start++;
$month_range[] = $month_start;
}
while ($month_end > 1) {
$month_end--;
$month_range[] = $month_end;
}
}
} else {
die;
}
// check if months exist / relevant
$month_p = [];
foreach ($month_key as $id => $arr) {
if (!in_array($arr[1], $month_range)) continue;
$_POST["id4"] = $id;
include('matrixQuery.php');
if (isset($value) && ctype_digit($value)) $month_p[] = intval($value);
}
// calculation for Sum / Season
$_POST["id4"] = 581;
if (count($month_p) == 0) $_POST["updVal"] = '';
else $_POST["updVal"] = intval(array_sum($month_p) / count($month_p));
include('matrixSave.php');
?>