<?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');
  $column_id = PostOperations::getVarValue('column_id');
  $anchor = PostOperations::getVarValue('anchor');
  $art = PostOperations::getVarValue('art');
  $gruppe = PostOperations::getVarValue('gruppe');

  $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_allg':

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        switch (PostOperations::getVarValue('sorttn')) {
          default:
          case 'tnauf':  $asc = true; break;
          case 'tnab':  $asc = false; break;
        }

        
        $objsettings->sorttn = 'name';
        $objsettings->sorttnasc = $asc;
        $objsettings->id = $tool_id;
        $objsettings = $writecolumns->setSemester($objsettings);
        $objsettings->useTool21Semester = PostOperations::getVarValue('useTool21Semester', 'true') == 'true';

        
        $objsettings->tnstatus = $writecolumns->getStatusFromRequest('tnstatus');

        
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        
        break;
      case 'noten': 
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->notenOhneEinzelnoten = PostOperations::isDefined('notenOhneEinzelnoten');
        $objsettings->notenOhneNotenloseFaecher = PostOperations::isDefined('notenOhneNotenloseFaecher');
        $objsettings->notenOhneFaecherloseBelegungen = PostOperations::isDefined('notenOhneFaecherloseBelegungen');
        ToolSettingsAPI::setToolSettings($objsettings);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;
    }
  }