<?php

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


class LanguageOperations
{
  private static $instance;

  private static function getInstance()
  {
    if (is_null(self::$instance)) {
      $languageKey = SessionOperations::getCurrentLanguageKey();
      if ($languageKey === KUFERWEB_SPRACHE_STANDARD) {
        self::$instance = self::getDefaultLanguageOperations();
      } else {
        
        $dbwork = new DBWorkHLMsp(1, true);
        $language = $dbwork->getOne($languageKey);
        $className = 'LanguageOperations' . StringOperations::strtoupper(StringOperations::substr($language->name, 0, 2));
        if (class_exists($className) && $className != 'LanguageOperations') {
          self::$instance = new $className();
        } else {
          self::$instance = self::getDefaultLanguageOperations();
        }
      }
    }

    return self::$instance;
  }

  private static function getDefaultLanguageOperations()
  {
    return new LanguageOperationsDE();
  }

  public static function getLanguageName()
  {
    return self::getInstance()->getLanguageName();
  }

  public static function getNameofMonths()
  {
    return self::getInstance()->getNameofMonths();
  }

  public static function getNameofMonthsShort()
  {
    return self::getInstance()->getNameofMonthsShort();
  }

  public static function getNameofDays()
  {
    return self::getInstance()->getNameofDays();
  }

  public static function getNameofDaysShort()
  {
    return self::getInstance()->getNameofDaysShort();
  }

  public static function getGender()
  {
    return self::getInstance()->getGender();
  }

  public static function getGenderShort()
  {
    return self::getInstance()->getGenderShort();
  }

  public static function translateGender($gender)
  {
    return PhpOperations::getIfIssetArray(static::getGender(), StringOperations::strtoupper($gender), $gender);
  }

  public static function translateGenderShort($gender)
  {
    return PhpOperations::getIfIssetArray(static::getGenderShort(), StringOperations::strtoupper($gender), $gender);
  }
}

abstract class LanguageOperationsParent
{
  protected $languageName;
  protected $months;
  protected $months_short;
  protected $days;
  protected $days_short;
  protected $gender;
  protected $gender_short;

  public function getLanguageName()
  {
    if (!isset($this->languageName)) {
      throw new Exception('invalid state - $languageName not correctly initialized');
    }

    return $this->languageName;
  }

  public function getNameofMonths()
  {
    if (!isset($this->months)) {
      throw new Exception('invalid state - $months not correctly initialized');
    }

    return $this->months;
  }

  public function getNameofMonthsShort()
  {
    if (!isset($this->months_short)) {
      throw new Exception('invalid state - $months_short not correctly initialized');
    }

    return $this->months_short;
  }

  public function getNameofDays()
  {
    if (!isset($this->days)) {
      throw new Exception('invalid state - $days not correctly initialized');
    }

    return $this->days;
  }

  public function getNameofDaysShort()
  {
    if (!isset($this->days_short)) {
      throw new Exception('invalid state - $days_short not correctly initialized');
    }

    return $this->days_short;
  }

  public function getGender()
  {
    if (!isset($this->gender)) {
      throw new Exception('invalid state - $gender not correctly initialized');
    }

    return $this->gender;
  }

  public function getGenderShort()
  {
    if (!isset($this->gender_short)) {
      throw new Exception('invalid state - $gender_short not correctly initialized');
    }

    return $this->gender_short;
  }
}
class LanguageOperationsDE extends LanguageOperationsParent
{
  public function __construct()
  {
    $this->languageName = 'DE';
    $this->months = array(1 => 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
    $this->months_short = array(1 => 'Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni', 'Juli', 'Aug.', 'Sept.', 'Okt.', 'Nov.', 'Dez.');
    $this->days = array(1 => 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag');
    $this->days_short = array(1 => 'Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.', 'So.');
    $this->gender = array(0 => 'Bitte wählen', 'W' => 'W - Weiblich', 'M' => 'M - Männlich', 'F' => 'F - Firma', 'I' => 'I - Inter', 'D' => 'D - Divers', 'O' => 'O - ohne Eintrag im Geburtsregister');
    $this->gender_short = array(0 => 'Bitte wählen', 'W' => 'w', 'M' => 'm', 'F' => 'f', 'I' => 'i', 'D' => 'd', 'O' => 'o');
  }
}

class LanguageOperationsEN extends LanguageOperationsParent
{
  public function __construct()
  {
    $this->languageName = 'EN';
    $this->months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    $this->months_short = array(1 => 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    $this->days = array(1 => 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
    $this->days_short = array(1 => 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
    $this->gender = array(0 => 'Please select', 'W' => 'Female', 'M' => 'Male', 'D' => 'diverse', 'I' => 'diverse', 'F' => 'Company', 'O' => 'without entry in birth register');
    $this->gender_short = array(0 => 'Please select', 'W' => 'F', 'M' => 'M', 'D' => 'diverse',  'DIVERS' => 'diverse', 'I' => 'diverse',  'INTER' => 'diverse',  'F' => 'Company',  'FIRMA' => 'Company', 'O' => 'without entry in birth register');
  }
}

class LanguageOperationsIT extends LanguageOperationsParent
{
  public function __construct()
  {
    $this->languageName = 'IT';
    $this->months = array(1 => 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
    $this->months_short = array(1 => 'Gen.', 'Feb.', 'Mar.', 'Apr.', 'Mag.', 'Giu.', 'Lug.', 'Ago.', 'Set.', 'Ott.', 'Nov.', 'Dic.');
    $this->days = array(1 => 'Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato', 'Domenica');
    $this->days_short = array(1 => 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab', 'Dom');
    $this->gender = array(0 => 'Prego sceliere', 'W' => 'Femmina', 'M' => 'Maschile', 'D' => 'diverso', 'I' => 'diverso', 'F' => 'Azienda', 'FIRMA' => 'Azienda', 'O' => 'senza registrazione');
    $this->gender_short = array(0 => 'Prego sceliere', 'W' => 'F', 'M' => 'M', 'D' => 'diverso', 'I' => 'diverso', 'F' => 'Azienda', 'FIRMA' => 'Azienda', 'O' => 'senza registrazione');
  }
}

class LanguageOperationsFR extends LanguageOperationsParent
{
  public function __construct()
  {
    $this->languageName = 'FR';
    $this->months = array(1 => 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
    $this->months_short = array(1 => 'janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août.', 'sept.', 'oct.', 'nov.', 'déc.');
    $this->days = array(1 => 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
    $this->days_short = array(1 => 'lu', 'ma', 'me', 'je', 've', 'sa', 'di');
    $this->gender = array(0 => 'aucune sélection', 'W' => 'féminin', 'M' => 'masculin', 'D' => 'autre', 'DIVERS' => 'autre', 'INTER' => 'autre', 'I' => 'autre', 'F' => 'entreprise', 'FIRMA' => 'entreprise', 'O' => 'sans inscription à registre d\'état civil');
    $this->gender_short = array(0 => 'aucune sélection', 'W' => 'f', 'M' => 'm', 'D' => 'autre', 'DIVERS' => 'autre', 'INTER' => 'autre', 'I' => 'autre', 'F' => 'entreprise', 'FIRMA' => 'entreprise', 'O' => 'sans inscription à registre d\'état civil');
  }
}