<?php
  header('Content-Type: application/json'); 
  include $_SERVER['DOCUMENT_ROOT']."/../../include/db_connect.php" ;
  if (isset($_GET['term'])) {
    $term = $_GET['term'];
    $query = "SELECT hostname AS serv FROM cmdb_srvall WHERE hostname LIKE '%$term%' UNION SELECT hostname AS serv FROM x_SRVALL WHERE hostname LIKE '%$term%'";
    $conn = DB_INFRA();
    $rs = odbc_exec($conn, $query);
    while ($row = odbc_fetch_array($rs)) {
      $servers[] = $row;
    }
    $result = [];
    if (is_array($servers)) {
        foreach ($servers as $server) {
            $result[] = $server['serv'];
        }
    }
    echo json_encode($result);
  }
