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


class BASysBenutzer extends \Personn
{
  public $kennung = '';
  public $aussenstelle = '';
  public $www = '';
  public $tel3 = '';
  public $rechtber_d = '';
  public $rechtber_t = '';
  public $rechtber_k = '';
  
  public $gruppe = false;
  public $gruppe1 = '';
  public $gruppe2 = '';
  public $gruppe3 = '';
  public $gruppe4 = '';
  public $gruppe5 = '';
  public $gruppe6 = '';
  public $gruppe7 = '';
  public $gruppe8 = '';
  public $gruppe9 = '';
  public $gruppe10 = '';
  public $gruppe11 = '';
  public $gruppe12 = '';
  public $webnichtuebersicht = '';
  public $stelle = '';
  
  public $zimmer = '';
  public $agb_bestaetigen;
  public $vorschlagknr;

  
  public $adr1 = '';
  public $adr2 = '';
  public $adr3 = '';
  public $adr4 = '';

  
  public $email;
  
  public $email2;
  
  public $email3;

  public function getVarValueEx($name, $datamodulname)
  {
    
    return \Datamodul::getVarValueEx($name, $datamodulname);
  }

  public function getVarValue($pName)
  {
    switch ($pName) {
      
      case 'titel_name_vorname': return $this->getVarValue('name_vorname_ohne_komma');
      case 'titel_vorname_name': return $this->getVarValue('vorname_name_ohne_komma');
      case 'namevorname': return trim($this->getVarValue('name') . ', ' . $this->getVarValue('vorname'), ' ,');
      default: return parent::getVarValue($pName);
    }
  }

  public function setValue2Var($var, $val)
  {
    \Datamodul::setValue2Var($var, $val);
  }

  
  public function getGruppen(): array
  {
    $gruppen = array();
    $dbwBasysBenutzer = new \DBWorkBASysUser();
    $anzahlGruppen = $dbwBasysBenutzer->getAnzahlGruppenInDb();
    for ($i = 1; $i <= $anzahlGruppen; $i++) {
      $gruppe = $this->getVarValue('gruppe' . $i);
      if ($gruppe != '') {
        $gruppen[] = $gruppe;
      }
    }

    return $gruppen;
  }

  
  public function getVarName4EmailSenderSetting(string $pEmpfaenger): string
  {
    return 'absenderMitarbeiterAn' . $pEmpfaenger;
  }

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'id':
        return \DatamodulVarType::TYPE_INT;
      case 'webnichtuebersicht':
      case 'gruppe':
        return \DatamodulVarType::TYPE_BOOL_WF;
      case 'agb_bestaetigen':
        return \DatamodulVarType::TYPE_DATETIME;
    }
  }

  public function getDmzVarnameMappingForReceivingData(): array
  {
    return array(
      'AgbBestaetigen' => 'agb_bestaetigen'
    );
  }

  public function getEMailName(): string
  {
    return $this->getVarValue('name_vorname_ohne_komma');
  }

  public function getEMailAddress(): ?string
  {
    return $this->email;
  }

  public function getDbTyp(): string
  {
    return 'M';
  }
}