-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
98 lines (86 loc) · 3.73 KB
/
functions.php
File metadata and controls
98 lines (86 loc) · 3.73 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
88
89
90
91
92
93
94
95
96
97
98
<?php
include('configTrumbullIndustries.php');
if (isset($_POST["Import"])) {
echo $filename = $_FILES["file"]["tmp_name"];
if ($_FILES["file"]["size"] > 0) {
$file = fopen($filename, "r");
while (($getData = fgetcsv($file, 10000, ",")) !== FALSE) {
$sql = "insert into `sample-data` (ID,SKU,TSI,VENDOR,BRAND,`SHIPPING TEMPLATE`,`TEMPLATE CODE`,`INSTOCK LEADTIME`,
`NOSTOCK LEADTIME`,QUANTITY,OBSOLETE,`IS UPDATED`) values
('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "','" . $getData[4] . "','" . $getData[5] . "',
'" . $getData[6] . "','" . $getData[7] . "','" . $getData[8] . "','" . $getData[9] . "','" . $getData[10] . "','" . $getData[11] . "')";
$result = mysqli_query($conn, $sql);
// var_dump(mysqli_error_list($con));
// exit();
if (!isset($result)) {
echo "<script type=\"text/javascript\">
alert(\"Invalid File:Please Upload CSV File.\");
window.location = \"index.php\"
</script>";
} else {
echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Imported.\");
window.location = \"index.php\"
</script>";
}
}
fclose($file);
}
}
if (isset($_POST["Export"])) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array(
'ID', 'SKU', 'TSI', 'VENDOR', 'BRAND', `SHIPPING TEMPLATE`, `TEMPLATE CODE`, `INSTOCK LEADTIME`,
`NOSTOCK LEADTIME`, 'QUANTITY', 'OBSOLETE', `IS UPDATED`
));
$query = "SELECT * from 'sample-data' ORDER BY ID DESC";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($result)) {
fputcsv($output, $row);
}
fclose($output);
}
function get_all_records()
{
$Sql = "SELECT * FROM 'sample-data'";
$result = mysqli_query($conn, $Sql);
if (mysqli_num_rows($result) > 0) {
echo "<div class='table-responsive'><table id='myTable' class='table table-striped table-bordered'>
<thead>
<tr>
<th>ID</th>
<th>SKU</th>
<th>TSI</th>
<th>VENDOR</th>
<th>BRAND</th>
<th>SHIPPING TEMPLATE</th>
<th>TEMPLATE CODE</th>
<th>INSTOCK LEADTIME</th>
<th>NOSTOCK LEADTIME</th>
<th>QUANTITY</th>
<th>OBSOLETE</th>
<th>IS UPDATED</th>
</tr></thead><tbody>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['SKU'] . "</td>
<td>" . $row['TSI'] . "</td>
<td>" . $row['VENDOR'] . "</td>
<td>" . $row['BRAND'] . "</td>
<td>" . $row['SHIPPING TEMPLATE'] . "</td>
<td>" . $row['TEMPLATE CODE'] . "</td>
<td>" . $row['INSTOCK LEADTIME'] . "</td>
<td>" . $row['NOSTOCK LEADTIME'] . "</td>
<td>" . $row['QUANTITY'] . "</td>
<td>" . $row['OBSOLETE'] . "</td>
<td>" . $row['IS UPDATED'] . "</td>
</tr>";
}
echo "</tbody></table></div>";
} else {
echo "you have no recent pending orders";
}
}