<?php
//Web-Self-Infra sur DUN-PRD-R1SCOM\OPS
function Invoke_WebSelfInfra($request)
{
  $user = "Scom-Write";
  $pwd = "Grant@ccess";
  $server = "DUN-PRD-R1SCOM.armony.net\OPS";
  $database = "web-self-infra";
  $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = odbc_exec($conn, $request);
  if (instr(strtoupper($request), "SELECT")) {
    while ($row = odbc_fetch_array($rs)) {
      $answer[] = $row;
    }
  }
  if (isset($answer)) {
    return $answer;
  }
}

function Invoke_SCOMInfra($request)
{
  $user = "Scom-Write";
  $pwd = "Grant@ccess";
  $server = "DUN-PRD-R1SCOM.armony.net\OPS";
  $database = "infra";
  $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = odbc_exec($conn, $request);
  if (instr(strtoupper($request), "SELECT")) {
    while ($row = odbc_fetch_array($rs)) {
      $answer[] = $row;
    }
  }
  if (isset($answer)) {
    return $answer;
  }
}

//MySQL sur DUN-SUP-ENTRY01
function Invoke_Entry01($request)
{
  $user = "infra";
  $pwd = "infra";
  $server = "dun-sup-entry01:3306";
  $database = "infra";
  $conn = new mysqli($server, $user, $pwd, $database);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = $conn->query($request);
  while ($row = mysqli_fetch_array($rs)) {
    $answer[] = $row;
  }
  if (isset($answer)) {
    return $answer;
  }
}

// MySQL web-infra-tools sur DUN-SUP-S2ENTRY
function Invoke_WebInfraTools($request)
{
  $user = "admin";
  $pwd = "Arth3m1s&*0";
  $server = "dun-sup-s2entry.armony.net:3306";
  $database = "webinfratools";
  $conn = new mysqli($server, $user, $pwd, $database);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = $conn->query($request);
  while ($row = mysqli_fetch_array($rs)) {
    $answer[] = $row;
  }
  if (isset($answer)) {
    return $answer;
  }
}

//INFRA sur DUN-PRD-R1MSSQL\PRD
function Invoke_Infra($request)
{
  error_reporting(E_ALL ^ E_WARNING);
  $user = "INFRA_dbo";
  $pwd = "Q3pUz2x9YL2r6k";
  $server = "DUN-PRD-R1MSSQL.armony.net\PRD";
  $database = "INFRA";
  $conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $pwd);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = odbc_exec($conn, $request);
  if (instr(strtoupper($request), "SELECT")) {
    while ($row = odbc_fetch_array($rs)) {
      $answer[] = $row;
    }
  }
  if (isset($answer)) {
    return $answer;
  } else {
    if ($rs) {
      return "OK";
    } else {
      error_reporting(E_ALL);
      return "ERROR : " . odbc_errormsg($conn);
    }
  }

}

// aixcmdb
function Invoke_aixcmdb($request)
{
  error_reporting(E_ALL ^ E_WARNING);
  $conn_string =  "DRIVER={IBM DB2 ODBC DRIVER};" .
    "DATABASE=AIXCMDB; " .
    "HOSTNAME=db2_aixcmdb.appliarmony.net;" .
    "PORT=50000; " .
    "PROTOCOL=TCPIP; " .
    "UID=aixcmdb;" .
    "AUTHENTICATION=SERVER;" .
    "PWD=aixcmdb;";
  $conn = odbc_connect($conn_string, "", "");
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = odbc_exec($conn, $request);
  if (instr(strtoupper($request), "SELECT")) {
    while ($row = odbc_fetch_array($rs)) {
      $answer[] = $row;
    }
  }
  if (isset($answer)) {
    return $answer;
  } else {
    if ($rs) {
      return "OK";
    } else {
      error_reporting(E_ALL);
      return "ERROR : " . odbc_errormsg($conn);
    }
  }

}

function Invoke_GLPI($request)
{
  $user="glpi_lect_seule";
  $pwd="glpi_lect_seule";
  $server="srvv-n4glpi-aim.process.dkm";
  $database="glpi";
  $conn = new mysqli($server, $user, $pwd, $database);
  if (!($conn)) {
    echo "Pas de connexion";
  }
  $rs = $conn->query($request);
  while ($row = mysqli_fetch_array($rs)) {
    $answer[] = $row;
  }
  if (isset($answer)) {
    return $answer;
  }
}
