<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Oeffentlich\Startseite;

class ShowStartseiteUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\UseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new ShowStartseiteResponse());
  }

  public function hasAccess($pToolSectionId = null)
  {
    return true;
  }

  public function action()
  {
    $this->setzeMenupunkte();
    $this->response->mitCaptcha = $this->mitCaptcha();

    $this->response->forward_to_tool = $this->request->forward_to_tool ?? null;
    $this->response->forward_to_id = $this->request->forward_to_id ?? null;

    return $this->response;
  }

  private function setzeMenupunkte()
  {
    $menuBar = new \MenuBar();
    $menuBar->setMenuBarFromSettings(array(), 'LOGIN', null, true, true);

    $this->response->menuPunkte = $menuBar->getMenuPunkte();
  }

  private function mitCaptcha()
  {
    $tool0settings = \ToolSettingsAPI::getToolSettings(0);
    if ($tool0settings->captchaLoginFehlerhaft) {
      $dbwLoginVersuch = new \DBWorkToolsLoginError(1, true);

      return $dbwLoginVersuch->useCaptcha4CurrentIp();
    } else {
      return false;
    }
  }
}

class ShowStartseiteRequest
{
  
  public $forward_to_tool;
  
  public $forward_to_id;
}

class ShowStartseiteResponse extends \Kufer\Web\KuferTools\Basis\UseCase\BasisResponse
{
  public $menuPunkte;
  public $mitCaptcha = false;

  
  public $forward_to_tool;
  
  public $forward_to_id;
}