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


class AktuelleSight extends BasisSight
{
  
  public $htmlop;
  public $dbwaktuelleswt;

  
  public $dbwuser;
  
  public $usergroup;
  
  public $selusercnt;

  
  public function initiate()
  {
    parent::initiate();

    $this->htmlop = new HTMLOperations();
    $this->dbwuser = new DBWorkUser(1, true);
    $this->dbwaktuelleswt = new DBWorkAktuellesWT(1, true);
  }

  
  public function _getFachbereiche()
  {
    $ben = SessionOperations::getCurrentWebToolsUser();
    $fachary = array();
    if (SessionOperations::isAdmin()) {
      $dbwdozfachbereich = new DBWorkDozFachbereich(1, true);
      $fachary = $dbwdozfachbereich->getFachbereichAll();
    } elseif ($ben->dnr != -1) {
      $dbwdozfachbereich = new DBWorkDozFachbereich(1, true);

      
      $fachary = $dbwdozfachbereich->getFachbereichByDNr($ben->dnr);
    }
    
    else {
    }

    return $fachary;
  }

  
  public function _getSelOptionUserGroup()
  {
    
    $user = $this->dbwuser->getUser($this->userid);
    $this->selusercnt = 0;
    $optary = $this->getoptValue0();
    if ($user->isAdmin()) {
      
      
      $optary[] = '<option value="1" ' . (in_array(1, $this->usergroup) ? 'selected="selected"' : '') . '>Mitarbeiter</option>';
      $optary[] = '<option value="2" ' . (in_array(2, $this->usergroup) ? 'selected="selected"' : '') . '>Dozenten</option>';
      $optary[] = '<option value="3" ' . (in_array(3, $this->usergroup) ? 'selected="selected"' : '') . '>Teilnehmer</option>';
      $optary[] = '<option value="4" ' . (in_array(4, $this->usergroup) ? 'selected="selected"' : '') . '>Hausmeister</option>';
      $this->selusercnt += 4;
    } else {
      
      

      if ($user->ben > 0) {
        $optary[] = '<option value="1" ' . (in_array(1, $this->usergroup) ? 'selected="selected"' : '') . '>Mitarbeiter</option>';
        $this->selusercnt++;
      }
      if ($user->dnr > 0) {
        $optary[] = '<option value="2" ' . (in_array(2, $this->usergroup) ? 'selected="selected"' : '') . '>Dozenten</option>';
        $this->selusercnt++;
      }
      if ($user->tnr > 0) {
        $optary[] = '<option value="3" ' . (in_array(3, $this->usergroup) ? 'selected="selected"' : '') . '>Teilnehmer</option>';
        $this->selusercnt++;
      }
      if ($user->anr > 0) {
        $optary[] = '<option value="4" ' . (in_array(4, $this->usergroup) ? 'selected="selected"' : '') . '>Hausmeister</option>';
        $this->selusercnt++;
      }
    }
    
    return $optary;
  }

  
  public function getOptvalue0()
  {
    return array();
  }

  
  public static function _convertUserGroupToName($pUsergrp)
  {
    
    if (!isset($pUsergrp)) {
      return '';
    }
    $usergrpary = explode(',', $pUsergrp);
    $usergrpnames = array();
    foreach ($usergrpary as $usergrpid) {
      switch ($usergrpid) {
        case 0:
            $usergrpnames[] = 'Allgemeine Infos';
            break;
        case 1:
          $usergrpnames[] = 'Mitarbeiter';
          break;
        case 2:
          $usergrpnames[] = 'Dozenten';
          break;
        case 3:
          $usergrpnames[] = 'Teilnehmer';
          break;
        case 4:
          $usergrpnames[] = 'Hausmeister';
          break;
      }
    }

    return implode(', ', $usergrpnames);
  }

  public function createSight()
  {
    
    
    $this->usergroup = PostOperations::getVarValue('benutzergruppe');
    
    $user = $this->dbwuser->getUser($this->userid);
    if ($this->usergroup == '') {
      if ($user->isAdmin()) {
        $this->usergroup = array('-1');
      } else {
        $this->usergroup = array();
        array_push($this->usergroup, '-1');
      }
    }
  }

  
}