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

        $raeumeproseite = PostOperations::getVarValue('raeumeproseite'); 
        switch (PostOperations::getVarValue('sortraeume', 'raeumeauf')) {
          default:
          case 'raeumeauf':  $sortraeume = 'raum_nr';  $asc = true; break;  
          case 'raeumeab':   $sortraeume = 'raum_nr';  $asc = false; break;  
          case 'bezauf':     $sortraeume = 'bez'; $asc = true; break;  
          case 'bezab':      $sortraeume = 'bez'; $asc = false; break;  
          case 'bezlangauf':   $sortraeume = 'mktext'; $asc = true; break;  
          case 'bezlangab':    $sortraeume = 'mktext'; $asc = false; break;  
        }
        $nurRaeumeAussenst = PostOperations::getVarValue('nurRaeumeAussenst');
        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $objsettings->raeumeproseite = $raeumeproseite;
        $objsettings->sortraeume = $sortraeume;
        $objsettings->sortraeumeasc = $asc;
        $objsettings->id = $tool_id;
        $objsettings->nurRaeumeAussenst = $nurRaeumeAussenst;
        $objsettings->filterMehrereGebaeude = PostOperations::isDefined('filterMehrereGebaeude');
        $objsettings->raumNichtVerfuegbar = PostOperations::isDefined('raumNichtVerfuegbar'); 
        $objsettings->nurzugeordneteorte = PostOperations::isDefined('nurzugeordneteorte');
        
        ToolSettingsAPI::setToolSettings($objsettings);
        
        echo $writecolumns->getLink($tool_id, $sight_id, $gruppe);

        
        break;
      
    
    case 'Show_Graf_Geb':

        
        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        $medienanzeigen1 = false;
        if (PostOperations::getVarValue('medienanzeigen1') != '') {
          $medienanzeigen1 = true;
        }
        $objsettings->medienanzeigen1 = $medienanzeigen1;
        $objsettings->id = $tool_id;
        
        
        $objsettings->cellheight_vert = PostOperations::getVarValue('cellheight_vert');
        $objsettings->cellwidth_vert = PostOperations::getVarValue('cellwidth_vert');
        $objsettings->cellwidth_header_vert = PostOperations::getVarValue('cellwidth_header_vert');
        $objsettings->cellheight_header_vert = PostOperations::getVarValue('cellheight_header_vert');
        $objsettings->cellheight_hori = PostOperations::getVarValue('cellheight_hori');
        $objsettings->cellwidth_hori = PostOperations::getVarValue('cellwidth_hori');
        $objsettings->cellheight_header_hori = PostOperations::getVarValue('cellheight_header_hori');
        $objsettings->cellwidth_header_hori = PostOperations::getVarValue('cellwidth_header_hori');
        $objsettings->belblock_height_vert = PostOperations::getVarValue('belblock_height_vert');
        $objsettings->sperrblock_height_vert = PostOperations::getVarValue('sperrblock_height_vert');
        $objsettings->belblock_width_hori = PostOperations::getVarValue('belblock_width_hori');
        $objsettings->sperrblock_width_hori = PostOperations::getVarValue('sperrblock_width_hori');

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

    
    case 'Show_Graf_Raum':

        
        
        $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
        if (PostOperations::getVarValue('medienanzeigen2') != '') {
          $medienanzeigen2 = true;
        } else {
          $medienanzeigen2 = false;
        }
        $objsettings->medienanzeigen2 = $medienanzeigen2;
        $objsettings->id = $tool_id;
        
        
        
        
        
        
        
        
        
        
        

        $farbenorm = PostOperations::getVarValue('farbenorm');
        $farbeX = PostOperations::getVarValue('farbeX');
        $farbeA = PostOperations::getVarValue('farbeA');
        $farbeN = PostOperations::getVarValue('farbeN');
        $farbeZ = PostOperations::getVarValue('farbeZ');
        $farbeV = PostOperations::getVarValue('farbeV');
        $farbeE = PostOperations::getVarValue('farbeE');
        $farbeP = PostOperations::getVarValue('farbeP');
        $farbeI = PostOperations::getVarValue('farbeI');
        $farbeS = PostOperations::getVarValue('farbeS');
        $farbe1K = PostOperations::getVarValue('farbe1K');

        $objsettings->farbenorm = $farbenorm;
        $objsettings->farbeX = $farbeX;
        $objsettings->farbeA = $farbeA;
        $objsettings->farbeN = $farbeN;
        $objsettings->farbeZ = $farbeZ;
        $objsettings->farbeV = $farbeV;
        $objsettings->farbeE = $farbeE;
        $objsettings->farbeP = $farbeP;
        $objsettings->farbeI = $farbeI;
        $objsettings->farbe1K = $farbe1K;
        $objsettings->farbeS = $farbeS;

         
         
        $objsettings->celltermheight_vert = PostOperations::getVarValue('celltermheight_vert');
        $objsettings->celltermwidth_vert = PostOperations::getVarValue('celltermwidth_vert');
        $objsettings->celltermwidth_header_vert = PostOperations::getVarValue('celltermwidth_header_vert');
        $objsettings->celltermheight_header_vert = PostOperations::getVarValue('celltermheight_header_vert');
        $objsettings->celltermheight_hori = PostOperations::getVarValue('celltermheight_hori');
        $objsettings->celltermwidth_hori = PostOperations::getVarValue('celltermwidth_hori');
        $objsettings->celltermheight_header_hori = PostOperations::getVarValue('celltermheight_header_hori');
        $objsettings->celltermwidth_header_hori = PostOperations::getVarValue('celltermwidth_header_hori');
        $objsettings->beltermblock_height_vert = PostOperations::getVarValue('beltermblock_height_vert');
        $objsettings->sperrtermblock_height_vert = PostOperations::getVarValue('sperrtermblock_height_vert');
        $objsettings->beltermblock_width_hori = PostOperations::getVarValue('beltermblock_width_hori');
        $objsettings->sperrtermblock_width_hori = PostOperations::getVarValue('sperrtermblock_width_hori');

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

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

   
    case 'Show_Kurstage':

            $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
            $sperrzeitenanzeigen = PostOperations::isDefined('sperrzeitanzeigen');
            
       
       
            $objsettings->id = $tool_id;
            $objsettings->sperrzeitanzeigen = $sperrzeitenanzeigen;
            
        
        ToolSettingsAPI::setToolSettings($objsettings);
      
         echo $writecolumns->getLink($tool_id, $sight_id);
        break;

    
    case 'Raumuebersicht':

      $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
       $raeumeproseite = PostOperations::getVarValue('raeumeproseite');
      
     
     
      $objsettings->id = $tool_id;
      $objsettings->raeumeproseite = $raeumeproseite;
      
      
      ToolSettingsAPI::setToolSettings($objsettings);
      echo $writecolumns->getLink($tool_id, $sight_id);
      break;

    
    case 'reiter_seite_raum':

      $objsettings = ToolSettingsAPI::getToolSettings($tool_id);
      $reiterSeite = new ReiterSeite($sight_id);
      $objsettings->reiterBeschriftung_raum = $reiterSeite->getPostToSettingsString();

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