<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

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

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

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

  public static function isKuferSql5()
  {
    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()
  {
    $fileName = BASEDIR . 'plugins' . DIRECTORY_SEPARATOR . 'epayment' . DIRECTORY_SEPARATOR . 'epayment.php';

    return file_exists($fileName);
  }

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

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

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

  private static function isDb($pDbTyp)
  {
    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)
  {
    self::$overrideDbName = $pName;
  }

  
  public static function isKinderAnmeldungErlaubt()
  {

    return true;
  }

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

  public static function isUploadViaMail(): bool
  {

    $settings = ToolSettingsAPI::getToolSettings(0);

    return $settings->uploadviamail;
  }
}