Skip to content

Commit 2ec4be8

Browse files
committed
Updated software post to use new logAction function, rework array handling tidy and added more details to logging
1 parent a86eecf commit 2ec4be8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

post/user/software.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
// GET Software Info
1717
$sql_software = mysqli_query($mysqli,"SELECT * FROM software WHERE software_id = $software_template_id");
18-
1918
$row = mysqli_fetch_array($sql_software);
20-
2119
$name = sanitizeInput($row['software_name']);
2220
$version = sanitizeInput($row['software_version']);
2321
$description = sanitizeInput($row['software_description']);
@@ -28,10 +26,12 @@
2826
// Software add query
2927
mysqli_query($mysqli,"INSERT INTO software SET software_name = '$name', software_version = '$version', software_description = '$description', software_type = '$type', software_license_type = '$license_type', software_notes = '$notes', software_client_id = $client_id");
3028

29+
$software_id = mysqli_insert_id($mysqli);
30+
3131
// Logging
32-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Create', log_description = 'Software created from template $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id");
32+
logAction("Software", "Create", "$session_name created software $name using template", $client_id, $software_id);
3333

34-
$_SESSION['alert_message'] = "Software created from template";
34+
$_SESSION['alert_message'] = "Software <strong>$name</strong> created from template";
3535

3636
header("Location: " . $_SERVER["HTTP_REFERER"]);
3737

@@ -71,23 +71,23 @@
7171
$alert_extended = "";
7272

7373
// Add Asset Licenses
74-
if (!empty($_POST['assets'])) {
74+
if (isset($_POST['assets'])) {
7575
foreach($_POST['assets'] as $asset) {
7676
$asset_id = intval($asset);
7777
mysqli_query($mysqli,"INSERT INTO software_assets SET software_id = $software_id, asset_id = $asset_id");
7878
}
7979
}
8080

8181
// Add Contact Licenses
82-
if (!empty($_POST['contacts'])) {
82+
if (isset($_POST['contacts'])) {
8383
foreach($_POST['contacts'] as $contact) {
8484
$contact = intval($contact);
8585
mysqli_query($mysqli,"INSERT INTO software_contacts SET software_id = $software_id, contact_id = $contact");
8686
}
8787
}
8888

89-
//Logging
90-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Create', log_description = '$session_name created software $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $software_id");
89+
// Logging
90+
logAction("Software", "Create", "$session_name created software $name", $client_id, $software_id);
9191

9292
$_SESSION['alert_message'] = "Software <strong>$name</strong> created $alert_extended";
9393

@@ -128,7 +128,7 @@
128128

129129
// Update Asset Licenses
130130
mysqli_query($mysqli,"DELETE FROM software_assets WHERE software_id = $software_id");
131-
if (!empty($_POST['assets'])) {
131+
if (isset($_POST['assets'])) {
132132
foreach($_POST['assets'] as $asset) {
133133
$asset = intval($asset);
134134
mysqli_query($mysqli,"INSERT INTO software_assets SET software_id = $software_id, asset_id = $asset");
@@ -137,15 +137,15 @@
137137

138138
// Update Contact Licenses
139139
mysqli_query($mysqli,"DELETE FROM software_contacts WHERE software_id = $software_id");
140-
if (!empty($_POST['contacts'])) {
140+
if (isset($_POST['contacts'])) {
141141
foreach($_POST['contacts'] as $contact) {
142142
$contact = intval($contact);
143143
mysqli_query($mysqli,"INSERT INTO software_contacts SET software_id = $software_id, contact_id = $contact");
144144
}
145145
}
146146

147-
//Logging
148-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Modify', log_description = '$session_name modified software $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $software_id");
147+
// Logging
148+
logAction("Software", "Edit", "$session_name edited software $name", $client_id, $software_id);
149149

150150
$_SESSION['alert_message'] = "Software <strong>$name</strong> updated";
151151

@@ -171,8 +171,8 @@
171171
mysqli_query($mysqli,"DELETE FROM software_contacts WHERE software_id = $software_id");
172172
mysqli_query($mysqli,"DELETE FROM software_assets WHERE software_id = $software_id");
173173

174-
//Logging
175-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Archive', log_description = '$session_name archived software $software_name and removed all device/user license associations', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $software_id");
174+
// Logging
175+
logAction("Software", "Archive", "$session_name archived software $software_name and removed all device/user license associations", $client_id, $software_id);
176176

177177
$_SESSION['alert_type'] = "error";
178178
$_SESSION['alert_message'] = "Software <strong>$software_name</strong> archived and removed all device/user license associations";
@@ -200,7 +200,7 @@
200200
mysqli_query($mysqli,"DELETE FROM software_assets WHERE software_id = $software_id");
201201

202202
//Logging
203-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Delete', log_description = '$session_name deleted software $software_name and removed all device/user license associations', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $software_id");
203+
logAction("Software", "Delete", "$session_name deleted software $software_name and removed all device/user license associations", $client_id);
204204

205205
$_SESSION['alert_type'] = "error";
206206
$_SESSION['alert_message'] = "Software <strong>$software_name</strong> deleted and removed all device/user license associations";
@@ -278,8 +278,8 @@
278278
fpassthru($f);
279279
}
280280

281-
// Logging
282-
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Software', log_action = 'Export', log_description = '$session_name exported $num_rows software license(s) to a CSV file', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id");
281+
//Logging
282+
logAction("Software", "Export", "$session_name exported $num_rows software(s) $software_name to a CSV file", $client_id);
283283

284284
exit;
285285

0 commit comments

Comments
 (0)