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

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




if (session_id() == '') {
  session_start();
}

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

SecurityOperations::PurgeInput(true);


abstract class Wizard
{
  
  public $wizardName;

  
  public $wizardDescription;

  
  public function getHMTLHead($pCSSFile = '../wizard.css')
  {
    return
      "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'>\n"
      . "<html><head>\n"
      . '<title>' . KUFERTOOLS . '-Wizard: ' . CleanOperations::cleanStringForHtml($this->wizardName) . "</title>\n"
      . "<link rel='stylesheet' type='text/css' href='" . CleanOperations::cleanStringForHtml($pCSSFile) . "'>\n"
      . "<meta http-equiv='content-type' content='text/html; charset=" . CodingOperations::getExternalEncoding() . "'>\n"
      . "</head>\n";
  }

  
  public function getHTMLBodyStart()
  {
    return
      "<body>\n";
  }

  
  public function getHTMLBodyEnd()
  {
    return
      "<div class=\"wizard wizardborder wizardfooter\">&copy; 2021 Kufer Software GmbH</div></body></html>\n";
  }

  
  public function getWizardHeader()
  {
    return
      
      "<div class='wizardborder'><div class='wizard wizardheader'>
	  <h1 class='font wizardheader'><span class='wizardtitle'>WebWizard</span></div><div class='wizardheaderright'><div class='backlink'><a class='font link wizardfooter' href='..'>&lt; Zurück</a></div>\n<h1>" . $this->wizardName . "</h1>\n";
  }

  
  public function getWizardDescription()
  {
    return
      "<p class='font wizarddescription'>" . CleanOperations::cleanStringForHtml($this->wizardDescription) . "</p></div></div><div class='clearfix'> </div>" . BR_WT . "\n";
  }

  
  public function getWizardBody()
  {
    if (SessionOperations::getVarValueIntern('wizard_authorized') != '') {
      return "<div class='wizard wizardborder wizardbody'>" . $this->_getWizardBody() . "</div>\n";
    } else {
      $phpfile = StringOperations::substr(RequestOperations::getPhpSelf(), -17);

      $objsettings = ToolSettingsAPI::getToolSettings(0);
      $https = '';
      if ($objsettings->SSLLogin) {
        $https = ConstantOperations::getHTTPSPath4Url(LOGIN);
      }

      $loginScript = $phpfile == 'wizards/index.php' ? $https . 'login.php' : $https . '../login.php';
      $return = $this->getLoginGUI('Bitte loggen Sie sich als ein User ein, der Administratorrechte besitzt!', $loginScript);

      return "<div class='wizard wizardborder wizardbody'>" . $return . "</div>\n";
    }
  }

  
  public function getWizardFooter()
  {
    return '';
  }

  
  public function start($pCSSFile = '')
  {
    if ($pCSSFile != '') {
      $content = $this->getHMTLHead($pCSSFile);
    } else {
      $content = $this->getHMTLHead();
    }
    $content .= $this->getHTMLBodyStart();
    $content .= $this->getWizardHeader();
    $content .= $this->getWizardDescription();
    $content .= $this->getWizardFooter();
    $content .= $this->getWizardBody();
    $content .= $this->getHTMLBodyEnd();

    $content = CodingOperations::encodeAnzeige(true, $content);
    echo $content;
  }

  
  abstract public function _getWizardBody();

  
  public function getLoginGUI($pHeader, $pFormlink)
  {
    return
      "<p class='font wizardbody'>" . $pHeader . '</p>' . BR_WT . "\n"
      . "<form action='" . CleanOperations::cleanStringForHtml($pFormlink) . "' method='POST'>\n"
      . "<table class='table'>\n"
      . "<tr class='tr'><td class='td key'>Login:<!--<a class='wizardbody font'> </a>--></td>"
      . "<td class='td value'><input type='text' name='login'></td></tr>\n"
      . "<tr class='tr'><td class='td key'>Passwort:<!--<a class='wizardbody font'> </a>--></td>"
      . "<td class='td value'><input type='password' name='password'></td></tr>\n"
      . '</table>' . BR_WT . "\n"
      . "<input type='submit' value='Einloggen'>"
      . "</form>\n";
  }
}