<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */




  session_start();
  
  if (!defined('ISKUFERTOOLS')) {
    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');
  $art = PostOperations::getVarValue('art');
  $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 'anmstand':
       switch (PostOperations::getVarValue('radioAnmStatus1', 'grafik')) {
          default:
          case 'text':     $anmstat1 = 'text'; break;
          case 'grafik':   $anmstat1 = 'grafik'; break;
        }
        switch (PostOperations::getVarValue('radioAnmStatus2', 'grafik')) {
          default:
          case 'text':     $anmstat2 = 'text'; break;
          case 'grafik':   $anmstat2 = 'grafik'; break;
        }
        switch (PostOperations::getVarValue('radioAnmStatus3', 'grafik')) {
          default:
          case 'text':     $anmstat3 = 'text'; break;
          case 'grafik':   $anmstat3 = 'grafik'; break;
        }
        switch (PostOperations::getVarValue('radioAnmStatus4', 'grafik')) {
          default:
          case 'text':     $anmstat4 = 'text'; break;
          case 'grafik':   $anmstat4 = 'grafik'; break;
        }

        $checkstat2 = (PostOperations::getVarValue('checkAnmStatus2', 'false') == 'true');
        $checkstat3 = (PostOperations::getVarValue('checkAnmStatus3', 'false') == 'true');
        $checkstat4 = (PostOperations::getVarValue('checkAnmStatus4', 'false') == 'true');


        $objsettings = ToolSettingsAPI::getToolSettings(0);
        $objsettings->id = $tool_id; 
        $objsettings->optionstatus1 = $anmstat1;
        $objsettings->optionstatus2 = $anmstat2;
        $objsettings->optionstatus3 = $anmstat3;
        $objsettings->optionstatus4 = $anmstat4;
        $objsettings->optionstatustext1 = PostOperations::getVarValue('textAnmStatus1');
        $objsettings->optionstatustext2 = PostOperations::getVarValue('textAnmStatus2');
        $objsettings->optionstatustext3 = PostOperations::getVarValue('textAnmStatus3');
        $objsettings->optionstatustext4 = PostOperations::getVarValue('textAnmStatus4');
        $objsettings->anmstatuscheck2 = $checkstat2;
        $objsettings->anmstatuscheck3 = $checkstat3;
        $objsettings->anmstatuscheck4 = $checkstat4;
        $objsettings->belegschwelleProz = PostOperations::getVarValue('BelegschwelleProz');
        $objsettings->belegschwelleZahl = PostOperations::getVarValue('BelegschwelleZahl');
        $objsettings->telefonnummerBeiLoginAnforderung = PostOperations::getVarValue('telefonnummerBeiLoginAnforderung');

        
        ToolSettingsAPI::setToolSettings($objsettings);

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

        
      case 'anmbest':

        $objsettings = ToolSettingsAPI::getToolSettings(0);
        $objsettings->id = $tool_id; 

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

        
        $objsettings->bccAnmeldebestaetigungeMail
          = (PostOperations::isDefined('bccAnmeldebestaetigungeMail') && !$objsettings->suppressInfoMail);


        $objsettings->bccAnmeldebestaetigungeMailAdresse = PostOperations::getVarValue('bccAnmeldebestaetigungeMailAdresse');
        $objsettings->infoMailMultipleContent = PostOperations::isDefined('infoMailMultipleContent');
        $objsettings->infoMailTextContent = PostOperations::isDefined('infoMailTextContent');

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

      case 'Set_Stat_Colors':

        $objsettings = ToolSettingsAPI::getToolSettings(0);

        $objsettings->kurs_status_farben = KursFarbeAPI::getSetting4Obj('kurs_farben');
        $objsettings->kurstag_status_farben = KurstagFarbeAPI::getSetting4Obj('kurstag_farben');
        $objsettings->belegung_status_farben = BelegungFarbeAPI::getSetting4Obj('belegung_farben');
        ToolSettingsAPI::setToolSettings($objsettings);
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);
        break;

    }
  }