<?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');
  $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 (PostOperations::getVarValue('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':

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->kurstageproseite = PostOperations::getVarValue('kurstageproseite');

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

        
        $abwKtStatus = PostOperations::getVarValue('abweichendeKtStatus');
        if ($abwKtStatus) {
          $objsettings->colorktstatus = '';
          for ($i = 0;$i < StringOperations::strlen(PostOperations::getVarValue('status'));$i++) {  
            
            
            switch (PostOperations::getVarValue('ktstatus_anzeige' . ($i + 1), 'schwarz')) {
              case 'grün':     $farbe = '#33A567'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'rot':      $farbe = '#FF0000'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'braun':    $farbe = '#663300'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'lila':     $farbe = '#CC00CC'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'blau':     $farbe = '#0000CC'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'gelb':     $farbe = '#FFFF00'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'schwarz':  $farbe = '#000000'; $objsettings->colorktstatus .= $farbe . ':'; break;
              case 'frei':
                 
                  
                  $farbe = PostOperations::getVarValue('ktstatus_frei' . ($i + 1));
                  $objsettings->colorktstatus .= $farbe . ':';
                  break;
            }
          }
          
          
          $statusFilter = new FilterInpKtStat();
          $statusFilter->setAllowedInput();
          $status = $statusFilter->eingabeFiltern(PostOperations::getVarValue('status'));

          $objsettings->ktstatus = $status;
        }
        $objsettings->abweichendeKtStatus = $abwKtStatus;



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

    }
  }