RACK_SLOTS_MAX) { $rack_refuse('unit_slots is how many it holds side by side - 0 to ' . RACK_SLOTS_MAX . '.'); } if ($holder_id && $slots) { $rack_refuse("An item in a holder (unit_parent_id) can't hold devices of its own (unit_slots)."); } // 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.'); } // Units, overlaps and slots - functions/rack.php $unit_place = rackPlacement($rack['rack_id'], $unit_id, ['holder' => $holder_id, 'position' => $position, 'start' => $start, 'end' => $end, 'face' => $face, 'full_depth' => $full_depth, 'slots' => $slots]); if (isset($unit_place['error'])) { $rack_refuse(strip_tags($unit_place['error']) . '.'); } // 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) . "'") . ", " . rackPlacementSet($unit_place) . ", unit_slots = " . intval($unit_place['slots']) . ", unit_power_watts = " . ($power_watts > 0 ? $power_watts : 'NULL') . ", unit_notes = '" . escapeSql($notes) . "'"; $unit_label = rackUnitName($asset_name, $label, $unit_type) . ($unit_place['holder'] ? " in slot {$unit_place['position']} of {$unit_place['holder_name']}" : '') . ' at ' . html_entity_decode(rackPositionLabel($unit_place['start'], $unit_place['end'])) . " ({$unit_place['face']})";