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

namespace Kufer\KuferTools\Utils;

class Referer
{
  
  public static function aktualisiereRefererInSession($toolId, $refererFromGet, $refererLabelFromGet, $sessionPrefix = 'referer_tool')
  {
    if(!empty($refererFromGet)) {
      \SessionOperations::setVarValueWTIntern($sessionPrefix.$toolId, $refererFromGet);
    }
    if(!empty($refererLabelFromGet)) {
      \SessionOperations::setVarValueWTIntern('label_'.$sessionPrefix.$toolId, $refererLabelFromGet);
    }
  }
  
  
  public static function resetRefererInSession($toolId, $sessionPrefix = 'referer_tool')
  {
    \SessionOperations::setVarValueWTIntern($sessionPrefix.$toolId, '');
    \SessionOperations::setVarValueWTIntern('label_'.$sessionPrefix.$toolId, '');
  }
  
  
  public static function getRefererFromSession($toolId, $default, $sessionPrefix = 'referer_tool')
  {
    $referer = \SessionOperations::getVarValueWTIntern($sessionPrefix.$toolId);
    if(empty($referer)) {
      $referer = $default;
    }
    return $referer;
  }
  
  
  public static function getRefererLabelFromSession($toolId, $default, $sessionPrefix = 'referer_tool')
  {
    $refererLabel = \SessionOperations::getVarValueWTIntern('label_'.$sessionPrefix.$toolId);
    if(empty($refererLabel)) {
      $refererLabel = $default;
    }
    return $refererLabel;
  }
}