<?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->kursuebersicht_ueberschrift = PostOperations::getVarValue('kursuebersicht_ueberschrift');
        if (trim($objsettings->kursuebersicht_ueberschrift) == '') {
          $objsettings->kursuebersicht_ueberschrift = 'Teilnehmerumfrage starten';
        }
        $objsettings->kurseproseite = $kurseproseite;
        $objsettings->sortkurse = $sortkurs;
        $objsettings->sortkurseasc = $asc;
        $objsettings->sortkurse2 = $sortkurs2;
        $objsettings->sortkurseasc2 = $asc2;
        $objsettings->id = $tool_id;
        $objsettings->search_stichwort_all = PostOperations::getVarValue('search_stichwort_all');
        $objsettings->ausgefalleneKurseNichtAnzeigen = PostOperations::getVarValue('ausgefalleneKurseNichtAnzeigen');
        $objsettings = $writecolumns->setSemester($objsettings);
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;

    case 'feedback_doz':

        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);

        $objsettings->feedbackbogen_nachspann = PostOperations::getVarValue('feedbackbogen_nachspann', 1);
        $objsettings->feedbackbogen_vorspann = PostOperations::getVarValue('feedbackbogen_vorspann', 1);
        $objsettings->feedback_vorspann_text = PostOperations::getVarValue('feedback_vorspann_text');
        $objsettings->feedback_nachspann_text = PostOperations::getVarValue('feedback_nachspann_text');
        $objsettings->show_bemerkungstext_as_placeholder = PostOperations::getVarValue('feedbackbogen_bemerkung', false) == true;

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

    }
  }