mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Fix CSV import 0.1 #175
This commit is contained in:
@@ -488,22 +488,28 @@ function ImportCSV() {
|
|||||||
|
|
||||||
$columns = getDevicesColumns();
|
$columns = getDevicesColumns();
|
||||||
|
|
||||||
$rowArray = array();
|
|
||||||
|
|
||||||
// Parse data from CSV file line by line (max 10000 lines)
|
// Parse data from CSV file line by line (max 10000 lines)
|
||||||
foreach($data as $row)
|
foreach($data as $row)
|
||||||
{
|
{
|
||||||
// Check if not empty and skipping first line
|
// Check if not empty and skipping first line
|
||||||
if(count(explode(',',$row)) == count($columns) && explode(',',$row)[0] != "\"dev_MAC\"")
|
$rowArray = explode(',',$row);
|
||||||
{
|
|
||||||
$sql = "INSERT INTO Devices (".implode(',', $columns).") VALUES (" . $row.")";
|
|
||||||
$result = $db->query($sql);
|
|
||||||
|
|
||||||
// check result
|
if(count($rowArray) > 20)
|
||||||
if ($result != TRUE) {
|
{
|
||||||
$error = $db->lastErrorMsg();
|
$cleanMac = str_replace("\"","",$rowArray[0]);
|
||||||
// break the while loop on error
|
|
||||||
break;
|
if(filter_var($cleanMac , FILTER_VALIDATE_MAC) == True || $cleanMac == "Internet")
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO Devices (".implode(',', $columns).") VALUES (" . $row.")";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// check result
|
||||||
|
if ($result != TRUE) {
|
||||||
|
$error = $db->lastErrorMsg();
|
||||||
|
// break the while loop on error
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user