<?php

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

  
  define('ISKUFERTOOLS', true);

  
  
  
  

  if (!defined('BASEDIR')) {
    include_once '..' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'constants.php';
  }

  CodingOperations::encodeEingaben();
  CodingOperations::setObStartIfInternalAndExternalEncodingAreDiffrent();
  CodingOperations::setEncodingResponseHeader();

  if (!session_id()) {
    session_start();
  }


  if (!SessionOperations::isAdmin()) {
    header('Location: index.php?sessionfail=1');
    die();
  }


  SecurityOperations::PurgeInput(true);

  
  
  if (PostOperations::isDefined('setvhssettings')
      && PostOperations::isDefined('vhsemail')
      && PostOperations::isDefined('vhsname')
      && PostOperations::isDefined('vhsstrasse')
      && PostOperations::isDefined('vhsort')
      && PostOperations::isDefined('vhstelefon')
      && PostOperations::isDefined('vhsfax')
      && PostOperations::isDefined('vhsimpressum')
      && PostOperations::isDefined('mailserver')


      && PostOperations::isDefined('mailadresse')
      && PostOperations::isDefined('emailfilepath')) {
    $settingsobj = AllgSettingsAPI::getAllgSettings();
    $settingsobj->vhsname = PostOperations::getVarValue('vhsname');
    $settingsobj->vhsstrasse = PostOperations::getVarValue('vhsstrasse');
    $settingsobj->vhsort = PostOperations::getVarValue('vhsort');
    $settingsobj->vhstelefon = PostOperations::getVarValue('vhstelefon');
    $settingsobj->vhsfax = PostOperations::getVarValue('vhsfax');
    $settingsobj->vhsemail = PostOperations::getVarValue('vhsemail');
    $settingsobj->impressum = PostOperations::getVarValue('vhsimpressum');
    $settingsobj->vhswiderruf = PostOperations::getVarValue('vhswiderruf');
    $settingsobj->vhsagb = PostOperations::getVarValue('vhsagb');
    $settingsobj->sslserver = PostOperations::getVarValue('sslserver');
    $settingsobj->emailanm = PostOperations::getVarValue('anmeldeemail');
    $settingsobj->smtpserver = PostOperations::getVarValue('mailserver');
    $settingsobj->smtpuser = str_replace('\\\\', '\\', PostOperations::getVarValue('mailaccount'));
    $settingsobj->smtppass = PostOperations::getVarValue('mailpassword');
    $settingsobj->smtpadresse = PostOperations::getVarValue('mailadresse');
    $settingsobj->dont64Encode = PostOperations::isDefined('dont64Encode');
    $settingsobj->usephpmail = PostOperations::isDefined('usephpmail');
    $settingsobj->noenvelopmail = PostOperations::isDefined('noenvelopmail');
    $settingsobj->usephpmailer = PostOperations::isDefined('usephpmailer');
    $settingsobj->phpmailerVerschluesselung = PostOperations::getVarValue('phpmailerVerschluesselung');
    $settingsobj->kontakt = PostOperations::getVarValue('vhskontakt');
    $settingsobj->content_encoding = PostOperations::getVarValue('content_encoding');
    $settingsobj->anmeldeInfoAdresse = PostOperations::getVarValue('anmeldeInfoAdresse');
    $settingsobj->protocolprio = PostOperations::getVarValue('protocolprio');
    
    $settingsobj->title = PostOperations::getVarValue('title');
    $settingsobj->fehlerMailAnEinrichtung = PostOperations::isDefined('fehlerMailAnEinrichtung');
    $settingsobj->fehlerMailAnEmail = PostOperations::isDefined('fehlerMailAnEmail');
    $settingsobj->fehlerMailAdresse = PostOperations::getVarValue('fehlerMailAdresse');
    $settingsobj->fehlerMailAnKubus = PostOperations::isDefined('fehlerMailAnKubus');
    $settingsobj->fehlerMailBetreff = PostOperations::getVarValue('fehlerMailBetreff');

    $settingsobj->blockLoginAnf = implode(',', PostOperations::getVarValue('loginAnf', array()));
    $settingsobj->veranplanmail = PostOperations::getVarValue('veranplanmail');

    AllgSettingsAPI::setAllgSettings($settingsobj);

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

    
    $objsettings->uploadpath = PostOperations::getVarValue('uploadpath');
    $objsettings->uploadmaxsize = PostOperations::getVarValue('uploadmaxsize');
    $objsettings->uploadmaxcount = PostOperations::getVarValue('uploadmaxcount');
    $objsettings->downloadpath = PostOperations::getVarValue('downloadpath');
    $objsettings->bildUploadMaxSize = PostOperations::getVarValue('bildUploadMaxSize');
    
    
    
    
    $objsettings->dokuUploadAllowByExclude = (PostOperations::getVarValue('allowedFileExt4Upload', 0) == 1);

    
    $objsettings->uploadWhitelist4Ext = PostOperations::getVarValue('uploadWhitelist4Ext');
    $objsettings->uploadBlacklist4Ext = PostOperations::getVarValue('uploadBlacklist4Ext');
    
    $objsettings->useAllowedExt4Attach = PostOperations::isDefined('useAllowedExt4Attach');
    

    
    
    $objsettings->kursFilterCheckKnrAb = PostOperations::isDefined('kursFilterCheckKnrAb');
    $objsettings->absenderTeilnehmerAnEinrichtung = PostOperations::getVarValue('absenderTeilnehmerAnEinrichtung');
    $objsettings->absenderTeilnehmerAnAndere = PostOperations::getVarValue('absenderTeilnehmerAnAndere');
    $objsettings->absenderDozentAnEinrichtung = PostOperations::getVarValue('absenderDozentAnEinrichtung');
    $objsettings->absenderDozentAnAndere = PostOperations::getVarValue('absenderDozentAnAndere');
    $objsettings->absenderMitarbeiterAnEinrichtung = PostOperations::getVarValue('absenderMitarbeiterAnEinrichtung');
    $objsettings->absenderMitarbeiterAnDozent = PostOperations::getVarValue('absenderMitarbeiterAnDozent');
    $objsettings->absenderMitarbeiterAnTeilnehmer = PostOperations::getVarValue('absenderMitarbeiterAnTeilnehmer');
    $objsettings->absenderHausmeisterAnEinrichtung = PostOperations::getVarValue('absenderHausmeisterAnEinrichtung');
    $objsettings->absenderHausmeisterAnAndere = PostOperations::getVarValue('absenderHausmeisterAnAndere');

    
    $objsettings->savemail2file = PostOperations::getVarValue('useMail');
    $objsettings->uebermittlungsartMitabeiterTools = PostOperations::getVarValue('uebermittlungsartMitabeiterTools');
    $objsettings->usexmlmail = true;
    $objsettings->savebak = (PostOperations::getVarValue('savebak') == 'J');
    
    $objsettings->dozAutoLogin = PostOperations::isDefined('dozAutoLogin');
    $objsettings->emailfilepath = str_replace('\\\\', '\\', PostOperations::getVarValue('emailfilepath'));
    $objsettings->willkommenTools = PostOperations::getVarValue('willkommenTools', 'Herzlich willkommen im Intranet der ' . PostOperations::getVarValue('vhsname'));
    $objsettings->vhswebsite = PostOperations::getVarValue('vhswebsite');
    $objsettings->mitUnterKursen = PostOperations::isDefined('mitUnterKursen');
    $objsettings->loginStammHoerer = PostOperations::isDefined('loginStammHoerer');

    $objsettings->nowebattendee = PostOperations::getVarValue('nowebattendee');
    
    $objsettings->duplicatedetection = PostOperations::getVarValue('duplicatedetection');
    $objsettings->downtimestart = PostOperations::getVarValue('downtimestart');
    $objsettings->downtimefinish = PostOperations::getVarValue('downtimefinish');

    $writecolumns = new writeColumns();
    $objsettings->semlist = $writecolumns->getSemlistFromRequest();
    
    $objsettings = $writecolumns->setSemester($objsettings);



    
    $objsettings->showSmsBetreff = PostOperations::getVarValue('showSmsBetreff', '0') == '1';

    
    $objsettings->linkToCurrentToolSettings = (PostOperations::getVarValue('linkToCurrentToolSettings', '') != '');

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

    if (!SessionOperations::isReplikat()) {
      $objsettings->direktMaKuerzel = PostOperations::getVarValue('direktMaKuerzel', '');
    }

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

    
    $objsettings->keepFilterSettings = PostOperations::getVarValue('keepFilterSettings', '0') == '1';

    $objsettings->forwardToResponsive = PostOperations::isDefined('forwardToResponsive');
    $objsettings->forwardHmToResponsive = PostOperations::isDefined('forwardHmToResponsive');
    $objsettings->forwardTnToResponsive = PostOperations::isDefined('forwardTnToResponsive');
    $objsettings->forwardMaToResponsive = PostOperations::isDefined('forwardMaToResponsive');

    
    $objsettings->vhsEmailTools = PostOperations::getVarValue('vhsEmailTools');
    
    $objsettings->vhsEmailTool0Section5 = PostOperations::getVarValue('vhsEmailTool0Section5');
    
    $objsettings->hint4Login = PostOperations::getVarValue('hint4Login');
    
    $objsettings->needAdress4Login = PostOperations::isDefined('needAdress4Login');
    $objsettings->telefonnummerBeiLoginAnforderung = PostOperations::getVarValue('telefonnummerBeiLoginAnforderung');

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

    ToolSettingsAPI::setToolSettings($objsettings);

  
  } elseif (PostOperations::isDefined('dmzServer')) {
    $settingsobj = AllgSettingsAPI::getAllgSettings();
    $settingsobj->dmzEnabled = PostOperations::getVarValue('dmzEnabled', 'N') == 'J';
    $settingsobj->dmzServer = PostOperations::getVarValue('dmzServer');
    $settingsobj->dmzPort = PostOperations::getVarValue('dmzPort');
    $settingsobj->emailViaDmz = PostOperations::getVarValue('emailViaDmz', 'N') == 'J';
    $settingsobj->successMsgAnwesenheiten = PostOperations::getVarValue('successMsgAnwesenheiten');
    $settingsobj->failSubmitMsgAnwesenheiten = PostOperations::getVarValue('failSubmitMsgAnwesenheiten');
    $settingsobj->failDoubleSubmitMsgAnwesenheiten = PostOperations::getVarValue('failDoubleSubmitMsgAnwesenheiten');
    $settingsobj->successMsgKursplanung = PostOperations::getVarValue('successMsgKursplanung');
    $settingsobj->failSubmitMsgKursplanung = PostOperations::getVarValue('failSubmitMsgKursplanung');
    $settingsobj->failNoChangesMsgKursplanung = PostOperations::getVarValue('failNoChangesMsgKursplanung');
    $settingsobj->successMsgKursplanungNeu = PostOperations::getVarValue('successMsgKursplanungNeu');
    $settingsobj->failSubmitMsgKursplanungNeu = PostOperations::getVarValue('failSubmitMsgKursplanungNeu');
    $settingsobj->failMsgKursplanungKeineEingetr = PostOperations::getVarValue('failMsgKursplanungKeineEingetr');
    $settingsobj->failMsgKursplanungEinigeEingetr = PostOperations::getVarValue('failMsgKursplanungEinigeEingetr');
    $settingsobj->failSubmitMsgNoten = PostOperations::getVarValue('failSubmitMsgNoten');
    $settingsobj->successMsgNotenSpeichern = PostOperations::getVarValue('successMsgNotenSpeichern');
    $settingsobj->successMsgNotenEinreichen = PostOperations::getVarValue('successMsgNotenEinreichen');
    $settingsobj->failMsgNotenKeineBelegung = PostOperations::getVarValue('failMsgNotenKeineBelegung');
    $settingsobj->failMsgNotenKeineFaecher = PostOperations::getVarValue('failMsgNotenKeineFaecher');
    $settingsobj->emailBetreffNotenEinreichen = PostOperations::getVarValue('emailBetreffNotenEinreichen');
    $settingsobj->emailTextNotenEinreichen = PostOperations::getVarValue('emailTextNotenEinreichen');
    $settingsobj->emailAnNotenEinreichen = PostOperations::getVarValue('emailAnNotenEinreichen');
    $settingsobj->msgNotenHinweis = PostOperations::getVarValue('msgNotenHinweis');
    $settingsobj->msgNotenHinweisMehrphasig = PostOperations::getVarValue('msgNotenHinweisMehrphasig');
    $settingsobj->msgNotenBezeichnerMehrphasig = PostOperations::getVarValue('msgNotenBezeichnerMehrphasig');

    AllgSettingsAPI::setAllgSettings($settingsobj);
  } elseif (PostOperations::isDefined('hiddenchangepwd')) { 
    $settingsobj = AllgSettingsAPI::getAllgSettings();
    if (PostOperations::getVarValue('changepwd') == '') {
      $settingsobj->changepwd = '';
    } else {
      $settingsobj->changepwd = '1';
    }
    if (PostOperations::getVarValue('newlogin') == '') {
      $settingsobj->newlogin = '';
    } else {
      $settingsobj->newlogin = '1';
    }
    AllgSettingsAPI::setAllgSettings($settingsobj);

    $objsettings = ToolSettingsAPI::getToolSettings(0);
    if (PostOperations::getVarValue('pwdMinLength', '') != ''
        && preg_match('/^([0-9]+)/', PostOperations::getVarValue('pwdMinLength'), $arr)) {
      if ($arr[0] == PostOperations::getVarValue('pwdMinLength')) {
        $objsettings->pwdMinLength = PostOperations::getVarValue('pwdMinLength');
      }
    }
    $objsettings->pwdSpecialCharsRequired = PostOperations::isDefined('pwdSpecialCharsRequired');
    $objsettings->pwdNumbersRequired = PostOperations::isDefined('pwdNumbersRequired');
    $objsettings->encrypt = PostOperations::getVarValue('encryptXmlKtoNr');
    $objsettings->SSLAnmeldung = PostOperations::isDefined('SSLAnmeldung');
    $objsettings->SSLLogin = PostOperations::isDefined('SSLLogin');
    $objsettings->captchaLoginFehlerhaft = PostOperations::isDefined('captchaLoginFehlerhaft');
    $objsettings->serverName = PostOperations::getVarValue('serverName');
    $objsettings->SSLserverName = PostOperations::getVarValue('SSLserverName');
    $objsettings->SSLserverNameTools = PostOperations::getVarValue('SSLserverNameTools');
    $objsettings->serverPort = PostOperations::getVarValue('serverPort');
    $objsettings->SSLserverPort = PostOperations::getVarValue('SSLserverPort');
    $objsettings->encryptXML = PostOperations::getVarValue('encryptXML');

    $objsettings->login_err_count = PostOperations::getVarValue('login_err_count', 0);
    $objsettings->login_err_email = PostOperations::isDefined('login_err_email');
    $objsettings->login_err_disable = PostOperations::getVarValue('login_err_disable', $objsettings::LOGIN_ERR_DISABLE_NICHT_SPERREN);
    $objsettings->login_err_disable_value = PostOperations::getVarValue('login_err_disable_value', 0);
    if ($objsettings->login_err_disable_value < 0) {
      $objsettings->login_err_disable_value = 0;
    }
    $objsettings->login_err_disable_unit = PostOperations::getVarValue('login_err_disable_unit', $objsettings::LOGIN_ERR_DISABLE_UNIT_MINUTEN);

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

    $objsettings->id = 0;
    ToolSettingsAPI::setToolSettings($objsettings);
  } elseif (PostOperations::isDefined('toolMap')) { 
    $allgsettings = AllgSettingsAPI::getAllgSettings();
    $allgsettings->headlinePosX = StringOperations::removeNonNumbers(PostOperations::getVarValue('headlinePosX'));
    if ($allgsettings->headlinePosX !== '') {
      $allgsettings->headlinePosX .= PostOperations::getVarValue('headlinePosXUnit');
    }
    $allgsettings->headlinePosY = StringOperations::removeNonNumbers(PostOperations::getVarValue('headlinePosY'));
    if ($allgsettings->headlinePosY !== '') {
      $allgsettings->headlinePosY .= PostOperations::getVarValue('headlinePosYUnit');
    }
    $allgsettings->headlineColor = PostOperations::getVarValue('headlineColor');
    $allgsettings->headlineSize = StringOperations::removeNonNumbers(PostOperations::getVarValue('headlineSize'));
    if ($allgsettings->headlineSize !== '') {
      $allgsettings->headlineSize .= PostOperations::getVarValue('headlineSizeUnit');
    }
    $allgsettings->headlineBold = PostOperations::getVarValue('headlineBold', 'N') == 'J';
    $allgsettings->headlineShowToolName = PostOperations::getVarValue('headlineShowToolName', 'N') == 'J';
    $allgsettings->headlineShowName = PostOperations::getVarValue('headlineShowName', 'N') == 'J';
    $allgsettings->headlineShow = PostOperations::getVarValue('headlineShow', 'N') == 'J';
    $allgsettings->leftMenuNotShowKontakt = PostOperations::getVarValue('leftMenuNotShowKontakt', 'N') == 'J';
    $allgsettings->leftMenuNotShowTippAufloesung = PostOperations::getVarValue('leftMenuNotShowTippAufloesung', 'N') == 'J';
    $allgsettings->buttonleite_position = PostOperations::getVarValue('buttonleite_position');
    $allgsettings->headlineToolueberschriftenWieImMenu = PostOperations::getVarValue('headlineToolueberschriftenWieImMenu', 'N') == 'J';

    AllgSettingsAPI::setAllgSettings($allgsettings);

    $buttonWidth = PostOperations::getVarValue('buttonWidth', 150);
    $objsettings = ToolSettingsAPI::getToolSettings(0);
    $objsettings->buttonWidth = ($buttonWidth >= 150) ? $buttonWidth : 150;
    $objsettings->menuBar = StringOperations::htmlentities(PostOperations::getVarValue('menuBarJSON'), ENT_NOQUOTES);

    
    $zurVhsHPAry = array();
    
    $benutzerKuerzelAry = array('DOZ', 'MA', 'TN', 'FA', 'ADR');
    foreach ($benutzerKuerzelAry as $benutzerKuerzel) {
      if (PostOperations::isDefined('showZurVhsHP_' . $benutzerKuerzel)) {
        $zurVhsHPAry[] = $benutzerKuerzel;
      }
    }
    $objsettings->zurVhsHPBenGruppen = implode(':', $zurVhsHPAry);
    ToolSettingsAPI::setToolSettings($objsettings);
  }

  $toolId = GetOperations::getVarValue('tool', 0);

  
  $toolx = new ToolX();
  $objtool = $toolx->getEinstellX($toolId);

  $allgsettings = AllgSettingsAPI::getAllgSettings();
  
  
  $objtool->header(array('js/json2.js', 'js/zentraleEinstellungen.js'), array('./css/zentraleEinstellungen.css'), $toolId, true);
  echo"
  <body id='body'>
  ";
  if (SessionOperations::getVarValueWTIntern('admin_id') == 1) {
    $objsettings = ToolSettingsAPI::getToolSettings(0);
    $buttonWidth = ($objsettings->buttonWidth >= 150) ? CleanOperations::cleanInt($objsettings->buttonWidth, 150) : 150;
    $sightId = $toolId == -2 ? -2 : GetOperations::getVarValue('sightid');
    echo"
    <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>
      <tr>
        <td class='left_menu' width='" . ($buttonWidth + 10) . "'>
          <a href='usertools.php'><img src='images/kufer.gif' border='0'></a>" . BR_WT;
    $objtool->leftmenu($toolId, SessionOperations::getVarValueWTIntern('login'), $objtool);
    echo"
        </td>
        <td id='main_menu'>
          <table cellpadding='0' cellspacing='5' border='0' width='100%'>
            <tr>";
    echo "<td valign='top' background='images/amainlogo_o.gif' height='50px'>";
    echo "<font id='text_vhs_titel'>" . CleanOperations::cleanStringForHtml($allgsettings->vhsname) . " </font><font id='text_hinweis'>(Administrator)</font>";

    $einstieg = GetOperations::getVarValue('einstieg', '');
    $editid = GetOperations::getVarValue('editid', '');
    echo'
              </td>
            </tr>
            <tr><td>';
    $objtool->mainmenu($einstieg, $editid, $sightId);
    echo"</td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td colspan='2'>" . BR_WT;
    $objtool->submenu();
    echo'
        </td>
      </tr>
    </table>';
  } else {
    $objtool->forbidden();
  }

  echo'
  </body>
  </html>
  ';

  CodingOperations::encodeAnzeige();
  ?>