$rack_units) { $rack_refuse("That doesn't fit - this rack runs from U1 to U$rack_units."); } // The asset has to be the client's, and in one place at a time $asset_name = ''; if ($asset_id) { $asset_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT asset_name FROM assets WHERE asset_id = $asset_id AND asset_client_id = " . intval($client_id))); if (!$asset_row) { $rack_refuse("asset_id isn't one of the client's assets."); } $asset_name = $asset_row['asset_name']; $racked = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT rack_name, unit_start_number, unit_end_number FROM rack_units LEFT JOIN racks ON rack_id = unit_rack_id WHERE unit_asset_id = $asset_id AND unit_id != $unit_id LIMIT 1")); if ($racked) { $rack_refuse("$asset_name is already racked in {$racked['rack_name']} at " . html_entity_decode(rackPositionLabel($racked['unit_start_number'], $racked['unit_end_number'])) . '.'); } } elseif ($label === '') { $rack_refuse('Send asset_id, or a name for the item in unit_device.'); } $conflict = rackUnitConflict($rack['rack_id'], $start, $end, $face, $full_depth, $unit_id); if ($conflict) { $rack_refuse(html_entity_decode(rackPositionLabel($start, $end)) . " on the $face is taken by {$conflict['name']} (" . html_entity_decode(rackPositionLabel($conflict['start'], $conflict['end'])) . ")."); } // A linked asset is drawn by its own asset type, so only unlinked items keep one $unit_set = "unit_device = '" . escapeSql(mb_substr($label, 0, 200)) . "', unit_asset_id = " . ($asset_id ?: 'NULL') . ", unit_type = " . ($asset_id ? 'NULL' : "'" . escapeSql($unit_type) . "'") . ", unit_start_number = $start, unit_end_number = $end, unit_face = '$face', unit_full_depth = $full_depth, unit_power_watts = " . ($power_watts > 0 ? $power_watts : 'NULL') . ", unit_notes = '" . escapeSql($notes) . "'"; $unit_label = rackUnitName($asset_name, $label, $unit_type) . ' at ' . html_entity_decode(rackPositionLabel($start, $end)) . " ($face)";