-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_newseason_print.php
executable file
·109 lines (97 loc) · 3.98 KB
/
admin_newseason_print.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
<?php
include 'tpl/auth.php';
include 'tpl/sql.php';
require_once 'phpqrcode.php';
if ((strlen($_POST['submit']) > 1) && (strlen($_POST['newplants']) > 0)) {
// We define newplants as a low number as a fallback in case of issues
$newplants = 1;
// Pull the details from the submitted form
$cultivarid = filter_var($_POST['cultivar'], FILTER_SANITIZE_STRING);
$cultivar = filter_var($_POST['cultivar'], FILTER_SANITIZE_STRING);
$facilityid = filter_var($_POST['facility'], FILTER_SANITIZE_STRING);
$newplants = filter_var($_POST['newplants'], FILTER_SANITIZE_STRING);
$seasonid = filter_var($_POST['seasonid'], FILTER_SANITIZE_STRING);
// Before we go any further, we want to get the cultivar human readable name
/*$sql = "SELECT * FROM cultivars where id='$cultivarid'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
$cultivarname = $row[0]['cultivar_name'];*/
$cultivarname = filter_var($_POST['cultivar'], FILTER_SANITIZE_STRING);
//echo "<br />\n";
//echo $cultivarname;
//print_r($row);
//echo "<br />\n";
// And the facility
$sql = "SELECT * FROM facilities where id='$facilityid'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
$facilityname = $row[0]['facilityname'];
//echo "<br />\n";
//echo $facilityname;
//print_r($row);
echo "<br />\n";
if ($newplants > 500) { $newplants = 10; }
// variables needed for the inserts
$date = date('Y-m-d');
$current_row_for_insert = 0;
$current_row_on_page = 0;
// Start with a HR outside of the loop so we've got a top-line to cut
echo "<hr />";
while ($current_row_for_insert < $newplants) {
// Make a UniqueID for the plant
$plant_uniqueid = uniqid('p', true);
// Now we make a QR Code for it
$fileName = $plant_uniqueid . ".png";
$pngAbsoluteFilePath = 'qrcodes/' . $fileName;
if (!file_exists($pngAbsoluteFilePath)) {
QRcode::png($plant_uniqueid, $pngAbsoluteFilePath, QR_ECLEVEL_L, 4, 2);
//echo 'File generated!';
} else {
//echo 'File already generated! We can use this cached file to speed up site on common codes!';
}
// Increase plant #
$current_row_for_insert++;
$current_row_on_page++;
$sql="INSERT INTO inventory (date_of_spawn, plant_uniqueid, season_id, plant_num, where_is_it_now, current_state, cultivar, mother_uniqueid) VALUES ('$date','$plant_uniqueid',$seasonid,'$current_row_for_insert','Nursery','In the early life stages','$cultivarname', 'Seed')";
//if (mysqli_query($conn, $sql)) {
if ($result = mysqli_query($con, $sql)) {
// echo "New record created successfully";
// So now we can make the label(s).
// For that we're going to want a table
echo "<table style='font-family: monospace; padding: 0;'>
<tr>
<td rowspan='5'><img src='" . $pngAbsoluteFilePath . "' width='80' height='80' /></td>
<td>Plant #" . $current_row_for_insert . "</td>
<td style='padding-left: 30px; padding-right: 30px'> | </td>
<td rowspan='5'><img src='" . $pngAbsoluteFilePath . "' width='80' height='80' /></td>
<td>Plant #" . $current_row_for_insert . "</td>
</tr>
<tr>
<td>Clone date: " . $date . "</td>
<td style='padding-left: 30px; padding-right: 30px'> | </td>
<td>Clone date: " . $date . "</td> </tr>
<tr>
<td>" . $cultivarname . "</td>
<td style='padding-left: 30px; padding-right: 30px'> | </td>
<td>" . $cultivarname . "</td>
</tr>
<tr>
<td>" . $plant_uniqueid . "</td>
<td style='padding-left: 30px; padding-right: 30px'> | </td>
<td>" . $plant_uniqueid . "</td>
</tr>
</table><hr />";
// echo $current_row_on_page . "<br />";
if (($current_row_on_page / 10) == 1) {
// We have 7 so now we pagebreak and add a starting HR
echo "<p style='page-break-after: always;'> </p><hr />";
$current_row_on_page = 0;
}
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
$savesuccess = 'true';
}
echo "<a href='admin.php'>Return home</a>";
?>