<?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');
  $showKursSucheFormular = PostOperations::isDefined('showKursSucheFormular');
  $user_id = SessionOperations::getUserID();
  $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_doz':

          $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
          $kurseproseite = PostOperations::getVarValue('kurseproseite', 10);
          $semlist = $writecolumns->getSemlistFromRequest();
          $arrayResult = $writecolumns->getSortierungsSettings();
          $sortkurs = $arrayResult[0];
          $asc = $arrayResult[1];
          $sortkurs2 = $arrayResult[2];
          $asc2 = $arrayResult[3];
          $objsettings->showTnNurWennMinTn = PostOperations::isDefined('showTnNurWennMinTn');
          $objsettings->showTnTrotzMinTnWennKursstatusLaeuft = $objsettings->showTnNurWennMinTn && PostOperations::isDefined('showTnTrotzMinTnWennKursstatusLaeuft');
          $objsettings->enableDozHatListeGedrucktButton = PostOperations::isDefined('enableDozHatListeGedrucktButton');
          if ($objsettings->enableDozHatListeGedrucktButton) {
            $objsettings->dozHatListeGeduruckt_beschriftung = PostOperations::getVarValue('dozHatListeGeduruckt_beschriftung');
            $objsettings->dozHatListeGeduruckt_beschreibung = PostOperations::getVarValue('dozHatListeGeduruckt_beschreibung');
            $objsettings->dozHatListeGeduruckt_email = PostOperations::getVarValue('dozHatListeGeduruckt_email');
            if (PostOperations::isDefined('dozHatListeGedruckt_uebertragungper')) {
              $objsettings->dozHatListeGedruckt_uebertragungper = PostOperations::getVarValue('dozHatListeGedruckt_uebertragungper');
              if (! in_array($objsettings->dozHatListeGedruckt_uebertragungper, array(HATLISTEGEDRUCKT_MAIL, HATLISTEGEDRUCKT_DMZ, HATLISTEGEDRUCKT_DIREKT))) {
                $objsettings->dozHatListeGedruckt_uebertragungper = HATLISTEGEDRUCKT_MAIL;
              }
            }
          }

          $buttonBezeichnung = new ButtonBeschriftung_DozKursUebersicht();
          $objsettings = $buttonBezeichnung->savePostToSettings($objsettings);

          $objsettings->kurseproseite = $kurseproseite;
          $objsettings->sortkurse = $sortkurs;
          $objsettings->sortkurseasc = $asc;
          $objsettings->sortkurse2 = $sortkurs2;
          $objsettings->sortkurseasc2 = $asc2;
          $objsettings->id = $tool_id;
          $objsettings = $writecolumns->setSemester($objsettings);
          $objsettings->notShowAbgeschlosseneKurse = (PostOperations::getVarValue('notShowAbgeschlosseneKurse') === 'on');
          $objsettings->tnDatenAusblendenNachKursEnde = PostOperations::getVarValue('tnDatenAusblendenNachKursEnde');
          ToolSettingsAPI::setToolSettings($objsettings);

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

      case 'kursdetails':

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

      
      case 'Sort_Stat': 

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->sendMail2Einrichtung = PostOperations::isDefined('sendMail2Einrichtung');
        $objsettings->sendMail2Dozent = PostOperations::isDefined('sendMail2Dozent');
        $objsettings->sendSms2Dozent = PostOperations::isDefined('sendSms2Dozent');
        $objsettings->showTnNurWennMinTn = PostOperations::isDefined('showTnNurWennMinTn');
        $objsettings->showTnTrotzMinTnWennKursstatusLaeuft = $objsettings->showTnNurWennMinTn && PostOperations::isDefined('showTnTrotzMinTnWennKursstatusLaeuft');
        $objsettings->sms_fusszeile = PostOperations::getVarValue('sms_fusszeile_textarea', '');
        $objsettings->showTnPictures = PostOperations::isDefined('showTnPictures');
        $objsettings->vhsEmailTool1Section3 = PostOperations::getVarValue('vhsEmailTool1Section3');
        $objsettings->tnDatenAusblendenNachKursEnde = PostOperations::getVarValue('tnDatenAusblendenNachKursEnde');
        
        $writestatus = new WriteStatTn($objsettings);

        
        $writestatus->writeSettings($objsettings, $tool_id, $sight_id);
        break;

      case 'Sort_StatKT': 

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

      case 'Anm_Best':
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->id = $tool_id;
        $objsettings->sendInfoMail = PostOperations::getVarValue('sendInfoMail', '');
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;
      case 'Anwesenheit_Bearbeiten': 
        
        $toolEinstAllg = new ToolEinstellAllg();
        $toolEinstAllg->storeSettings4Anwesenheiten($tool_id, $sight_id, $writecolumns);
        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 'upload':
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
       
        
        $objsettings->freigabeDokuByMA = (PostOperations::getVarValue('freigabeDokuByMA', 'ma') === 'ma'); 
       
        $downloadFuer = PostOperations::getVarValue('downloadFuer', array());
        $objsettings->downloadFuer = SerializeOperations::serialize4Settings($downloadFuer);
        $objsettings->uploadInfoMailAnVerwMa = PostOperations::isDefined('uploadInfoMailAnVerwMa');
        $objsettings->uploadInfoMailAnPlanMa = PostOperations::isDefined('uploadInfoMailAnPlanMa');
        $objsettings->vhsEmailTool1Section318 = PostOperations::getVarValue('vhsEmailTool1Section318');
        $objsettings->sendMailOnly4FreigabeMA = PostOperations::isDefined('sendMailOnly4FreigabeMA');

        ToolSettingsAPI::setToolSettings($objsettings);

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

      case 'reiter_seite':

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $reiterSeite = new ReiterSeite($sight_id);
        $objsettings->reiterBeschriftung = $reiterSeite->getPostToSettingsString();
        $objsettings->stornoBenachrichtigungsMailAnVerwMa = PostOperations::isDefined('stornoBenachrichtigungsMailAnVerwMa');
        $objsettings->stornoBenachrichtigungsMailAnPlanMa = PostOperations::isDefined('stornoBenachrichtigungsMailAnPlanMa');
        $objsettings->vhsEmailTool1Section334 = PostOperations::getVarValue('vhsEmailTool1Section334');

        
        ToolSettingsAPI::setToolSettings($objsettings);

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

      case 'honorar_reiter':
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->zusatz_vertrag_anzeigen = PostOperations::getVarValue('zusatz_vertrag_anzeigen');
        $objsettings->honorar_nur_gesamtbetrag = PostOperations::getVarValue('honorar_nur_gesamtbetrag');
        $objsettings->fahrtkosten_nur_gesamtbetrag = PostOperations::getVarValue('fahrtkosten_nur_gesamtbetrag');
        $objsettings->spesen_nur_gesamtbetrag = PostOperations::getVarValue('spesen_nur_gesamtbetrag');
        ToolSettingsAPI::setToolSettings($objsettings);

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