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


class URLParameterNewsletterBestaetigungKuferSql extends URLParameterBasis
{
  public $newsl;
  public $nl_step2;

  private $decodedNr = -1;
  private $decodedTyp = '';

  public function getNr()
  {
    if ($this->decodedNr === -1) {
      $this->decodedNr = $this->decodeToArray()['nr'];
    }

    return $this->decodedNr;
  }

  
  public function getPersonenTyp()
  {
    if ($this->decodedTyp === '') {
      $this->decodedTyp = $this->decodeToArray()['typ'];
    }

    return $this->decodedTyp;
  }

  public function decode()
  {
    if (strlen($this->newsl) > 0) {
      $newsl = str_replace('-', '=', $this->newsl);

      return base64_decode($newsl);
    }

    return '';
  }

  public function decodeToArray()
  {
    $klartext = $this->decode();
    if (strlen($klartext) > 0
            && StringOperations::strpos($klartext, 'nr=') !== false
            && StringOperations::strpos($klartext, '&typ=') !== false) {
      $items = explode('&', $klartext);
      $result = array();
      foreach ($items as $item) {
        $tmp = explode('=', $item);
        $result[$tmp[0]] = $tmp[1];
      }

      return $result;
    }

    return array('nr' => -1, 'typ' => '');
  }
}