mirror of https://github.com/itflow-org/itflow
Moved Transfer Asset to Client to a Bulk Action and create Primary Interface when moving with MAC address
This commit is contained in:
parent
08ebedef03
commit
fc24bcb24f
|
|
@ -208,6 +208,10 @@ if (mysqli_num_rows($os_sql) > 0) {
|
|||
<i class="fas fa-fw fa-user mr-2"></i>Assign Contact
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#bulkTransferAssetClientModal">
|
||||
<i class="fas fa-fw fa-arrow-right mr-2"></i>Transfer to Client
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#bulkAssignLocationModal">
|
||||
<i class="fas fa-fw fa-map-marker-alt mr-2"></i>Assign Location
|
||||
</a>
|
||||
|
|
@ -579,9 +583,6 @@ if (mysqli_num_rows($os_sql) > 0) {
|
|||
<i class="fas fa-fw fa-trash mr-2"></i>Delete
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#transferAssetModal<?php echo $asset_id; ?>">
|
||||
<i class="fas fa-fw fa-arrow-right mr-2"></i>Transfer
|
||||
</a>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_asset=<?php echo $asset_id; ?>&csrf_token=<?php echo $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-archive mr-2"></i>Archive
|
||||
</a>
|
||||
|
|
@ -597,11 +598,8 @@ if (mysqli_num_rows($os_sql) > 0) {
|
|||
<?php
|
||||
|
||||
require "modals/client_asset_edit_modal.php";
|
||||
|
||||
require "modals/client_asset_copy_modal.php";
|
||||
|
||||
require "modals/client_asset_transfer_modal.php";
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -611,6 +609,7 @@ if (mysqli_num_rows($os_sql) > 0) {
|
|||
</div>
|
||||
<?php require_once "modals/client_asset_bulk_assign_location_modal.php"; ?>
|
||||
<?php require_once "modals/client_asset_bulk_assign_contact_modal.php"; ?>
|
||||
<?php require_once "modals/client_asset_bulk_transfer_client_modal.php"; ?>
|
||||
<?php require_once "modals/client_asset_bulk_edit_status_modal.php"; ?>
|
||||
<?php require_once "modals/client_asset_bulk_add_ticket_modal.php"; ?>
|
||||
</form>
|
||||
|
|
@ -622,11 +621,8 @@ if (mysqli_num_rows($os_sql) > 0) {
|
|||
|
||||
<?php
|
||||
require_once "modals/client_asset_add_modal.php";
|
||||
|
||||
require_once "modals/client_asset_import_modal.php";
|
||||
|
||||
require_once "modals/client_asset_export_modal.php";
|
||||
|
||||
require_once "includes/footer.php";
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ if (isset($_GET['location']) & !empty($_GET['location'])) {
|
|||
}
|
||||
|
||||
//Rebuild URL
|
||||
$url_query_strings_sort = http_build_query($get_copy);
|
||||
//$url_query_strings_sort = http_build_query($get_copy);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, locations.*, users.*, GROUP_CONCAT(tags.tag_name) FROM contacts
|
||||
LEFT JOIN locations ON location_id = contact_location_id
|
||||
|
|
|
|||
|
|
@ -54,9 +54,6 @@ if (isset($_GET['referral']) & !empty($_GET['referral'])) {
|
|||
$referral_filter = '';
|
||||
}
|
||||
|
||||
//Rebuild URL
|
||||
$url_query_strings_sort = http_build_query($get_copy);
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@ if (isset($_GET['category']) & !empty($_GET['category'])) {
|
|||
$category_filter = '';
|
||||
}
|
||||
|
||||
//Rebuild URL
|
||||
$url_query_strings_sort = http_build_query($get_copy);
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT SQL_CALC_FOUND_ROWS * FROM expenses
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ $get_copy = $_GET; // create a copy of the $_GET array
|
|||
//unset($get_copy['page']);
|
||||
unset($get_copy['sort']);
|
||||
unset($get_copy['order']);
|
||||
//Rebuild URL
|
||||
$url_query_strings_sort = http_build_query($get_copy);
|
||||
|
||||
// Paging
|
||||
if (isset($_GET['page'])) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<div class="modal" id="bulkTransferAssetClientModal" 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-exchange mr-2"></i>Transferring Asset(s)</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>New Client <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
</div>
|
||||
<select class="form-control select2" name="bulk_client_id">
|
||||
<option value="">- Client -</option>
|
||||
<?php
|
||||
$clients_sql = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_id != $client_id AND client_archived_at IS NULL");
|
||||
|
||||
while ($row = mysqli_fetch_array($clients_sql)) {
|
||||
$client_id_select = intval($row["client_id"]);
|
||||
$client_name_select = nullable_htmlentities($row["client_name"]);
|
||||
?>
|
||||
<option value='<?php echo $client_id_select; ?>'><?php echo $client_name_select; ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-dark" role="alert">
|
||||
<i>The current asset will be archived and content copied to a new asset.</i>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="bulk_transfer_client_asset" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Transfer</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
<div class="modal" id="transferAssetModal<?php echo $asset_id; ?>" 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-<?php echo $device_icon; ?> mr-2"></i>Transfer asset: <strong><?php echo $asset_name; ?></strong> to a different client</h5>
|
||||
<button type="button" class="close text-white" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="current_asset_id" value="<?php echo $asset_id; ?>">
|
||||
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
<div class="form-group">
|
||||
<label>New Client <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||
</div>
|
||||
|
||||
<?php $clients_sql = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_id != $client_id AND client_archived_at IS NULL"); ?>
|
||||
<select class="form-control select2" name="new_client_id" required>
|
||||
<?php
|
||||
while ($row = mysqli_fetch_array($clients_sql)) {
|
||||
$id = intval($row["client_id"]);
|
||||
$name = nullable_htmlentities($row["client_name"]);
|
||||
echo "<option value='$id'>$name</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-dark" role="alert">
|
||||
<i>The current asset will be archived and content copied to a new asset.</i>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer bg-white">
|
||||
<button type="submit" name="change_client_asset" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Transfer</button>
|
||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
$notification_type = nullable_htmlentities($row['notification_type']);
|
||||
$notification_details = nullable_htmlentities($row['notification']);
|
||||
$notification_action = nullable_htmlentities($row['notification_action']);
|
||||
$notification_created_at_formated = date('M d g:ia',strtotime($row['notification_created_at']));
|
||||
$notification_timestamp_formated = date('M d g:ia',strtotime($row['notification_timestamp']));
|
||||
$notification_client_id = intval($row['notification_client_id']);
|
||||
if(empty($notification_action)) { $notification_action = "#"; }
|
||||
?>
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
<i class="fas fa-bullhorn mr-2"></i><?php echo $notification_type; ?>
|
||||
</span>
|
||||
<small class="text-muted float-right">
|
||||
<?php echo $notification_created_at_formated; ?>
|
||||
<?php echo $notification_timestamp_formated; ?>
|
||||
</small>
|
||||
</div>
|
||||
<small class="text-secondary"><?php echo $notification_details; ?></small>
|
||||
|
|
|
|||
|
|
@ -120,61 +120,6 @@ if (isset($_POST['edit_asset'])) {
|
|||
|
||||
}
|
||||
|
||||
if (isset($_POST['change_client_asset'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
validateCSRFToken($_POST['csrf_token']);
|
||||
|
||||
$current_asset_id = intval($_POST['current_asset_id']);
|
||||
$new_client_id = intval($_POST['new_client_id']);
|
||||
|
||||
// Get Asset details and current client ID/Name for logging
|
||||
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name FROM assets LEFT JOIN clients ON client_id = asset_client_id WHERE asset_id = $current_asset_id"));
|
||||
$asset_name = sanitizeInput($row['asset_name']);
|
||||
$asset_notes = sanitizeInput($row['asset_notes']);
|
||||
$current_client_id = intval($row['asset_client_id']);
|
||||
$current_client_name = sanitizeInput($row['client_name']);
|
||||
|
||||
// Get new client name for logging
|
||||
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id"));
|
||||
$new_client_name = sanitizeInput($row['client_name']);
|
||||
|
||||
// Create new asset
|
||||
mysqli_query($mysqli, "
|
||||
INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important)
|
||||
SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important
|
||||
FROM assets
|
||||
WHERE asset_id = $current_asset_id
|
||||
");
|
||||
$new_asset_id = mysqli_insert_id($mysqli);
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id");
|
||||
|
||||
// Archive/log the current asset
|
||||
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
||||
mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id");
|
||||
|
||||
// Log Archive
|
||||
logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id);
|
||||
|
||||
// Log Transfer
|
||||
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id);
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id");
|
||||
|
||||
// Log the new asset
|
||||
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
||||
logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id);
|
||||
|
||||
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Asset <strong>$name</strong> transferred";
|
||||
|
||||
header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['archive_asset'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
|
@ -303,6 +248,84 @@ if (isset($_POST['bulk_assign_asset_location'])) {
|
|||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_transfer_client_asset'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
validateCSRFToken($_POST['csrf_token']);
|
||||
|
||||
$new_client_id = intval($_POST['bulk_client_id']);
|
||||
|
||||
// Transfer selected asset to new client
|
||||
if (isset($_POST['asset_ids'])) {
|
||||
|
||||
// Get Count
|
||||
$asset_count = count($_POST['asset_ids']);
|
||||
|
||||
foreach($_POST['asset_ids'] as $current_asset_id) {
|
||||
$current_asset_id = intval($current_asset_id);
|
||||
|
||||
// Get Asset details and current client ID/Name for logging
|
||||
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT asset_name, asset_notes, asset_client_id, client_name, interface_mac
|
||||
FROM assets
|
||||
LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
|
||||
LEFT JOIN clients ON client_id = asset_client_id
|
||||
WHERE asset_id = $current_asset_id")
|
||||
);
|
||||
$asset_name = sanitizeInput($row['asset_name']);
|
||||
$asset_notes = sanitizeInput($row['asset_notes']);
|
||||
$interface_mac = sanitizeInput($row['interface_mac']);
|
||||
$current_client_id = intval($row['asset_client_id']);
|
||||
$current_client_name = sanitizeInput($row['client_name']);
|
||||
|
||||
// Get new client name for logging
|
||||
$row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $new_client_id"));
|
||||
$new_client_name = sanitizeInput($row['client_name']);
|
||||
|
||||
// Create new asset
|
||||
mysqli_query($mysqli, "
|
||||
INSERT INTO assets (asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important)
|
||||
SELECT asset_type, asset_name, asset_description, asset_make, asset_model, asset_serial, asset_os, asset_status, asset_purchase_date, asset_warranty_expire, asset_install_date, asset_notes, asset_important
|
||||
FROM assets
|
||||
WHERE asset_id = $current_asset_id
|
||||
");
|
||||
$new_asset_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Add Primary Interface
|
||||
mysqli_query($mysqli,"INSERT INTO asset_interfaces SET interface_name = 'Primary', interface_mac = '$interface_mac', interface_port = 'eth0', interface_primary = 1, interface_asset_id = $new_asset_id");
|
||||
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_client_id = $new_client_id WHERE asset_id = $new_asset_id");
|
||||
|
||||
// Archive/log the current asset
|
||||
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
||||
mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $current_asset_id");
|
||||
|
||||
// Log Archive
|
||||
logAction("Asset", "Archive", "$session_name archived asset $asset_name (via transfer)", $current_client_id, $current_asset_id);
|
||||
|
||||
// Log Transfer
|
||||
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $current_client_id, $current_asset_id);
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $current_asset_id");
|
||||
|
||||
// Log the new asset
|
||||
$notes = $asset_notes . "\r\n\r\n---\r\n* " . date('Y-m-d H:i:s') . ": Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)";
|
||||
logAction("Asset", "Create", "$session_name created asset $name (via transfer)", $new_client_id, $new_asset_id);
|
||||
|
||||
logAction("Asset", "Transfer", "$session_name Transferred asset $asset_name (old asset ID: $current_asset_id) from $current_client_name to $new_client_name (new asset ID: $new_asset_id)", $new_client_id, $new_asset_id);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE assets SET asset_notes = '$notes' WHERE asset_id = $new_asset_id");
|
||||
|
||||
} // End Transfer to Client Loop
|
||||
|
||||
// Bulk Logging
|
||||
logAction("Asset", "Bulk Transfer", "$session_name transferred $asset_count assets to $new_client_name", $new_client_id);
|
||||
|
||||
$_SESSION['alert_message'] = "Transferred <strong>$asset_count</strong> assets to <strong>$new_client_name</strong>.";
|
||||
}
|
||||
|
||||
header("Location: client_assets.php?client_id=$new_client_id&asset_id=$new_asset_id");
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_assign_asset_contact'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue