mirror of https://github.com/itflow-org/itflow
Add basic asset import functionality
This commit is contained in:
parent
a4b264143a
commit
5dc9eb4d1d
|
|
@ -0,0 +1,26 @@
|
|||
<div class="modal" id="addAssetCSVModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-dark">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-fw fa-desktop"></i> Import Assets via CSV</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body bg-white">
|
||||
<p>Format: name, type, make, model, serial, os</p>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||
|
||||
<div class="form-group">
|
||||
<input type="file" class="form-control-file" name="file">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="import_client_assets_csv" class="btn btn-primary">Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -73,7 +73,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
<div class="col-md-8">
|
||||
<div class="float-right">
|
||||
<a href="post.php?export_client_<?php echo $_GET['tab']; ?>_csv=<?php echo $client_id; ?>" class="btn btn-default"><i class="fa fa-fw fa-download"></i> Export</a>
|
||||
<a href="#" class="btn btn-default"><i class="fa fa-fw fa-upload"></i> Import</a>
|
||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#addAssetCSVModal"><i class="fa fa-fw fa-upload"></i> Import</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -259,4 +259,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("add_asset_modal.php"); ?>
|
||||
<?php
|
||||
include("add_asset_modal.php");
|
||||
include("add_asset_csv_modal.php");
|
||||
?>
|
||||
49
post.php
49
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']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue