<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

class System
{
  public static function isWindows(): bool
  {
    $uname = php_uname('s');

    return StringOperations::strtoupper(StringOperations::substr($uname, 0, 3)) === 'WIN';
  }

  public static function isUnicode(): bool
  {
    return defined('KW_INTERNAL_ENCODING') && KW_INTERNAL_ENCODING === UTF_8;
  }

  public static function isKuferSql5(): bool
  {
    if (static::$enforceKuferSqlVersion > 0) {
      $version = static::$enforceKuferSqlVersion;
    } else {
      static $versionFromDB = null;
      if (is_null($versionFromDB)) {
        $versionFromDB = 400;
        $dbw = new DBWorkBASysSettings(1, true);
        if ($dbw->checkTableExists('grundsys')) {
          $versionFromDB = $dbw->getVersion();
        }
      }
      $version = $versionFromDB;
    }

    return ($version >= 500);
  }

  
  public static $enforceKuferSqlVersion = 0;

  public static function isEpaymentAvailable(): bool
  {
    $fileName = BASEDIR . 'plugins' . DIRECTORY_SEPARATOR . 'epayment' . DIRECTORY_SEPARATOR . 'epayment.php';

    return file_exists($fileName);
  }

  public static function isDbMySql(): bool
  {
    return static::isDB('MYSQL');
  }

  public static function isDbMsSql(): bool
  {
    return static::isDB('MSSQL');
  }

  public static function isDbOracle(): bool
  {
    return static::isDB('ORACLE');
  }

  private static function isDb($pDbTyp): bool
  {
    if (self::$overrideDbName !== '') {
      $dbname = self::$overrideDbName;
    } else {
      $dbop = DBOperation::getInstance(1);
      $dbname = $dbop->getDBName();
    }

    return $dbname === $pDbTyp;
  }

  private static $overrideDbName = '';

  public static function setOverrideDbName($pName): void
  {
    self::$overrideDbName = $pName;
  }

  
  public static function isKinderAnmeldungErlaubt(): bool
  {

    return true;
  }

  public static function isDublettenErkennungVertauschteName(): bool
  {
    $settings = ToolSettingsAPI::getToolSettings(0);

    return $settings->duplicatedetectiongetauschtenamen == ANMELDUNGSOFORTEINBUCHEN_DUBLETTENERKENNUNG_GETAUSCHTE_NAMEN;
  }

  public static function isStammhMitFirma(): bool
  {
    return DBWorkBASysSettings::isFrankfurtHera();
  }

  public static function isUploadViaMail(): bool
  {
    $settings = ToolSettingsAPI::getToolSettings(0);

    return $settings->uploadviamail;
  }

  public static function isTerminAnfrageErlaubt(): bool
  {
    return DBWorkBASysSettings::isVerbraucherServiceOderZentrale();
  }

  public static function isGutscheinEinloesenErlaubt() : bool
  {
    return DBWorkBASysSettings::isGutscheinEinloesenAktiviert() && SessionOperations::isSofortEinbuchenWEBAllgemein();
  }
}