diff --git a/add_asset_csv_modal.php b/add_asset_csv_modal.php new file mode 100644 index 00000000..6099668f --- /dev/null +++ b/add_asset_csv_modal.php @@ -0,0 +1,26 @@ + diff --git a/client_assets.php b/client_assets.php index 1cf47892..cb7c389a 100644 --- a/client_assets.php +++ b/client_assets.php @@ -73,7 +73,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
Export - Import +
@@ -259,4 +259,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()")); - \ No newline at end of file + \ No newline at end of file diff --git a/post.php b/post.php index b7aeb81b..c16def06 100644 --- a/post.php +++ b/post.php @@ -4132,6 +4132,55 @@ if(isset($_POST['add_asset'])){ } +if (isset($_POST["import_client_assets_csv"])) { + $client_id = intval($_POST['client_id']); + $file_name = $_FILES["file"]["tmp_name"]; + + if ($_FILES["file"]["size"] > 0) { + $file = fopen($file_name, "r"); + fgetcsv($file, 1000, ","); // Skip first line + while (($column = fgetcsv($file, 1000, ",")) !== FALSE) { + if (isset($column[0])) { + $name = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[0]))); + } + if (isset($column[1])) { + $type = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[1]))); + } + if (isset($column[2])) { + $make = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[2]))); + } + if (isset($column[3])) { + $model = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[3]))); + } + if (isset($column[4])) { + $serial = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[4]))); + } + if (isset($column[5])) { + $os = trim(strip_tags(mysqli_real_escape_string($mysqli, $column[5]))); + } + // Potentially import the rest in the future? + + // Add + mysqli_query($mysqli,"INSERT INTO assets SET asset_name = '$name', asset_type = '$type', asset_make = '$make', asset_model = '$model', asset_serial = '$serial', asset_os = '$os', asset_created_at = NOW(), asset_client_id = $client_id, company_id = $session_company_id"); + + //Logging + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Asset', log_action = 'Created', log_description = '$name', log_created_at = NOW(), company_id = $session_company_id, log_user_id = $session_user_id"); + } + fclose($file); + + $_SESSION['alert_message'] = "Asset added"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + } + else { + // The file was empty + $_SESSION['alert_type'] = "warning"; + $_SESSION['alert_message'] = "Something went wrong"; + header("Location: " . $_SERVER["HTTP_REFERER"]); + } +} + + if(isset($_POST['edit_asset'])){ $asset_id = intval($_POST['asset_id']);