'.$device['uplink'].' '.$device['name'].' :: ['.$device['model_name'].']' . '", "icon" : "'.$dev_icon.'", "id" : "'.$device['id'].'","state" : { "opened" : true },'; $output .= '"a_attr" : { "href": "'.reencodeurl('/admin/devices/editdevice.php?id='.$device['id']).'"},'; $output .= '"children" : [' . print_child($device['id'], $hash, $processed_ids) . ']'; $output .= "},\n"; } return $output; } $dSQL = 'SELECT D.*,DM.model_name FROM devices as D,device_models as DM WHERE D.device_model_id=DM.id AND (deleted=0 and device_type<=2)'; $switches = get_records_sql($db_link,$dSQL); $dev_hash = NULL; // Сначала соберем все устройства foreach ($switches as $row) { $dev_id = $row['id']; $dev_hash[$dev_id]['id'] = $dev_id; $dev_hash[$dev_id]['name'] = $row['device_name']; $dev_hash[$dev_id]['type'] = $row['device_type']; $dev_hash[$dev_id]['model_name'] = $row['model_name']; $dev_hash[$dev_id]['parent_id'] = null; // инициализируем $pSQL = 'SELECT * FROM device_ports WHERE uplink = 1 and device_id='.$dev_id; $uplink = get_record_sql($db_link,$pSQL); if (empty($uplink)) { continue; } if (empty($uplink['target_port_id'])) { continue; } $dev_hash[$dev_id]['uplink'] = $uplink['port_name']; $parentSQL = 'SELECT * FROM device_ports WHERE device_ports.id='.$uplink['target_port_id']; $parent = get_record_sql($db_link,$parentSQL); // Защита от ссылки на самого себя if ($parent['device_id'] == $dev_id) { // Устройство ссылается само на себя - пропускаем эту связь $dev_hash[$dev_id]['parent_id'] = null; continue; } $dev_hash[$dev_id]['parent_id'] = $parent['device_id']; $dev_hash[$dev_id]['parent_port'] = $parent['port_name']; } print '
'; print "\n"; print '