<?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 'Show_Sort_Sem': 

        $kurseproseite = PostOperations::getVarValue('kurseproseite'); 
        $arrayResult = $writecolumns->getSortierungsSettings();
        $sortkurs = $arrayResult[0];
        $asc = $arrayResult[1];
        $sortkurs2 = $arrayResult[2];
        $asc2 = $arrayResult[3];
        switch (PostOperations::getVarValue('kurs_ausgef', 'rot')) {
          default:
          case 'rot':    $farbe = '#FF0000'; break;
          case 'braun':  $farbe = '#663300'; break;
          case 'lila':   $farbe = '#CC00CC'; break;
          case 'blau':   $farbe = '#0000CC'; break;
          case 'gelb':   $farbe = '#FFFF00'; break;
          case 'blind':  $farbe = '#blind';  break;
        }
        

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

        $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->teilnehmerproseite = PostOperations::getVarValue('teilnehmerproseite', 20);

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

       
       $writestatus = new WriteStatTn($objsettings);
       
       $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 'Anm_Best':
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->id = $tool_id;
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;
      case 'anmelden':

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->anmEndeErreicht = PostOperations::isDefined('anmEndeErreicht');
        $objsettings->anmKursBeginnErreicht = PostOperations::isDefined('anmKursBeginnErreicht');
        $objsettings->ueberbuchenErlaubt = PostOperations::isDefined('ueberbuchenErlaubt');
        $objsettings->kindNameVorbelegen = PostOperations::isDefined('kindNameVorbelegen');
        $objsettings->kursDetailsIgnoreTool8Settings = PostOperations::isDefined('kursDetailsIgnoreTool8Settings');
        $objsettings->anmeldeArt = PostOperations::getVarValue('anmeldeArt');
        
        $objsettings->zahlartAnmDefault = PostOperations::getVarValue('zahlartAnmDefault');
        $objsettings->sendInfoMail = PostOperations::isDefined('sendInfoMail');

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

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

    }
  }