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

  session_start();
  
  define('ISKUFERTOOLS', true);
  
  if (!defined('BASEDIR')) {
    include_once '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'constants.php';
  }


  

  $tool_id = PostOperations::getVarValue('tool');
  $sight_id = PostOperations::getVarVAlue('sightid');
  $gruppe = PostOperations::getVarValue('gruppe');
  $art = PostOperations::getVarValue('art');
  $column_id = PostOperations::getVarValue('column_id');
  $anchor = PostOperations::getVarValue('anchor');

  $user_id = SessionOperations::getUserID();
  $dbsight = new DBWorkSightsSettings();
  $writecolumns = new writeColumns();
  if ($user_id != -1) {
    switch ($art) {
      case 'add':

        $writecolumns->addColumn(PostOperations::getVarValue('spalte'), PostOperations::getVarValue('titel'), PostOperations::getVarValue('td_width'), PostOperations::getVarValue('font_size'), PostOperations::getVarValue('bold'));
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;

      case 'del':

        $writecolumns->deleteColumn($column_id);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor - 1);
    break;

      case 'edit':

        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor, $column_id);
    break;

      case 'save':

        $writecolumns->updateColumn($column_id, PostOperations::getVarValue('spalte'), PostOperations::getVarValue('title'), PostOperations::getVarValue('width'), PostOperations::getVarValue('fontsize'), PostOperations::getVarValue('bold'));
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor);
    break;

      case 'abort':

        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor);
        break;

      case 'up':

        $writecolumns->moveColumnUp($sight_id, $column_id);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor - 1);
    break;

      case 'down':

        $writecolumns->moveColumnDown($sight_id, $column_id);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor + 1);
    break;

      case 'uebersicht_mitarbeiter':
         
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $kurseproseite = PostOperations::getVarValue('kurseproseite', 10);
        $arrayResult = $writecolumns->getSortierungsSettings();
        $sortkurs = $arrayResult[0];
        $asc = $arrayResult[1];
        $sortkurs2 = $arrayResult[2];
        $asc2 = $arrayResult[3];

         
        $objsettings->kurseproseite = $kurseproseite;
        $objsettings->sortkurse = $sortkurs;
        $objsettings->sortkurseasc = $asc;
        $objsettings->sortkurse2 = $sortkurs2;
        $objsettings->sortkurseasc2 = $asc2;
        $objsettings->id = $tool_id;
        $objsettings = $writecolumns->setSemester($objsettings);

        
        $objsettings->sameAussenst = PostOperations::getVarValue('sameAussenst');
        
        $objsettings->useBereichsRechte = PostOperations::getVarValue('useBereichsRechte');

        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;

      case 'Sort_Stat': 

        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->id = $tool_id;

        
        $objsettings->meldeBenachrichtigungsMailAnVerwMa = PostOperations::getVarValue('meldeBenachrichtigungsMailAnVerwMa');
        $objsettings->meldeImmerBenachrichtigungsMail = PostOperations::getVarValue('meldeImmerBenachrichtigungsMail');
        $objsettings->weitermeldenKursAuswaehlen = PostOperations::isDefined('weitermeldenKursAuswaehlen');

        $objsettings->vhsEmailTool8Section242 = PostOperations::getVarValue('vhsEmailTool8Section242');
        
        $objsettings->writeNachlassGrund2IntBemerkung = PostOperations::getVarValue('writeNachlassGrund2IntBemerkung');
        $objsettings->sendMail2Ma = PostOperations::isDefined('sendMail2Ma');

        
        $objsettings->stornoMinTNanzahlPruefen = PostOperations::isDefined('autoStornoMinTNanzahl');

        
        $objsettings->tnr_maennlich_innsbruck = PostOperations::getVarValue('tnr_maennlich_innsbruck', $objsettings->tnr_maennlich_innsbruck);
        $objsettings->tnr_maennlich_auswaerts = PostOperations::getVarValue('tnr_maennlich_auswaerts', $objsettings->tnr_maennlich_auswaerts);
        $objsettings->tnr_weiblich_innsbruck = PostOperations::getVarValue('tnr_weiblich_innsbruck', $objsettings->tnr_weiblich_innsbruck);
        $objsettings->tnr_weiblich_auswaerts = PostOperations::getVarValue('tnr_weiblich_auswaerts', $objsettings->tnr_weiblich_auswaerts);

        
        $objsettingsTool11 = ToolSettingsAPI::getToolSettings(11);
        $objsettingsTool11->stornoMinTNanzahlPruefen = $objsettings->stornoMinTNanzahlPruefen;
        ToolSettingsAPI::setToolSettings($objsettingsTool11);

        $writestatus = new WriteStatTn($objsettings);
        $writestatus->sortvarstr = 'sorttn';
        
        $writestatus->writeSettings($objsettings, $tool_id, $sight_id);
        break;

      case 'Sort_StatKT': 

        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        
        $writestatus = new WriteStatKt($objsettings);
        
        $writestatus->writeSettings($objsettings, $tool_id, $sight_id);
        break;

      case 'reiter_seite': 

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $reiterSeite = new ReiterSeite($sight_id);
        $objsettings->reiterBeschriftung = $reiterSeite->getPostToSettingsString();
        $objsettings->vhsEmailTool8Section377 = PostOperations::getVarValue('vhsEmailTool8Section377');
        
        ToolSettingsAPI::setToolSettings($objsettings);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;
      case 'details_info': 
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->benutzteinfo = PostOperations::getVarValue('benutzteinfo', 0);
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;

      case 'Show_Kt_Bearb': 
        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->hl_faecher = PostOperations::getVarValue('hl_faecher');
        $objsettings->hl_info_felder = PostOperations::getVarValue('hl_info_felder');
         $objsettings->hl_raum = PostOperations::getVarValue('hl_raum');
        $objsettings->medienMailAnVerwMa = PostOperations::getVarValue('medienMailAnVerwMa');
        
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor + 1);
        break;
      case 'doz_honorar':
      case 'dozenten':
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->pdf_liste_an_doz = PostOperations::getVarValue('pdfListeAnDoz');

        $objsettings = $writecolumns->setSortierung($objsettings, 'sortdoz');

        ToolSettingsAPI::setToolSettings($objsettings);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor + 1);
        break;
      case 'Anwesenheit_Bearbeiten': 
        
        $toolEinstAllg = new ToolEinstellAllg();
        $toolEinstAllg->storeSettings4Anwesenheiten($tool_id, $sight_id, $writecolumns);
        break;
      case 'kurs_bearbeiten': 
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->kurse_hl_raum = PostOperations::getVarValue('kurse_hl_raum');
        ToolSettingsAPI::setToolSettings($objsettings);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe, $anchor + 1);
        break;

    }
  }