-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowFixtures.php
124 lines (112 loc) · 4.43 KB
/
showFixtures.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
<?php
include 'classes/phpheader.php';
$query = "SELECT fixtureNum, CAST(fixtureNum AS unsigned) AS sortCol FROM scanned
WHERE store='".mysqli_real_escape_string($conn,$_POST['storenum'])."' AND dept='".mysqli_real_escape_string($conn,$_POST['dept'])."'
GROUP BY(fixtureNum)
ORDER BY sortCol ASC";
$fixtures = array_column(mysqli_fetch_all(mysqli_query($conn,$query),MYSQLI_ASSOC),"fixtureNum");
$head = ['title'=>'View Fixtures'];
include 'classes/header.php';
?>
<div class="contain textcenter">
Department: <?php echo htmlentities($_POST['dept']);?><br>
Store: <?php echo htmlentities($_POST['storenum']);?>
</div>
<div class="contain">
<table class='table'>
<thead>
<th>Fixture</th>
<th>Shelves</th>
<th>Boxes</th>
<th>Modified</th>
<th>Actions</th>
</thead>
<tbody>
<?php foreach($fixtures as $fixture):
$query = "SELECT date FROM scanned WHERE fixtureNum='$fixture' ORDER BY date DESC";
$date = mysqli_fetch_row(mysqli_query($conn,$query))[0];
$query = "SELECT DISTINCT shelfNum
FROM scanned WHERE fixtureNum = '".$fixture."' ORDER BY CAST(shelfNum AS unsigned) ASC";
$shelves = mysqli_fetch_all(mysqli_query($conn,$query),MYSQLI_ASSOC);
?>
<tr>
<td><?php echo $fixture;?></td>
<td> </td>
<td> </td>
<td><?php echo $date;?></td>
<td><button type="button" onclick="submitForm({action: 'print', fixture: '<?php echo $fixture; ?>'});">Print</button>
<button type="button" onclick="submitForm({action: 'edit', fixture: '<?php echo $fixture; ?>'});">Edit</button>
</td>
</tr>
<?php
foreach($shelves as $shelf):
$query = "SELECT date FROM scanned WHERE fixtureNum='$fixture' AND shelfNum='{$shelf['shelfNum']}' ORDER BY date DESC";
$date = mysqli_fetch_row(mysqli_query($conn,$query))[0];
$query = "SELECT DISTINCT boxnum
FROM scanned WHERE fixtureNum='$fixture' AND shelfNum='{$shelf['shelfNum']}' ORDER BY CAST(boxnum AS unsigned) ASC";
$boxes = mysqli_fetch_all(mysqli_query($conn,$query),MYSQLI_ASSOC);
if($shelf['shelfNum']!=''):?>
<tr>
<td style="border:none;"> </td>
<td><?php echo $shelf['shelfNum'];?></td>
<td> </td>
<td><?php echo $date; ?></td>
<td>
<button type="button" onclick="submitForm({action: 'print', fixture: '<?php echo $fixture; ?>', shelf: '<?php echo $shelf['shelfNum'];?>'});">Print</button>
<button type="button" onclick="submitForm({action: 'edit', fixture: '<?php echo $fixture; ?>', shelf: '<?php echo $shelf['shelfNum'];?>'});">Edit</button>
</td>
</tr>
<?php endif; foreach($boxes as $box):
$query = "SELECT date FROM scanned WHERE fixtureNum='$fixture' AND shelfNum='{$shelf['shelfNum']}' AND boxnum='{$box['boxnum']}' ORDER BY date DESC";
$date = mysqli_fetch_row(mysqli_query($conn,$query))[0];
if($box['boxnum']!=''):
?>
<tr>
<td style="border:none;"> </td>
<td style="border:none;"> </td>
<td><?php echo $box['boxnum'];?></td>
<td><?php echo $date; ?></td>
<td>
<button type="button" onclick="submitForm({action: 'print',
fixture: '<?php echo $fixture; ?>',
shelf: '<?php echo $shelf['shelfNum'];?>',
box: '<?php echo $box['boxnum']; ?>'});">Print</button>
<button type="button" onclick="submitForm({action: 'edit',
fixture: '<?php echo $fixture; ?>',
shelf: '<?php echo $shelf['shelfNum'];?>',
box: '<?php echo $box['boxnum']; ?>'});">Edit</button>
</td>
</tr>
<?php endif; endforeach;?>
<?php endforeach;?>
<?php endforeach;?>
</tbody>
</table>
</div>
<form method="POST" id="postForm">
<input type="hidden" name='dept' value='<?php echo htmlentities($_POST['dept']);?>'>
<input type="hidden" name='store' value='<?php echo htmlentities($_POST['storenum']);?>'>
<input type="hidden" name='fixture' value=''>
<input type="hidden" name='shelf' value=''>
<input type="hidden" name='box' value=''>
</form>
<script>
function submitForm(args){
//Set form action
if(args.action === 'print')
action = 'printing.php';
if(args.action === 'edit')
action = 'remove-scan.php';
$('#postForm').attr('action',action);
//Set values
names = ['fixture','shelf','box'];
names.forEach((element) => {
if(args.hasOwnProperty(element)){
$('[name='+element+']').attr('value',args[element]);
}
});
//Submit form
$('#postForm').submit();
}
</script>
<?php include 'classes/footer.php'; ?>