Add clients/read.php API endpoint.

Adjust asset create/update so that they function without all attributes being provided. Update will default to using the value currently in the database, rather than overwriting blank.
This commit is contained in:
Marcus Hill
2022-04-18 15:59:09 +01:00
parent 6ff6cb7c19
commit 2d6e7dbb37
5 changed files with 235 additions and 30 deletions

View File

@@ -4,14 +4,101 @@ require('../validate_api_key.php');
require('../require_post_method.php');
// Parse info
require('asset_model.php');
// Variable assignment - assigning blank if a value is not provided
if(isset($_POST['asset_name'])){
$name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_name'])));
} else{
$name = '';
}
if(isset($_POST['asset_type'])){
$type = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_type'])));
} else{
$type = '';
}
if(isset($_POST['asset_make'])){
$make = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_make'])));
} else{
$make = '';
}
if(isset($_POST['asset_model'])){
$model = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_model'])));
} else{
$model = '';
}
if(isset($_POST['asset_serial'])){
$serial = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_serial'])));
} else{
$serial = '';
}
if(isset($_POST['asset_os'])){
$os = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_os'])));
} else{
$os = '';
}
if(isset($_POST['asset_ip'])){
$aip = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_ip'])));
} else{
$aip = '';
}
if(isset($_POST['asset_mac'])){
$mac = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_mac'])));
} else{
$mac = '';
}
if(isset($_POST['asset_purchase_date'])){
$purchase_date = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_purchase_date'])));
} else{
$purchase_date = "0000-00-00";
}
if(isset($_POST['asset_warranty_expire'])){
$warranty_expire = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_warranty_expire'])));
} else{
$warranty_expire = "0000-00-00";
}
if(isset($_POST['asset_install_date'])){
$install_date = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_install_date'])));
} else{
$install_date = "0000-00-00";
}
if(isset($_POST['asset_notes'])){
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_notes'])));
} else{
$notes = '';
}
if(isset($_POST['asset_meshcentral_id'])){
$meshcentral_id = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['asset_meshcentral_id'])));
} else{
$meshcentral_id = '';
}
if(isset($_POST['asset_vendor_id'])){
$vendor = intval($_POST['asset_vendor_id']);
} else{
$vendor = '0';
}
if(isset($_POST['asset_location_id'])){
$location = intval($_POST['asset_location_id']);
} else{
$location = '0';
}
if(isset($_POST['asset_contact_id'])){
$contact = intval($_POST['asset_contact_id']);
} else{
$contact = '0';
}
if(isset($_POST['asset_network_id'])){
$network = intval($_POST['asset_network_id']);
} else{
$network = '0';
}
// Default
$insert_id = FALSE;
if(!empty($name) && !empty($client_id)){
// Insert into Database
$insert_sql = 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_ip = '$asset_ip', asset_mac = '$mac', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_purchase_date = '$purchase_date', asset_warranty_expire = '$warranty_expire', asset_install_date = '$install_date', asset_notes = '$notes', asset_created_at = NOW(), asset_network_id = $network, asset_client_id = $client_id, company_id = '$company_id'");
$insert_sql = 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_ip = '$aip', asset_mac = '$mac', asset_location_id = $location, asset_vendor_id = $vendor, asset_contact_id = $contact, asset_purchase_date = '$purchase_date', asset_warranty_expire = '$warranty_expire', asset_install_date = '$install_date', asset_notes = '$notes', asset_created_at = NOW(), asset_network_id = $network, asset_client_id = $client_id, company_id = '$company_id'");
if($insert_sql){
$insert_id = mysqli_insert_id($mysqli);